Skip to content

Commit d40c3f4

Browse files
authored
Merge pull request #567 from stephensli/eslint-migration
Eslint migration
2 parents f239ac6 + 9af4205 commit d40c3f4

18 files changed

+512
-494
lines changed

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true
6+
},
7+
extends: [
8+
'standard'
9+
],
10+
parserOptions: {
11+
ecmaVersion: 12,
12+
sourceType: 'module'
13+
},
14+
rules: {
15+
semi: ['error', 'always']
16+
},
17+
ignorePatterns: ['dist', 'soljson.js']
18+
};

abi.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var semver = require('semver');
1+
const semver = require('semver');
22

33
function update (compilerVersion, abi) {
4-
var hasConstructor = false;
5-
var hasFallback = false;
4+
let hasConstructor = false;
5+
let hasFallback = false;
66

7-
for (var i = 0; i < abi.length; i++) {
8-
var item = abi[i];
7+
for (let i = 0; i < abi.length; i++) {
8+
const item = abi[i];
99

1010
if (item.type === 'constructor') {
1111
hasConstructor = true;

downloadCurrentVersion.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
// This is used to download the correct binary version
44
// as part of the prepublish step.
55

6-
var pkg = require('./package.json');
7-
var fs = require('fs');
8-
var https = require('follow-redirects').https;
9-
var MemoryStream = require('memorystream');
10-
var keccak256 = require('js-sha3').keccak256;
6+
const pkg = require('./package.json');
7+
const fs = require('fs');
8+
const https = require('follow-redirects').https;
9+
const MemoryStream = require('memorystream');
10+
const keccak256 = require('js-sha3').keccak256;
1111

1212
function getVersionList (cb) {
1313
console.log('Retrieving available version list...');
1414

15-
var mem = new MemoryStream(null, { readable: false });
15+
const mem = new MemoryStream(null, { readable: false });
1616
https.get('https://solc-bin.ethereum.org/bin/list.json', function (response) {
1717
if (response.statusCode !== 200) {
1818
console.log('Error downloading file: ' + response.statusCode);
@@ -39,7 +39,7 @@ function downloadBinary (outputName, version, expectedHash) {
3939
process.exit(1);
4040
});
4141

42-
var file = fs.createWriteStream(outputName, { encoding: 'binary' });
42+
const file = fs.createWriteStream(outputName, { encoding: 'binary' });
4343
https.get('https://solc-bin.ethereum.org/bin/' + version, function (response) {
4444
if (response.statusCode !== 200) {
4545
console.log('Error downloading file: ' + response.statusCode);
@@ -48,7 +48,7 @@ function downloadBinary (outputName, version, expectedHash) {
4848
response.pipe(file);
4949
file.on('finish', function () {
5050
file.close(function () {
51-
var hash = '0x' + keccak256(fs.readFileSync(outputName, { encoding: 'binary' }));
51+
const hash = '0x' + keccak256(fs.readFileSync(outputName, { encoding: 'binary' }));
5252
if (expectedHash !== hash) {
5353
console.log('Hash mismatch: ' + expectedHash + ' vs ' + hash);
5454
process.exit(1);
@@ -63,13 +63,13 @@ console.log('Downloading correct solidity binary...');
6363

6464
getVersionList(function (list) {
6565
list = JSON.parse(list);
66-
var wanted = pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1];
67-
var releaseFileName = list.releases[wanted];
68-
var expectedFile = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0];
66+
const wanted = pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1];
67+
const releaseFileName = list.releases[wanted];
68+
const expectedFile = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0];
6969
if (!expectedFile) {
7070
console.log('Version list is invalid or corrupted?');
7171
process.exit(1);
7272
}
73-
var expectedHash = expectedFile.keccak256;
73+
const expectedHash = expectedFile.keccak256;
7474
downloadBinary('soljson.js', releaseFileName, expectedHash);
7575
});

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
var wrapper = require('./wrapper.js');
1+
const wrapper = require('./wrapper.js');
22

33
module.exports = wrapper(require('./soljson.js'));

linker.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
var assert = require('assert');
2-
var keccak256 = require('js-sha3').keccak256;
1+
const assert = require('assert');
2+
const keccak256 = require('js-sha3').keccak256;
33

44
function libraryHashPlaceholder (input) {
55
return '$' + keccak256(input).slice(0, 34) + '$';
66
}
77

8-
var linkBytecode = function (bytecode, libraries) {
8+
const linkBytecode = function (bytecode, libraries) {
99
assert(typeof bytecode === 'string');
1010
assert(typeof libraries === 'object');
1111
// NOTE: for backwards compatibility support old compiler which didn't use file names
12-
var librariesComplete = {};
13-
for (var libraryName in libraries) {
12+
const librariesComplete = {};
13+
for (const libraryName in libraries) {
1414
if (typeof libraries[libraryName] === 'object') {
1515
// API compatible with the standard JSON i/o
16-
for (var lib in libraries[libraryName]) {
16+
for (const lib in libraries[libraryName]) {
1717
librariesComplete[lib] = libraries[libraryName][lib];
1818
librariesComplete[libraryName + ':' + lib] = libraries[libraryName][lib];
1919
}
2020
} else {
2121
// backwards compatible API for early solc-js versions
22-
var parsed = libraryName.match(/^([^:]+):(.+)$/);
22+
const parsed = libraryName.match(/^([^:]+):(.+)$/);
2323
if (parsed) {
2424
librariesComplete[parsed[2]] = libraries[libraryName];
2525
}
2626
librariesComplete[libraryName] = libraries[libraryName];
2727
}
2828
}
2929

30-
for (libraryName in librariesComplete) {
31-
var hexAddress = librariesComplete[libraryName];
30+
for (const libraryName in librariesComplete) {
31+
let hexAddress = librariesComplete[libraryName];
3232
if (hexAddress.slice(0, 2) !== '0x' || hexAddress.length > 42) {
3333
throw new Error('Invalid address specified for ' + libraryName);
3434
}
@@ -38,10 +38,10 @@ var linkBytecode = function (bytecode, libraries) {
3838

3939
// Support old (library name) and new (hash of library name)
4040
// placeholders.
41-
var replace = function (name) {
41+
const replace = function (name) {
4242
// truncate to 37 characters
43-
var truncatedName = name.slice(0, 36);
44-
var libLabel = '__' + truncatedName + Array(37 - truncatedName.length).join('_') + '__';
43+
const truncatedName = name.slice(0, 36);
44+
const libLabel = '__' + truncatedName + Array(37 - truncatedName.length).join('_') + '__';
4545
while (bytecode.indexOf(libLabel) >= 0) {
4646
bytecode = bytecode.replace(libLabel, hexAddress);
4747
}
@@ -54,22 +54,22 @@ var linkBytecode = function (bytecode, libraries) {
5454
return bytecode;
5555
};
5656

57-
var findLinkReferences = function (bytecode) {
57+
const findLinkReferences = function (bytecode) {
5858
assert(typeof bytecode === 'string');
5959
// find 40 bytes in the pattern of __...<36 digits>...__
6060
// e.g. __Lib.sol:L_____________________________
61-
var linkReferences = {};
62-
var offset = 0;
61+
const linkReferences = {};
62+
let offset = 0;
6363
while (true) {
64-
var found = bytecode.match(/__(.{36})__/);
64+
const found = bytecode.match(/__(.{36})__/);
6565
if (!found) {
6666
break;
6767
}
6868

69-
var start = found.index;
69+
const start = found.index;
7070
// trim trailing underscores
7171
// NOTE: this has no way of knowing if the trailing underscore was part of the name
72-
var libraryName = found[1].replace(/_+$/gm, '');
72+
const libraryName = found[1].replace(/_+$/gm, '');
7373

7474
if (!linkReferences[libraryName]) {
7575
linkReferences[libraryName] = [];

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"solcjs": "solcjs"
88
},
99
"scripts": {
10-
"lint": "node ./node_modules/semistandard/bin/cmd.js",
10+
"lint": "eslint .",
11+
"lint:fix": "eslint --fix .",
1112
"updateBinary": "node downloadCurrentVersion.js && node verifyVersion.js",
1213
"prepublishOnly": "npm run updateBinary",
1314
"pretest": "npm run lint",
@@ -56,16 +57,15 @@
5657
},
5758
"devDependencies": {
5859
"coveralls": "^3.0.0",
60+
"eslint": "^7.32.0",
61+
"eslint-config-standard": "^16.0.3",
62+
"eslint-plugin-import": "^2.25.3",
63+
"eslint-plugin-node": "^11.1.0",
64+
"eslint-plugin-promise": "^5.1.1",
5965
"nyc": "^14.1.0",
60-
"semistandard": "^12.0.0",
6166
"tape": "^4.11.0",
6267
"tape-spawn": "^1.4.2"
6368
},
64-
"semistandard": {
65-
"ignore": [
66-
"soljson.js"
67-
]
68-
},
6969
"nyc": {
7070
"exclude": [
7171
"soljson.js"

smtchecker.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
// another run.
55
// Returns null if no solving is requested.
66
function handleSMTQueries (inputJSON, outputJSON, solver) {
7-
var auxInputReq = outputJSON.auxiliaryInputRequested;
7+
const auxInputReq = outputJSON.auxiliaryInputRequested;
88
if (!auxInputReq) {
99
return null;
1010
}
1111

12-
var queries = auxInputReq.smtlib2queries;
12+
const queries = auxInputReq.smtlib2queries;
1313
if (!queries || Object.keys(queries).length === 0) {
1414
return null;
1515
}
1616

17-
var responses = {};
18-
for (var query in queries) {
17+
const responses = {};
18+
for (const query in queries) {
1919
responses[query] = solver(queries[query]);
2020
}
2121

@@ -28,7 +28,7 @@ function handleSMTQueries (inputJSON, outputJSON, solver) {
2828
function smtCallback (solver) {
2929
return function (query) {
3030
try {
31-
var result = solver(query);
31+
const result = solver(query);
3232
return { contents: result };
3333
} catch (err) {
3434
return { error: err };

smtsolver.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var commandExistsSync = require('command-exists').sync;
2-
var execSync = require('child_process').execSync;
3-
var fs = require('fs');
4-
var tmp = require('tmp');
1+
const commandExistsSync = require('command-exists').sync;
2+
const execSync = require('child_process').execSync;
3+
const fs = require('fs');
4+
const tmp = require('tmp');
55

66
const timeout = 10000;
77

8-
var potentialSolvers = [
8+
const potentialSolvers = [
99
{
1010
name: 'z3',
1111
params: '-smt2 rlimit=20000000 rewriter.pull_cheap_ite=true fp.spacer.q3.use_qgen=true fp.spacer.mbqi=false fp.spacer.ground_pobs=false'
@@ -15,21 +15,21 @@ var potentialSolvers = [
1515
params: '--lang=smt2 --tlimit=' + timeout
1616
}
1717
];
18-
var solvers = potentialSolvers.filter(solver => commandExistsSync(solver.name));
18+
const solvers = potentialSolvers.filter(solver => commandExistsSync(solver.name));
1919

2020
function solve (query) {
2121
if (solvers.length === 0) {
2222
throw new Error('No SMT solver available. Assertion checking will not be performed.');
2323
}
2424

25-
var tmpFile = tmp.fileSync({ postfix: '.smt2' });
25+
const tmpFile = tmp.fileSync({ postfix: '.smt2' });
2626
fs.writeFileSync(tmpFile.name, query);
2727
// TODO For now only the first SMT solver found is used.
2828
// At some point a computation similar to the one done in
2929
// SMTPortfolio::check should be performed, where the results
3030
// given by different solvers are compared and an error is
3131
// reported if solvers disagree (i.e. SAT vs UNSAT).
32-
var solverOutput;
32+
let solverOutput;
3333
try {
3434
solverOutput = execSync(
3535
solvers[0].name + ' ' + solvers[0].params + ' ' + tmpFile.name, {

test/abi.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,67 @@ tape('ABI translator', function (t) {
77
st.end();
88
});
99
t.test('0.1.1 (no constructor)', function (st) {
10-
st.deepEqual(abi.update('0.1.1', []), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
10+
st.deepEqual(abi.update('0.1.1', []), [{ inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' }]);
1111
st.end();
1212
});
1313
t.test('0.3.6 (constructor)', function (st) {
14-
var input = [ { inputs: [], type: 'constructor' } ];
15-
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
14+
const input = [{ inputs: [], type: 'constructor' }];
15+
st.deepEqual(abi.update('0.3.6', input), [{ inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }, { payable: true, stateMutability: 'payable', type: 'fallback' }]);
1616
st.end();
1717
});
1818
t.test('0.3.6 (non-constant function)', function (st) {
19-
var input = [ { inputs: [], type: 'function' } ];
20-
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
19+
const input = [{ inputs: [], type: 'function' }];
20+
st.deepEqual(abi.update('0.3.6', input), [{ inputs: [], payable: true, stateMutability: 'payable', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' }]);
2121
st.end();
2222
});
2323
t.test('0.3.6 (constant function)', function (st) {
24-
var input = [ { inputs: [], type: 'function', constant: true } ];
25-
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], constant: true, stateMutability: 'view', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
24+
const input = [{ inputs: [], type: 'function', constant: true }];
25+
st.deepEqual(abi.update('0.3.6', input), [{ inputs: [], constant: true, stateMutability: 'view', type: 'function' }, { payable: true, stateMutability: 'payable', type: 'fallback' }]);
2626
st.end();
2727
});
2828
t.test('0.3.6 (event)', function (st) {
29-
var input = [ { inputs: [], type: 'event' } ];
30-
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], type: 'event' }, { payable: true, stateMutability: 'payable', type: 'fallback' } ]);
29+
const input = [{ inputs: [], type: 'event' }];
30+
st.deepEqual(abi.update('0.3.6', input), [{ inputs: [], type: 'event' }, { payable: true, stateMutability: 'payable', type: 'fallback' }]);
3131
st.end();
3232
});
3333
t.test('0.3.6 (has no fallback)', function (st) {
34-
var input = [ { inputs: [], type: 'constructor' } ];
35-
st.deepEqual(abi.update('0.3.6', input), [ { inputs: [], type: 'constructor', payable: true, stateMutability: 'payable' }, { type: 'fallback', payable: true, stateMutability: 'payable' } ]);
34+
const input = [{ inputs: [], type: 'constructor' }];
35+
st.deepEqual(abi.update('0.3.6', input), [{ inputs: [], type: 'constructor', payable: true, stateMutability: 'payable' }, { type: 'fallback', payable: true, stateMutability: 'payable' }]);
3636
st.end();
3737
});
3838
t.test('0.4.0 (has fallback)', function (st) {
39-
var input = [ { inputs: [], type: 'constructor' }, { type: 'fallback' } ];
40-
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], type: 'constructor', payable: true, stateMutability: 'payable' }, { type: 'fallback', stateMutability: 'nonpayable' } ]);
39+
const input = [{ inputs: [], type: 'constructor' }, { type: 'fallback' }];
40+
st.deepEqual(abi.update('0.4.0', input), [{ inputs: [], type: 'constructor', payable: true, stateMutability: 'payable' }, { type: 'fallback', stateMutability: 'nonpayable' }]);
4141
st.end();
4242
});
4343
t.test('0.4.0 (non-constant function)', function (st) {
44-
var input = [ { inputs: [], type: 'function' } ];
45-
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], stateMutability: 'nonpayable', type: 'function' } ]);
44+
const input = [{ inputs: [], type: 'function' }];
45+
st.deepEqual(abi.update('0.4.0', input), [{ inputs: [], stateMutability: 'nonpayable', type: 'function' }]);
4646
st.end();
4747
});
4848
t.test('0.4.0 (constant function)', function (st) {
49-
var input = [ { inputs: [], type: 'function', constant: true } ];
50-
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], constant: true, stateMutability: 'view', type: 'function' } ]);
49+
const input = [{ inputs: [], type: 'function', constant: true }];
50+
st.deepEqual(abi.update('0.4.0', input), [{ inputs: [], constant: true, stateMutability: 'view', type: 'function' }]);
5151
st.end();
5252
});
5353
t.test('0.4.0 (payable function)', function (st) {
54-
var input = [ { inputs: [], payable: true, type: 'function' } ];
55-
st.deepEqual(abi.update('0.4.0', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'function' } ]);
54+
const input = [{ inputs: [], payable: true, type: 'function' }];
55+
st.deepEqual(abi.update('0.4.0', input), [{ inputs: [], payable: true, stateMutability: 'payable', type: 'function' }]);
5656
st.end();
5757
});
5858
t.test('0.4.1 (constructor not payable)', function (st) {
59-
var input = [ { inputs: [], payable: false, type: 'constructor' } ];
60-
st.deepEqual(abi.update('0.4.1', input), [ { inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' } ]);
59+
const input = [{ inputs: [], payable: false, type: 'constructor' }];
60+
st.deepEqual(abi.update('0.4.1', input), [{ inputs: [], payable: true, stateMutability: 'payable', type: 'constructor' }]);
6161
st.end();
6262
});
6363
t.test('0.4.5 (constructor payable)', function (st) {
64-
var input = [ { inputs: [], payable: false, type: 'constructor' } ];
65-
st.deepEqual(abi.update('0.4.5', input), [ { inputs: [], payable: false, stateMutability: 'nonpayable', type: 'constructor' } ]);
64+
const input = [{ inputs: [], payable: false, type: 'constructor' }];
65+
st.deepEqual(abi.update('0.4.5', input), [{ inputs: [], payable: false, stateMutability: 'nonpayable', type: 'constructor' }]);
6666
st.end();
6767
});
6868
t.test('0.4.16 (statemutability)', function (st) {
69-
var input = [ { inputs: [], payable: false, stateMutability: 'pure', type: 'function' } ];
70-
st.deepEqual(abi.update('0.4.16', input), [ { inputs: [], payable: false, stateMutability: 'pure', type: 'function' } ]);
69+
const input = [{ inputs: [], payable: false, stateMutability: 'pure', type: 'function' }];
70+
st.deepEqual(abi.update('0.4.16', input), [{ inputs: [], payable: false, stateMutability: 'pure', type: 'function' }]);
7171
st.end();
7272
});
7373
});

0 commit comments

Comments
 (0)