From 837deed8883947ab36587ebabf7de77140b87f20 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 21 Aug 2017 15:55:12 -0700 Subject: [PATCH] Lint --- .eslintrc | 1 + lib/app.js | 6 +++--- lib/parse.js | 2 +- test/app.js | 12 +++++------ test/assert.js | 43 ++++++++++++++++++++-------------------- test/conditional.js | 2 +- test/return.js | 1 - test/statements.js | 4 ++-- test/util/mockTruffle.js | 2 +- test/util/util.js | 11 +++++----- test/util/vm.js | 2 +- test/zeppelin.js | 1 - 12 files changed, 42 insertions(+), 45 deletions(-) diff --git a/.eslintrc b/.eslintrc index ed70c92..8a03244 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,7 @@ "objectsInObjects": false, "arraysInObjects": false }], + "no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }], "object-curly-newline": ["error", { "minProperties": 1 }], "object-property-newline": ["error"], "prefer-template": [0], diff --git a/lib/app.js b/lib/app.js index 7c2cad8..c467553 100644 --- a/lib/app.js +++ b/lib/app.js @@ -68,7 +68,7 @@ class App { // Load config if present, accomodate common windows naming. let truffleConfig; - + shell.test('-e', `${this.workingDir}/truffle.js`) ? truffleConfig = reqCwd.silent(`${this.workingDir}/truffle.js`) : truffleConfig = reqCwd.silent(`${this.workingDir}/truffle-config.js`); @@ -142,11 +142,11 @@ class App { const options = this.testrpcOptions || defaultRpcOptions; const npm = './node_modules/.bin/testrpc-sc'; const yarn = './node_modules/ethereumjs-testrpc-sc/build/cli.node.js'; - + shell.test('-e', yarn) ? command = `${yarn} ` : command = `${npm} `; - + // Launch this.testrpcProcess = childprocess.exec(command + options, null, (err, stdout, stderr) => { if (err) { diff --git a/lib/parse.js b/lib/parse.js index 3ac5fd4..f00d2ec 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,4 +1,4 @@ -/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }]*/ +/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }] */ /** * Methods in this file walk the AST and call the instrumenter diff --git a/test/app.js b/test/app.js index fe115b1..0cbdfe2 100644 --- a/test/app.js +++ b/test/app.js @@ -60,7 +60,7 @@ describe('app', () => { const testConfig = Object.assign({}, config); testConfig.testrpcOptions = `--account="${privateKey},${balance}" --port 8777`; - testConfig.dir = './mock', + testConfig.dir = './mock'; testConfig.norpc = false; testConfig.port = 8777; @@ -79,7 +79,7 @@ describe('app', () => { const testConfig = Object.assign({}, config); testConfig.testCommand = 'mocha --timeout 5000 > /dev/null 2>&1'; - testConfig.dir = './mock', + testConfig.dir = './mock'; testConfig.norpc = false; testConfig.port = 8888; @@ -98,7 +98,7 @@ describe('app', () => { const testConfig = Object.assign({}, config); testConfig.testCommand = 'node ../test/util/mockTestCommand.js'; - testConfig.dir = './mock', + testConfig.dir = './mock'; testConfig.norpc = false; testConfig.port = 8888; @@ -118,7 +118,7 @@ describe('app', () => { const testConfig = Object.assign({}, config); - testConfig.dir = './mock', + testConfig.dir = './mock'; testConfig.norpc = false; testConfig.port = 8889; @@ -159,7 +159,7 @@ describe('app', () => { };`; const testConfig = Object.assign({}, config); - testConfig.dir = './mock', + testConfig.dir = './mock'; testConfig.norpc = false; testConfig.port = 8555; // Manually inspect that port is actually set to 8999 @@ -209,7 +209,7 @@ describe('app', () => { collectGarbage(); }); - it('project uses truffle-config.js: should generate coverage, cleanup and exit(0)', () => { + it('project uses truffle-config.js: should generate coverage, cleanup and exit(0)', () => { // Directory should be clean assert(pathExists('./coverage') === false, 'should start without: coverage'); assert(pathExists('./coverage.json') === false, 'should start without: coverage.json'); diff --git a/test/assert.js b/test/assert.js index 04e38a7..2f074c1 100644 --- a/test/assert.js +++ b/test/assert.js @@ -84,27 +84,26 @@ describe('asserts and requires', () => { }); it('should cover multi-line require statements as if they are if statements when they fail', done => { - const contract = util.getCode('assert/RequireMultiline.sol'); - const info = getInstrumentedVersion(contract, filePath); - const coverage = new CoverageMap(); - coverage.addContract(info, filePath); - - vm.execute(info.contract, 'a', [true, true, false]).then(events => { - const mapping = coverage.generate(events, pathPrefix); - assert.deepEqual(mapping[filePath].l, { - 5: 1, - }); - assert.deepEqual(mapping[filePath].b, { - 1: [0, 1], - }); - assert.deepEqual(mapping[filePath].s, { - 1: 1, - }); - assert.deepEqual(mapping[filePath].f, { - 1: 1, - }); - done(); - }).catch(done); - }); + const contract = util.getCode('assert/RequireMultiline.sol'); + const info = getInstrumentedVersion(contract, filePath); + const coverage = new CoverageMap(); + coverage.addContract(info, filePath); + vm.execute(info.contract, 'a', [true, true, false]).then(events => { + const mapping = coverage.generate(events, pathPrefix); + assert.deepEqual(mapping[filePath].l, { + 5: 1, + }); + assert.deepEqual(mapping[filePath].b, { + 1: [0, 1], + }); + assert.deepEqual(mapping[filePath].s, { + 1: 1, + }); + assert.deepEqual(mapping[filePath].f, { + 1: 1, + }); + done(); + }).catch(done); + }); }); diff --git a/test/conditional.js b/test/conditional.js index 582385f..21ad227 100644 --- a/test/conditional.js +++ b/test/conditional.js @@ -199,5 +199,5 @@ describe('conditional statements', () => { assert.deepEqual(mapping[filePath].f, {1: 1}); done(); }).catch(done); - });*/ + }); */ }); diff --git a/test/return.js b/test/return.js index 04bfd48..a8ebaa3 100644 --- a/test/return.js +++ b/test/return.js @@ -5,7 +5,6 @@ const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); const util = require('./util/util.js'); describe('return statements', () => { - it('should compile after instrumenting function that returns true', () => { const contract = util.getCode('return/return.sol'); const info = getInstrumentedVersion(contract, 'test.sol'); diff --git a/test/statements.js b/test/statements.js index b620920..1c3c6e9 100644 --- a/test/statements.js +++ b/test/statements.js @@ -60,8 +60,8 @@ describe('generic statements', () => { util.report(output.errors); assert.fail('WRONG'); // We shouldn't hit this. } catch (err) { - (err.actual === 'WRONG') ? assert(false): assert(true); - } + (err.actual === 'WRONG') ? assert(false) : assert(true); + } }); it('should cover a statement following a close brace', done => { diff --git a/test/util/mockTruffle.js b/test/util/mockTruffle.js index f83e69e..a517ff6 100644 --- a/test/util/mockTruffle.js +++ b/test/util/mockTruffle.js @@ -15,7 +15,7 @@ const shell = require('shelljs'); module.exports.install = function install(contract, test, config, _trufflejs, _trufflejsName) { const configjs = `module.exports = ${JSON.stringify(config)}`; const contractLocation = `./${contract}`; - const trufflejsName = _trufflejsName || 'truffle.js'; + const trufflejsName = _trufflejsName || 'truffle.js'; // Mock migrations const initialMigration = ` diff --git a/test/util/util.js b/test/util/util.js index 36b82ee..446028f 100644 --- a/test/util/util.js +++ b/test/util/util.js @@ -11,12 +11,11 @@ module.exports.getCode = function getCode(_path) { }; module.exports.report = function report(errors) { - - if (errors){ + if (errors) { errors.forEach(error => { - if (error.indexOf('Warning') === -1) { - throw new Error(`Instrumented solidity invalid: ${errors}`); - } + if (error.indexOf('Warning') === -1) { + throw new Error(`Instrumented solidity invalid: ${errors}`); + } }); - } + } }; diff --git a/test/util/vm.js b/test/util/vm.js index 2bcabbd..2ffc130 100644 --- a/test/util/vm.js +++ b/test/util/vm.js @@ -123,7 +123,7 @@ function callMethod(vm, abi, address, functionName, args) { events.pop(); shell.rm('./allFiredEvents'); resolve(events); - } catch (err) { + } catch (e) { resolve([]); } }); diff --git a/test/zeppelin.js b/test/zeppelin.js index 957f49d..e5b1c83 100644 --- a/test/zeppelin.js +++ b/test/zeppelin.js @@ -5,7 +5,6 @@ const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); const util = require('./util/util.js'); describe('Battery test of production contracts: OpenZeppelin', () => { - it('should compile after instrumenting zeppelin-solidity/Bounty.sol', () => { const bounty = getInstrumentedVersion(util.getCode('zeppelin/Bounty.sol'), 'Bounty.sol'); const ownable = getInstrumentedVersion(util.getCode('zeppelin/Ownable.sol'), 'Ownable.sol');