From eb269986fa1fcbd1953c43918e8a88ed9227d818 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:45:07 +0100 Subject: [PATCH 1/6] tools: enable eslint no-undef-init rule This also fixes the three entries that did not pass. --- .eslintrc.js | 1 + lib/internal/util.js | 4 ++-- test/parallel/test-fs-utimes.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cd5fc51e8e3071..58f131c1b6f8e8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -130,6 +130,7 @@ module.exports = { // http://eslint.org/docs/rules/#variables 'no-delete-var': 'error', 'no-undef': 'error', + 'no-undef-init': 'error', 'no-unused-vars': ['error', { args: 'none' }], 'no-use-before-define': ['error', { classes: true, diff --git a/lib/internal/util.js b/lib/internal/util.js index 630cd0ef213bdb..5cec64ca18bfba 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -228,8 +228,8 @@ function getSystemErrorName(err) { // getConstructorOf is wrapped into this to save iterations function getIdentificationOf(obj) { const original = obj; - let constructor = undefined; - let tag = undefined; + let constructor; + let tag; while (obj) { if (constructor === undefined) { diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index dae9c7dc9eabfc..5b57287a6428b5 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -88,7 +88,7 @@ function testIt(atime, mtime, callback) { expect_errno('futimesSync', fd, ex, 'ENOSYS'); } - let err = undefined; + let err; try { fs.utimesSync('foobarbaz', atime, mtime); } catch (ex) { From 8583f20f41f2d1570c58355f3875ee535f661aee Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:46:15 +0100 Subject: [PATCH 2/6] tools: enable eslint strict key-spacing --- .eslintrc.js | 2 +- benchmark/http/_chunky_http_client.js | 4 ++-- test/parallel/test-eslint-require-buffer.js | 8 ++++---- test/parallel/test-https-agent-servername.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 58f131c1b6f8e8..e72726197a2a49 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -166,7 +166,7 @@ module.exports = { ObjectExpression: 'first', SwitchCase: 1, }], - 'key-spacing': ['error', { mode: 'minimum' }], + 'key-spacing': ['error', { mode: 'strict' }], 'keyword-spacing': 'error', 'linebreak-style': ['error', 'unix'], 'max-len': ['error', { diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js index a90535e489f4c9..7728a5d06c60aa 100644 --- a/benchmark/http/_chunky_http_client.js +++ b/benchmark/http/_chunky_http_client.js @@ -5,8 +5,8 @@ const common = require('../common.js'); const net = require('net'); const bench = common.createBenchmark(main, { - len: [1, 4, 8, 16, 32, 64, 128], - n: [5, 50, 500, 2000], + len: [1, 4, 8, 16, 32, 64, 128], + n: [5, 50, 500, 2000], type: ['send'], }); diff --git a/test/parallel/test-eslint-require-buffer.js b/test/parallel/test-eslint-require-buffer.js index ca2c44cb322515..bdc794dd594240 100644 --- a/test/parallel/test-eslint-require-buffer.js +++ b/test/parallel/test-eslint-require-buffer.js @@ -36,14 +36,14 @@ ruleTester.run('require-buffer', rule, { output: useStrict + bufferModule + useBuffer, }, { - code: mockComment + useBuffer, + code: mockComment + useBuffer, errors: [{ message }], - output: mockComment + bufferModule + useBuffer, + output: mockComment + bufferModule + useBuffer, }, { - code: mockComment + useStrict + useBuffer, + code: mockComment + useStrict + useBuffer, errors: [{ message }], - output: mockComment + useStrict + bufferModule + useBuffer, + output: mockComment + useStrict + bufferModule + useBuffer, }, ] }); diff --git a/test/parallel/test-https-agent-servername.js b/test/parallel/test-https-agent-servername.js index 985fbb3ce3f76e..df14d113994f89 100644 --- a/test/parallel/test-https-agent-servername.js +++ b/test/parallel/test-https-agent-servername.js @@ -10,7 +10,7 @@ const fixtures = require('../common/fixtures'); const options = { key: fixtures.readKey('agent1-key.pem'), cert: fixtures.readKey('agent1-cert.pem'), - ca: fixtures.readKey('ca1-cert.pem') + ca: fixtures.readKey('ca1-cert.pem') }; From b2def4e89ed0310846f0061534550107f10dc77b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:49:26 +0100 Subject: [PATCH 3/6] tools: enable eslint no-whitespace-before-property rule --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index e72726197a2a49..a4439d7ab23d8e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -212,6 +212,7 @@ module.exports = { 'no-tabs': 'error', 'no-trailing-spaces': 'error', 'no-unsafe-finally': 'error', + 'no-whitespace-before-property': 'error', 'object-curly-spacing': ['error', 'always'], 'one-var-declaration-per-line': 'error', 'operator-linebreak': ['error', 'after'], From 38ebc0a32df6a78f7e4182035113b95470791133 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:51:11 +0100 Subject: [PATCH 4/6] tools: enable eslint one-var rule --- .eslintrc.js | 1 + benchmark/tls/tls-connect.js | 6 +-- test/parallel/test-cluster-worker-kill.js | 45 +++++++++++------------ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a4439d7ab23d8e..5ea4d0b086b6cc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -214,6 +214,7 @@ module.exports = { 'no-unsafe-finally': 'error', 'no-whitespace-before-property': 'error', 'object-curly-spacing': ['error', 'always'], + 'one-var': ['error', { initialized: 'never' }], 'one-var-declaration-per-line': 'error', 'operator-linebreak': ['error', 'after'], quotes: ['error', 'single', 'avoid-escape'], diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index da0f5e08d5e6db..524d7468d000a1 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -1,7 +1,7 @@ 'use strict'; -var fs = require('fs'), - path = require('path'), - tls = require('tls'); +const fs = require('fs'); +const path = require('path'); +const tls = require('tls'); const common = require('../common.js'); const bench = common.createBenchmark(main, { diff --git a/test/parallel/test-cluster-worker-kill.js b/test/parallel/test-cluster-worker-kill.js index 38e2deb1555c2d..bb2d3495d95a4d 100644 --- a/test/parallel/test-cluster-worker-kill.js +++ b/test/parallel/test-cluster-worker-kill.js @@ -40,29 +40,28 @@ if (cluster.isWorker) { } else if (cluster.isMaster) { - const KILL_SIGNAL = 'SIGKILL', - expected_results = { - cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"], - cluster_emitExit: [1, "the cluster did not emit 'exit'"], - cluster_exitCode: [null, 'the cluster exited w/ incorrect exitCode'], - cluster_signalCode: [KILL_SIGNAL, - 'the cluster exited w/ incorrect signalCode'], - worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"], - worker_emitExit: [1, "the worker did not emit 'exit'"], - worker_state: ['disconnected', 'the worker state is incorrect'], - worker_exitedAfter: [false, - 'the .exitedAfterDisconnect flag is incorrect'], - worker_died: [true, 'the worker is still running'], - worker_exitCode: [null, 'the worker exited w/ incorrect exitCode'], - worker_signalCode: [KILL_SIGNAL, - 'the worker exited w/ incorrect signalCode'] - }, - results = { - cluster_emitDisconnect: 0, - cluster_emitExit: 0, - worker_emitDisconnect: 0, - worker_emitExit: 0 - }; + const KILL_SIGNAL = 'SIGKILL'; + const expected_results = { + cluster_emitDisconnect: [1, "the cluster did not emit 'disconnect'"], + cluster_emitExit: [1, "the cluster did not emit 'exit'"], + cluster_exitCode: [null, 'the cluster exited w/ incorrect exitCode'], + cluster_signalCode: [KILL_SIGNAL, + 'the cluster exited w/ incorrect signalCode'], + worker_emitDisconnect: [1, "the worker did not emit 'disconnect'"], + worker_emitExit: [1, "the worker did not emit 'exit'"], + worker_state: ['disconnected', 'the worker state is incorrect'], + worker_exitedAfter: [false, 'the .exitedAfterDisconnect flag is incorrect'], + worker_died: [true, 'the worker is still running'], + worker_exitCode: [null, 'the worker exited w/ incorrect exitCode'], + worker_signalCode: [KILL_SIGNAL, + 'the worker exited w/ incorrect signalCode'] + }; + const results = { + cluster_emitDisconnect: 0, + cluster_emitExit: 0, + worker_emitDisconnect: 0, + worker_emitExit: 0 + }; // start worker From da0707faa9f8c66c73f98e50d3b18ce742129658 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:51:36 +0100 Subject: [PATCH 5/6] tools: update eslint rule The former notation was deprecated. This updates it as recommended. --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5ea4d0b086b6cc..5fb535c3d83759 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -217,7 +217,7 @@ module.exports = { 'one-var': ['error', { initialized: 'never' }], 'one-var-declaration-per-line': 'error', 'operator-linebreak': ['error', 'after'], - quotes: ['error', 'single', 'avoid-escape'], + quotes: ['error', 'single', { avoidEscape: true }], semi: 'error', 'semi-spacing': 'error', 'space-before-blocks': ['error', 'always'], From 9be87985e2cd1fbe2c64889109b313bc6e8189f4 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 17 Feb 2018 03:58:50 +0100 Subject: [PATCH 6/6] doc: enable eslint prefer-template rule --- doc/.eslintrc.yaml | 1 + doc/api/esm.md | 4 ++-- doc/api/http.md | 2 +- doc/api/stream.md | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/.eslintrc.yaml b/doc/.eslintrc.yaml index c8c1612e3a100b..7b38afec10276a 100644 --- a/doc/.eslintrc.yaml +++ b/doc/.eslintrc.yaml @@ -12,6 +12,7 @@ rules: no-var: error prefer-const: error prefer-rest-params: error + prefer-template: error # Stylistic Issues no-multiple-empty-lines: [error, {max: 1, maxEOF: 0, maxBOF: 0}] diff --git a/doc/api/esm.md b/doc/api/esm.md index 3ff2904488afc1..2a564332951fea 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -118,7 +118,7 @@ given module specifier and parent file URL: ```js const baseURL = new URL('file://'); -baseURL.pathname = process.cwd() + '/'; +baseURL.pathname = `${process.cwd()}/`; export async function resolve(specifier, parentModuleURL = baseURL, @@ -161,7 +161,7 @@ const builtins = Module.builtinModules; const JS_EXTENSIONS = new Set(['.js', '.mjs']); const baseURL = new URL('file://'); -baseURL.pathname = process.cwd() + '/'; +baseURL.pathname = `${process.cwd()}/`; export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) { if (builtins.includes(specifier)) { diff --git a/doc/api/http.md b/doc/api/http.md index daa058a8b0b426..e396471b3e9802 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -422,7 +422,7 @@ const req = http.request(options); req.end(); req.on('information', (res) => { - console.log('got information prior to main response: ' + res.statusCode); + console.log(`Got information prior to main response: ${res.statusCode}`); }); ``` diff --git a/doc/api/stream.md b/doc/api/stream.md index c72873c466fdb3..20eaa95bc19ab4 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1852,7 +1852,7 @@ class Counter extends Readable { if (i > this._max) this.push(null); else { - const str = '' + i; + const str = String(i); const buf = Buffer.from(str, 'ascii'); this.push(buf); }