From b1b1978ec5a533607c5c2decaec44f00ff0a80b4 Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Sun, 18 Sep 2016 01:43:49 -0400 Subject: [PATCH] tools: add additional ESLint rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/8643 Reviewed-By: Michaël Zasso Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Anna Henningsen Reviewed-By: Roman Reiss Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- .eslintrc | 9 +++++++++ benchmark/util/format.js | 4 ++-- lib/_tls_wrap.js | 2 +- lib/internal/bootstrap_node.js | 2 +- test/inspector/inspector-helper.js | 6 +++--- test/inspector/test-inspector.js | 20 +++++++++---------- test/message/throw_in_line_with_tabs.js | 2 +- test/parallel/test-debug-protocol-execute.js | 4 ++-- test/parallel/test-http-multi-line-headers.js | 2 +- ...test-http-response-multi-content-length.js | 2 +- .../test-http-response-multiheaders.js | 2 +- test/parallel/test-regress-GH-5727.js | 2 +- test/parallel/test-repl.js | 4 ++-- test/parallel/test-stream2-writable.js | 4 ++-- test/parallel/test-tls-cipher-list.js | 6 +++--- test/parallel/test-tls-client-verify.js | 2 +- test/sequential/test-process-warnings.js | 2 +- 17 files changed, 42 insertions(+), 33 deletions(-) diff --git a/.eslintrc b/.eslintrc index f1525a6309cfb6..6ae06ef7dde353 100644 --- a/.eslintrc +++ b/.eslintrc @@ -30,6 +30,7 @@ rules: # Best Practices # http://eslint.org/docs/rules/#best-practices + dot-location: [2, property] no-fallthrough: 2 no-global-assign: 2 no-multi-spaces: 2 @@ -37,6 +38,10 @@ rules: no-redeclare: 2 no-self-assign: 2 no-unused-labels: 2 + no-useless-call: 2 + no-useless-escape: 2 + no-void: 2 + no-with: 2 # Strict Mode # http://eslint.org/docs/rules/#strict-mode @@ -64,6 +69,8 @@ rules: # http://eslint.org/docs/rules/#stylistic-issues brace-style: [2, 1tbs, {allowSingleLine: true}] comma-spacing: 2 + comma-style: 2 + computed-property-spacing: 2 eol-last: 2 func-call-spacing: 2 indent: [2, 2, {SwitchCase: 1, MemberExpression: 1}] @@ -74,9 +81,11 @@ rules: new-parens: 2 no-mixed-spaces-and-tabs: 2 no-multiple-empty-lines: [2, {max: 2}] + no-tabs: 2 no-trailing-spaces: 2 quotes: [2, single, avoid-escape] semi: 2 + semi-spacing: 2 space-before-blocks: [2, always] space-before-function-paren: [2, never] space-in-parens: [2, never] diff --git a/benchmark/util/format.js b/benchmark/util/format.js index 6a0b6c63dc1087..05176aa24fb01f 100644 --- a/benchmark/util/format.js +++ b/benchmark/util/format.js @@ -4,8 +4,8 @@ const util = require('util'); const common = require('../common'); const v8 = require('v8'); const bench = common.createBenchmark(main, { - n: [1e6] -, type: ['string', + n: [1e6], + type: ['string', 'number', 'object', 'unknown', diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index e1e4ab8af64ca6..c86239a7c95830 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -918,7 +918,7 @@ Server.prototype.addContext = function(servername, context) { var re = new RegExp('^' + servername.replace(/([\.^$+?\-\\[\]{}])/g, '\\$1') - .replace(/\*/g, '[^\.]*') + + .replace(/\*/g, '[^.]*') + '$'); this._contexts.push([re, tls.createSecureContext(context).context]); }; diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 562b3851b9812a..c9e937e2922062 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -125,7 +125,7 @@ const filename = Module._resolveFilename(process.argv[1]); var source = fs.readFileSync(filename, 'utf-8'); // remove shebang and BOM - source = internalModule.stripBOM(source.replace(/^\#\!.*/, '')); + source = internalModule.stripBOM(source.replace(/^#!.*/, '')); // wrap it source = Module.wrap(source); // compile the script, this will throw if it fails diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 865ddeb3b5fefa..bd7d3748ccae64 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -77,9 +77,9 @@ function checkHttpResponse(port, path, callback) { http.get({port, path}, function(res) { let response = ''; res.setEncoding('utf8'); - res. - on('data', (data) => response += data.toString()). - on('end', () => callback(JSON.parse(response))); + res + .on('data', (data) => response += data.toString()) + .on('end', () => callback(JSON.parse(response))); }); } diff --git a/test/inspector/test-inspector.js b/test/inspector/test-inspector.js index e2493c87396112..91d930851bd381 100644 --- a/test/inspector/test-inspector.js +++ b/test/inspector/test-inspector.js @@ -85,9 +85,9 @@ function testBreakpointOnStart(session) { { 'method': 'Runtime.runIfWaitingForDebugger' } ]; - session. - sendInspectorCommands(commands). - expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session)); + session + .sendInspectorCommands(commands) + .expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session)); } function testSetBreakpointAndResume(session) { @@ -105,9 +105,9 @@ function testSetBreakpointAndResume(session) { 'params': { 'scriptId': session.mainScriptId } }, expectMainScriptSource ], ]; - session. - sendInspectorCommands(commands). - expectMessages([ + session + .sendInspectorCommands(commands) + .expectMessages([ setupExpectConsoleOutput('log', ['A message', 5]), setupExpectBreakOnLine(5, session.mainScriptPath, session, (id) => scopeId = id), @@ -131,7 +131,7 @@ function testInspectScope(session) { [ { 'method': 'Debugger.evaluateOnCallFrame', 'params': { - 'callFrameId': '{\"ordinal\":0,\"injectedScriptId\":1}', + 'callFrameId': '{"ordinal":0,"injectedScriptId":1}', 'expression': 'k + t', 'objectGroup': 'console', 'includeCommandLineAPI': true, @@ -153,9 +153,9 @@ function testInspectScope(session) { function testWaitsForFrontendDisconnect(session, harness) { console.log('[test]', 'Verify node waits for the frontend to disconnect'); - session.sendInspectorCommands({ 'method': 'Debugger.resume'}). - expectStderrOutput('Waiting for the debugger to disconnect...'). - disconnect(true); + session.sendInspectorCommands({ 'method': 'Debugger.resume'}) + .expectStderrOutput('Waiting for the debugger to disconnect...') + .disconnect(true); } function runTests(harness) { diff --git a/test/message/throw_in_line_with_tabs.js b/test/message/throw_in_line_with_tabs.js index 3bb403feb3221b..ad95d66e97ec55 100644 --- a/test/message/throw_in_line_with_tabs.js +++ b/test/message/throw_in_line_with_tabs.js @@ -1,4 +1,4 @@ -/* eslint-disable indent */ +/* eslint-disable indent, no-tabs */ 'use strict'; require('../common'); diff --git a/test/parallel/test-debug-protocol-execute.js b/test/parallel/test-debug-protocol-execute.js index e87b25f5cb45da..2283a3c54e9034 100644 --- a/test/parallel/test-debug-protocol-execute.js +++ b/test/parallel/test-debug-protocol-execute.js @@ -15,6 +15,6 @@ assert.strictEqual(protocol.res.body, undefined); protocol.state = 'sterrance'; assert.throws( - () => { protocol.execute('grumblecakes'); }, - /^Error: Unknown state$/ + () => { protocol.execute('grumblecakes'); }, + /^Error: Unknown state$/ ); diff --git a/test/parallel/test-http-multi-line-headers.js b/test/parallel/test-http-multi-line-headers.js index f534b3b8db605c..df333cdd62bf9b 100644 --- a/test/parallel/test-http-multi-line-headers.js +++ b/test/parallel/test-http-multi-line-headers.js @@ -14,7 +14,7 @@ var server = net.createServer(function(conn) { 'Content-Length: ' + body.length + '\r\n' + 'Content-Type: text/plain;\r\n' + ' x-unix-mode=0600;\r\n' + - ' name=\"hello.txt\"\r\n' + + ' name="hello.txt"\r\n' + '\r\n' + body; diff --git a/test/parallel/test-http-response-multi-content-length.js b/test/parallel/test-http-response-multi-content-length.js index 098061002b003c..3290f74c16e250 100644 --- a/test/parallel/test-http-response-multi-content-length.js +++ b/test/parallel/test-http-response-multi-content-length.js @@ -27,7 +27,7 @@ const server = http.createServer((req, res) => { var count = 0; server.listen(0, common.mustCall(() => { - for (let n = 1; n <= MAX_COUNT ; n++) { + for (let n = 1; n <= MAX_COUNT; n++) { // This runs twice, the first time, the server will use // setHeader, the second time it uses writeHead. In either // case, the error handler must be called because the client diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index 577f401abb60ab..f4c1fd4116b735 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -48,7 +48,7 @@ const server = http.createServer(function(req, res) { server.listen(0, common.mustCall(function() { var count = 0; - for (let n = 1; n <= 2 ; n++) { + for (let n = 1; n <= 2; n++) { // this runs twice, the first time, the server will use // setHeader, the second time it uses writeHead. The // result on the client side should be the same in diff --git a/test/parallel/test-regress-GH-5727.js b/test/parallel/test-regress-GH-5727.js index ae8cca9cbf3338..3f52c55e7aaca6 100644 --- a/test/parallel/test-regress-GH-5727.js +++ b/test/parallel/test-regress-GH-5727.js @@ -4,7 +4,7 @@ const assert = require('assert'); const net = require('net'); const invalidPort = -1 >>> 0; -const errorMessage = /"port" argument must be \>= 0 and \< 65536/; +const errorMessage = /"port" argument must be >= 0 and < 65536/; net.Server().listen(common.PORT, function() { const address = this.address(); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 495125f6dcbd0a..a6603332aad672 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -160,7 +160,7 @@ function error_test() { // invalid RegExps are a special case of syntax error, // should throw { client: client_unix, send: '/(/;', - expect: /\bSyntaxError: Invalid regular expression\:/ }, + expect: /\bSyntaxError: Invalid regular expression:/ }, // invalid RegExp modifiers are a special case of syntax error, // should throw (GH-4012) { client: client_unix, send: 'new RegExp("foo", "wrong modifier");', @@ -313,7 +313,7 @@ function error_test() { { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, - { client: client_unix, send: "function x(s) {\nreturn s.replace(/\'/,'');\n}", + { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}", expect: prompt_multiline + prompt_multiline + 'undefined\n' + prompt_unix }, { client: client_unix, send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 57877b048bef42..050c2121b2289a 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -154,7 +154,7 @@ test('write bufferize', function(t) { }); chunks.forEach(function(chunk, i) { - var enc = encodings[ i % encodings.length ]; + var enc = encodings[i % encodings.length]; chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); @@ -192,7 +192,7 @@ test('write no bufferize', function(t) { }); chunks.forEach(function(chunk, i) { - var enc = encodings[ i % encodings.length ]; + var enc = encodings[i % encodings.length]; chunk = Buffer.from(chunk); tw.write(chunk.toString(enc), enc); }); diff --git a/test/parallel/test-tls-cipher-list.js b/test/parallel/test-tls-cipher-list.js index ba844c944e7cf4..44ebd3d2f824ad 100644 --- a/test/parallel/test-tls-cipher-list.js +++ b/test/parallel/test-tls-cipher-list.js @@ -16,9 +16,9 @@ function doCheck(arg, check) { '-pe', 'require("crypto").constants.defaultCipherList' ]); - spawn(process.execPath, arg, {}). - on('error', common.fail). - stdout.on('data', function(chunk) { + spawn(process.execPath, arg, {}) + .on('error', common.fail) + .stdout.on('data', function(chunk) { out += chunk; }).on('end', function() { assert.equal(out.trim(), check); diff --git a/test/parallel/test-tls-client-verify.js b/test/parallel/test-tls-client-verify.js index e566cafc8ca33b..7844253db9c15f 100644 --- a/test/parallel/test-tls-client-verify.js +++ b/test/parallel/test-tls-client-verify.js @@ -10,7 +10,7 @@ var tls = require('tls'); var fs = require('fs'); -var hosterr = /Hostname\/IP doesn\'t match certificate\'s altnames/g; +var hosterr = /Hostname\/IP doesn't match certificate's altnames/g; var testCases = [{ ca: ['ca1-cert'], key: 'agent2-key', diff --git a/test/sequential/test-process-warnings.js b/test/sequential/test-process-warnings.js index 3ae00c8158d15c..1e8b2b13a20a78 100644 --- a/test/sequential/test-process-warnings.js +++ b/test/sequential/test-process-warnings.js @@ -29,5 +29,5 @@ execFile(node, traceWarn, function(er, stdout, stderr) { assert.equal(er, null); assert.equal(stdout, ''); assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr)); - assert(/at Object\.\\s\(.+warnings.js:3:9\)/.test(stderr)); + assert(/at Object\.\s\(.+warnings.js:3:9\)/.test(stderr)); });