diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..df0d96ab --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,17 @@ +module.exports = { + "env": { + "node": true, + "commonjs": true, + "es6": true + }, + "extends": ["eslint:recommended"], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + } +}; diff --git a/package.json b/package.json index 90bc86d7..fb071f65 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "codecov-upload-js": "codecov --disable=gcov --file=coverage-js.lcov", "codecov-upload": "npm run codecov-upload-cc && npm run codecov-upload-js", "linter": "node scripts/linter.js", - "format": "npx clang-format -i src/*" + "format": "npx clang-format -i src/*", + "lint-test": "(npx eslint test{,/**}/*.js && echo 'No problems found') || echo 'Lint failed for some files'" }, "repository": { "type": "git", @@ -54,9 +55,10 @@ }, "homepage": "https://github.com/nodejs/llnode#readme", "devDependencies": { + "clang-format": "1.2.4", "codecov": "^3.1.0", + "eslint": "^6.5.1", "nyc": "^13.1.0", - "clang-format": "1.2.4", "tape": "^4.4.0" }, "nyc": { @@ -73,4 +75,4 @@ "bindings": "^1.3.0", "node-addon-api": "^1.1.0" } -} +} \ No newline at end of file diff --git a/test/common.js b/test/common.js index a8c2c125..131fd26d 100644 --- a/test/common.js +++ b/test/common.js @@ -1,6 +1,5 @@ 'use strict'; -const fs = require('fs'); const os = require('os'); const path = require('path'); const util = require('util'); @@ -48,7 +47,7 @@ function SessionOutput(session, stream, timeout) { stream.on('data', (data) => { buf += data; - for (;;) { + for (; ;) { let index = buf.indexOf('\n'); if (index === -1) @@ -114,7 +113,7 @@ SessionOutput.prototype.wait = function wait(regexp, callback, allLines) { } let done = false; - const check = setTimeout(() => { + setTimeout(() => { if (done) return; @@ -229,7 +228,8 @@ function saveCoreLLDB(scenario, core, cb) { function spawnWithTimeout(cmd, cb) { const proc = spawn(cmd, { shell: true, - stdio: ['pipe', 'pipe', 'pipe'] }); + stdio: ['pipe', 'pipe', 'pipe'] + }); const stdout = new SessionOutput(null, proc.stdout, exports.saveCoreTimeout); const stderr = new SessionOutput(null, proc.stderr, exports.saveCoreTimeout); stdout.on('line', (line) => { debug('[stdout]', line); }); @@ -240,7 +240,7 @@ function spawnWithTimeout(cmd, cb) { proc.kill(); }, exports.saveCoreTimeout); - proc.on('exit', (status) => { + proc.on('exit', () => { clearTimeout(timeout); cb(null); }); @@ -248,8 +248,8 @@ function spawnWithTimeout(cmd, cb) { function saveCoreLinux(executable, scenario, core, cb) { const cmd = `ulimit -c unlimited && ${executable} ` + - `--abort_on_uncaught_exception --expose_externalize_string ` + - `${path.join(exports.fixturesDir, scenario)}; `; + `--abort_on_uncaught_exception --expose_externalize_string ` + + `${path.join(exports.fixturesDir, scenario)}; `; spawnWithTimeout(cmd, () => { // FIXME (mmarchini): Should also handle different core system settings. spawnWithTimeout(`mv ./core ${core}`, cb); @@ -314,7 +314,7 @@ Session.prototype.hasSymbol = function hasSymbol(symbol, callback) { let pattern = new RegExp(symbol); this.linesUntil(versionMark, (err, lines) => { - if(pattern.test(lines.join('\n'))) { + if (pattern.test(lines.join('\n'))) { callback(err, true); } else { return callback(err, false); diff --git a/test/fixtures/frame-scenario.js b/test/fixtures/frame-scenario.js index 259bf901..005cd43b 100644 --- a/test/fixtures/frame-scenario.js +++ b/test/fixtures/frame-scenario.js @@ -1,7 +1,5 @@ // Note: top-level 'use strict' intentionally omitted. -const common = require('../common'); - -function crasher(unused) { +function crasher() { 'use strict'; process.abort(); // Creates an exit frame. return this; // Force definition of |this|. diff --git a/test/fixtures/inspect-scenario.js b/test/fixtures/inspect-scenario.js index 1864a8b7..9779b434 100644 --- a/test/fixtures/inspect-scenario.js +++ b/test/fixtures/inspect-scenario.js @@ -1,7 +1,5 @@ 'use strict'; -const common = require('../common'); - const zlib = require('zlib'); let outerVar = 'outer variable'; @@ -36,19 +34,18 @@ function closure() { c.hashmap['some-key'] = 42; c.hashmap['other-key'] = 'ohai'; c.hashmap['cons-string'] = - 'this could be a bit smaller, but v8 wants big str.'; + 'this could be a bit smaller, but v8 wants big str.'; c.hashmap['cons-string'] += c.hashmap['cons-string']; c.hashmap['internalized-string'] = 'foobar'; // This thin string points to the previous 'foobar'. c.hashmap['thin-string'] = makeThin('foo', 'bar'); // Create an externalized string and slice it. c.hashmap['externalized-string'] = - 'string that will be externalized and sliced'; - externalizeString(c.hashmap['externalized-string']); + 'string that will be externalized and sliced'; // Sliced strings need to be longer that SlicedString::kMinLength // which seems to be 13 so our string is 26. c.hashmap['sliced-externalized-string'] = - c.hashmap['externalized-string'].substring(10,36); + c.hashmap['externalized-string'].substring(10, 36); c.hashmap['array'] = [true, 1, undefined, null, 'test', Class]; c.hashmap['long-array'] = new Array(20).fill(5); @@ -70,12 +67,12 @@ function closure() { c.hashmap[0] = null; c.hashmap[4] = undefined; c.hashmap[23] = /regexp/; - c.hashmap[25] = (a,b)=>{a+b}; + c.hashmap[25] = (a, b) => { a + b }; c.hashmap[oneSymbol] = 42; let scopedVar = 'scoped value'; let scopedAPI = zlib.createDeflate()._handle; - let scopedArray = [ 0, scopedAPI ]; + let scopedArray = [0, scopedAPI]; c.hashmap['date_1'] = new Date('2000-01-01'); c.hashmap['date_2'] = new Date(1); @@ -90,15 +87,8 @@ function closure() { this.name = "Class B"; } - function Class_C(class_b_array) { - this.arr = class_b_array; - this.my_class_c = "My Class C"; - } - const arr = new Array(); - for(let i=0; i < 10; i++) arr.push(new Class_B()); - - let classC = new Class_C(arr); + for (let i = 0; i < 10; i++) arr.push(new Class_B()); c.method(); } diff --git a/test/fixtures/scan-scenario.js b/test/fixtures/scan-scenario.js index 12f606f4..d5d9ad04 100644 --- a/test/fixtures/scan-scenario.js +++ b/test/fixtures/scan-scenario.js @@ -1,20 +1,11 @@ 'use strict'; -const common = require('../common'); - const zlib = require('zlib'); let outerVar = 'outer variable'; exports.holder = {}; -function makeThin(a, b) { - var str = a + b; - var obj = {}; - obj[str]; // Turn the cons string into a thin string. - return str; -} - function closure() { function Class() { @@ -34,7 +25,7 @@ function closure() { let scopedVar = 'scoped value'; let scopedAPI = zlib.createDeflate()._handle; - let scopedArray = [ 0, scopedAPI ]; + let scopedArray = [0, scopedAPI]; exports.holder = scopedAPI; @@ -46,15 +37,8 @@ function closure() { this.my_class_b = "Class B"; } - function Class_C(class_b_array) { - this.arr = class_b_array; - this.my_class_c = "My Class C"; - } - const arr = new Array(); - for(let i=0; i < 10; i++) arr.push(new Class_B()); - - let classC = new Class_C(arr); + for (let i = 0; i < 10; i++) arr.push(new Class_B()); c.method(); } diff --git a/test/fixtures/stack-scenario.js b/test/fixtures/stack-scenario.js index 1ac02f7f..ad59a7db 100644 --- a/test/fixtures/stack-scenario.js +++ b/test/fixtures/stack-scenario.js @@ -1,16 +1,14 @@ 'use strict'; -const common = require('../common'); - function first() { second('second args', 1); } -function second(arg1, arg2) { +function second() { third('third args', 1, { a: 1 }); } -function third(arg1, arg2, arg3) { +function third() { const c = new Class(); c.method('method args', 1.23, null); @@ -19,7 +17,7 @@ function third(arg1, arg2, arg3) { function Class() { } -Class.prototype.method = function method(arg1, arg2, arg3) { +Class.prototype.method = function method() { throw new Error('Uncaught'); }; diff --git a/test/fixtures/workqueue-scenario.js b/test/fixtures/workqueue-scenario.js index add58d6b..4b9c157f 100644 --- a/test/fixtures/workqueue-scenario.js +++ b/test/fixtures/workqueue-scenario.js @@ -3,13 +3,11 @@ const http = require('http') var fs = require('fs'); // Creates a Timer to be inspected with getactivehandles -setInterval(() => {}, 500); +setInterval(() => { }, 500); // Creates a TCP to be inspected with getactivehandles const server = http.createServer((req, res) => { res.end('test'); }); -server.listen(4321, (err) => {}); +server.listen(4321, () => { }); // Creates a FSReqWrap to be inspected with getactivehandles -fs.readFile('invalidFile', (err, data) => {}); - -uncaughtException(); +fs.readFile('invalidFile', () => { }); diff --git a/test/plugin/frame-test.js b/test/plugin/frame-test.js index 71007407..cc615fba 100644 --- a/test/plugin/frame-test.js +++ b/test/plugin/frame-test.js @@ -5,10 +5,10 @@ const tape = require('tape'); const common = require('../common'); const sourceCode = [ -"10 function eyecatcher() {", -"11 crasher(); // # args < # formal parameters inserts an adaptor frame.", -"12 return this; // Force definition of |this|.", -"13 }", + "10 function eyecatcher() {", + "11 crasher(); // # args < # formal parameters inserts an adaptor frame.", + "12 return this; // Force definition of |this|.", + "13 }", ]; const lastLine = new RegExp(sourceCode[sourceCode.length - 1]); @@ -20,35 +20,35 @@ function fatalError(t, sess, err) { function testFrameList(t, sess, frameNumber) { sess.send(`frame select ${frameNumber}`); - sess.linesUntil(/frame/, (err, lines) => { + sess.linesUntil(/frame/, (err) => { if (err) { return fatalError(t, sess, err); } sess.send('v8 source list'); - sess.linesUntil(/v8 source list/, (err, lines) => { + sess.linesUntil(/v8 source list/, () => { sess.linesUntil(lastLine, (err, lines) => { if (err) { return fatalError(t, sess, err); } t.equal(lines.length, sourceCode.length, - `v8 source list correct size`); + `v8 source list correct size`); for (let i = 0; i < lines.length; i++) { t.equal(lines[i].trim(), sourceCode[i], `v8 source list #${i}`); } sess.send('v8 source list -l 2'); - sess.linesUntil(/v8 source list/, (err, lines) => { + sess.linesUntil(/v8 source list/, () => { sess.linesUntil(lastLine, (err, lines) => { if (err) { return fatalError(t, sess, err); } t.equal(lines.length, sourceCode.length - 1, - `v8 source list -l 2 correct size`); + `v8 source list -l 2 correct size`); for (let i = 0; i < lines.length; i++) { t.equal(lines[i].trim(), sourceCode[i + 1], - `v8 source list -l 2 #${i}`); + `v8 source list -l 2 #${i}`); } sess.quit(); diff --git a/test/plugin/workqueue-test.js b/test/plugin/workqueue-test.js index 7fcb7a93..5f49e9c6 100644 --- a/test/plugin/workqueue-test.js +++ b/test/plugin/workqueue-test.js @@ -37,7 +37,7 @@ tape('v8 workqueue commands', (t) => { }); // Check if current node version support these commands. - sess.waitError(/error: Couldn't get node's Environment/, (err, line) => { + sess.waitError(/error: Couldn't get node's Environment/, (err) => { if (err) { testWorkqueueCommands(t, sess); } else {