From cab6be8a813c3337eb88f52c853e428860eb4d0b Mon Sep 17 00:00:00 2001 From: Kate Sills Date: Mon, 4 May 2020 14:44:59 -0700 Subject: [PATCH] chore: make cosmic-swingset lint clean (#1054) ensure linting errors in lib-wallet.js especially are caught by CI --- packages/cosmic-swingset/calc-rpcport.js | 1 + .../cosmic-swingset/lib/ag-solo/bundle.js | 1 + .../lib/ag-solo/chain-cosmos-sdk.js | 8 +++++ .../lib/ag-solo/set-gci-ingress.js | 1 + .../lib/ag-solo/upload-contract.js | 32 +++++++++++++------ .../cosmic-swingset/lib/ag-solo/vats/ibc.js | 1 + .../lib/ag-solo/vats/vat-registrar.js | 2 +- .../lib/ag-solo/vats/vat-sharing.js | 2 +- .../lib/ag-solo/vats/vat-uploads.js | 2 +- packages/cosmic-swingset/package.json | 5 +-- .../cosmic-swingset/test/test-node-version.js | 14 -------- 11 files changed, 40 insertions(+), 29 deletions(-) delete mode 100644 packages/cosmic-swingset/test/test-node-version.js diff --git a/packages/cosmic-swingset/calc-rpcport.js b/packages/cosmic-swingset/calc-rpcport.js index 305f35b9fb8..4202bc80050 100755 --- a/packages/cosmic-swingset/calc-rpcport.js +++ b/packages/cosmic-swingset/calc-rpcport.js @@ -9,6 +9,7 @@ const toml = require('@iarna/toml'); const configString = fs.readFileSync(process.argv[2]).toString(); const config = toml.parse(configString); const { laddr } = config.rpc; // like tcp://0.0.0.0:26657 +// eslint-disable-next-line no-useless-escape const m = laddr.match(/^tcp:\/\/([\d\.]+):(\d+)$/); if (!m) { throw new Error(`error, unexpected laddr format ${laddr}`); diff --git a/packages/cosmic-swingset/lib/ag-solo/bundle.js b/packages/cosmic-swingset/lib/ag-solo/bundle.js index 3e36670981b..de8593e8b70 100644 --- a/packages/cosmic-swingset/lib/ag-solo/bundle.js +++ b/packages/cosmic-swingset/lib/ag-solo/bundle.js @@ -143,6 +143,7 @@ export default async function bundle(insistIsBasedir, args) { const main = mainNS.default; if (typeof main !== 'function') { console.error(`Bundle main does not have an export default function`); + // eslint-disable-next-line no-continue continue; } diff --git a/packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js b/packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js index 88cd567897a..5e0e07435d2 100644 --- a/packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js +++ b/packages/cosmic-swingset/lib/ag-solo/chain-cosmos-sdk.js @@ -73,11 +73,13 @@ export async function connectToChain( const queued = {}; async function retryRpcAddr(tryOnce) { + // eslint-disable-next-line no-constant-condition while (true) { const randomRpcAddr = rpcAddresses[Math.floor(Math.random() * rpcAddresses.length)]; // tryOnce will either throw if cancelled (which rejects this promise), + // eslint-disable-next-line no-await-in-loop const ret = await tryOnce(randomRpcAddr); if (ret !== undefined) { // Or returns non-undefined, which we should resolve. @@ -85,6 +87,7 @@ export async function connectToChain( } // It was undefined, so wait, then retry. + // eslint-disable-next-line no-await-in-loop await new Promise(resolve => setTimeout(resolve, 5000)); } } @@ -96,6 +99,7 @@ export async function connectToChain( throwIfCancelled = () => undefined, defaultIfCancelled = WAS_CANCELLED_EXCEPTION, ) { + // eslint-disable-next-line consistent-return return retryRpcAddr(async rpcAddr => { await throwIfCancelled(); @@ -165,6 +169,7 @@ export async function connectToChain( if (maxQueued !== undefined) { while (queue.length > 0 && queue.length >= maxQueued) { // Cancel the excesses from most recent down to the currently-running. + // eslint-disable-next-line no-unused-vars const [proceed, cancel] = queue.pop(); log.debug(`cancelling ${queue.length}`); cancel(); @@ -188,6 +193,7 @@ export async function connectToChain( resolveWait = resolve; if (queue[0] === qentry) { // Wake us immediately, since we're first in queue. + // eslint-disable-next-line no-unused-vars const [proceed, cancel] = qentry; proceed(); } @@ -216,6 +222,7 @@ export async function connectToChain( } if (queue[0] !== undefined) { // Wake the next in queue. + // eslint-disable-next-line no-unused-vars const [proceed, cancel] = queue[0]; proceed(); } @@ -227,6 +234,7 @@ export async function connectToChain( 'getMailbox', 1, // Only one helper running at a time. ['query', 'swingset', 'mailbox', myAddr], + // eslint-disable-next-line consistent-return ret => { const { stdout, stderr } = ret; log.error(stderr); diff --git a/packages/cosmic-swingset/lib/ag-solo/set-gci-ingress.js b/packages/cosmic-swingset/lib/ag-solo/set-gci-ingress.js index 65deb1e5a7b..e42995da553 100644 --- a/packages/cosmic-swingset/lib/ag-solo/set-gci-ingress.js +++ b/packages/cosmic-swingset/lib/ag-solo/set-gci-ingress.js @@ -71,6 +71,7 @@ export default function setGCIIngress(basedir, GCI, rpcAddresses, chainID) { }; add(newconn); const connections = []; + // eslint-disable-next-line no-unused-vars Object.entries(connsByType).forEach(([type, conns]) => connections.push(...conns), ); diff --git a/packages/cosmic-swingset/lib/ag-solo/upload-contract.js b/packages/cosmic-swingset/lib/ag-solo/upload-contract.js index 8908defa3fd..8fbf65b1ee3 100644 --- a/packages/cosmic-swingset/lib/ag-solo/upload-contract.js +++ b/packages/cosmic-swingset/lib/ag-solo/upload-contract.js @@ -1,12 +1,22 @@ -// This javascript source file uses the "tildot" syntax (foo~.bar()) for -// eventual sends. +// In the future, this javascript source file will use the "tildot" +// syntax (foo~.bar()) for eventual sends. // https://agoric.com/documentation/ertp/guide/other-concepts.html -// Tildot is standards track with TC39, the JavaScript standards committee. -// https://github.com/tc39/proposal-wavy-dot +// Tildot is standards track with TC39, the JavaScript standards +// committee. https://github.com/tc39/proposal-wavy-dot + +import { E } from '@agoric/eventual-send'; export default async function uploadContracts({ home, bundle }) { console.error(`Installing targeted contracts...`); - await upload(home, bundle, Object.keys(bundle).filter(k => k !== 'main').sort(), true); + // eslint-disable-next-line no-use-before-define + await upload( + home, + bundle, + Object.keys(bundle) + .filter(k => k !== 'main') + .sort(), + true, + ); } export async function upload(homeP, bundle, keys, verbose = false) { @@ -22,7 +32,8 @@ export async function upload(homeP, bundle, keys, verbose = false) { const { source, moduleFormat } = bundle[key]; // console.error(`Uploading ${source}`); - const targetObj = await homeP~.[target]; + // eslint-disable-next-line no-await-in-loop + const targetObj = await E(homeP)[target]; if (!targetObj) { console.error( `Contract installation target object ${target} is not available for ${name}; skipping...`, @@ -32,15 +43,16 @@ export async function upload(homeP, bundle, keys, verbose = false) { if (verbose) { console.debug(name); } - contractsAP.push(targetObj~.install(source, moduleFormat)); + contractsAP.push(E(targetObj).install(source, moduleFormat)); names.push(name); } } - const uploadsP = homeP~.uploads; + const uploadsP = E(homeP).uploads; const contracts = await Promise.all(contractsAP); - for (let i = 0; i < contracts.length; i ++) { - await uploadsP~.set(names[i], contracts[i]); + for (let i = 0; i < contracts.length; i += 1) { + // eslint-disable-next-line no-await-in-loop + await E(uploadsP).set(names[i], contracts[i]); } console.error('See home.uploads~.list()'); diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/ibc.js b/packages/cosmic-swingset/lib/ag-solo/vats/ibc.js index 789c7d344d1..5f41bf3f44f 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/ibc.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/ibc.js @@ -390,6 +390,7 @@ export function makeIBCProtocolHandler( // TODO: Will need to change to dispatch (without sending) // a ChanOpenInit to get a passive relayer flowing. + // eslint-disable-next-line no-constant-condition if (false) { const packet = { source_channel: channelID, diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js b/packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js index c8a3ab0345b..8828df03b27 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/vat-registrar.js @@ -3,7 +3,7 @@ import { makeRegistrar } from '@agoric/registrar'; // This vat contains the registrar for the demo. -function build(E, log) { +function build(_E, _log) { const sharedRegistrar = makeRegistrar(); function getSharedRegistrar() { diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js b/packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js index 4f2cf6d7c7d..734a02895fd 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/vat-sharing.js @@ -3,7 +3,7 @@ import { makeSharingService } from '@agoric/sharing-service'; // This vat contains the sharing service for the demo. -function build(E, log) { +function build(_E, _log) { const sharingService = makeSharingService(); function getSharingService() { diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js b/packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js index e73273a6627..070fd31402f 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/vat-uploads.js @@ -3,7 +3,7 @@ import makeScratchPad from './scratch'; // This vat contains the private upload scratch pad. -function build(E, log) { +function build(_E, _log) { const uploads = makeScratchPad(); function getUploads() { diff --git a/packages/cosmic-swingset/package.json b/packages/cosmic-swingset/package.json index a3aa08e8e52..67ccb740768 100644 --- a/packages/cosmic-swingset/package.json +++ b/packages/cosmic-swingset/package.json @@ -13,7 +13,7 @@ "pretty-check": "prettier --check '**/*.js'", "lint": "eslint '**/*.js'", "lint-fix": "eslint --fix '**/*.js'", - "lint-check": "echo disabling lint in cosmic-swingset until files are lint compliant" + "lint-check": "eslint '**/*.js'" }, "keywords": [], "author": "Agoric", @@ -66,5 +66,6 @@ }, "publishConfig": { "access": "public" - } + }, + "engines" : { "node" : ">=11.0" } } diff --git a/packages/cosmic-swingset/test/test-node-version.js b/packages/cosmic-swingset/test/test-node-version.js deleted file mode 100644 index dde407b613e..00000000000 --- a/packages/cosmic-swingset/test/test-node-version.js +++ /dev/null @@ -1,14 +0,0 @@ -// eslint-disable-next-line no-redeclare -/* global process */ -import semver from 'semver'; -import { test } from 'tape-promise/tape'; - -test('Node version', t => { - t.true( - // FIXME: Temporarily disabled until Node.js v12 is LTS - // Otherwise, this fails CircleCI - semver.satisfies(process.version, '>=11.0') || true, - 'we need Node 11 where the IO queue is higher priority than the Promise queue', - ); - t.end(); -});