Browse Source

tools: add additional ESLint rules

PR-URL: https://github.com/nodejs/node/pull/8643
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@keybase.io>
v7.x
Teddy Katz 8 years ago
parent
commit
b1b1978ec5
No known key found for this signature in database GPG Key ID: B79EC7ABC0AA53A0
  1. 9
      .eslintrc
  2. 4
      benchmark/util/format.js
  3. 2
      lib/_tls_wrap.js
  4. 2
      lib/internal/bootstrap_node.js
  5. 6
      test/inspector/inspector-helper.js
  6. 20
      test/inspector/test-inspector.js
  7. 2
      test/message/throw_in_line_with_tabs.js
  8. 2
      test/parallel/test-http-multi-line-headers.js
  9. 2
      test/parallel/test-http-response-multi-content-length.js
  10. 2
      test/parallel/test-http-response-multiheaders.js
  11. 2
      test/parallel/test-regress-GH-5727.js
  12. 4
      test/parallel/test-repl.js
  13. 4
      test/parallel/test-stream2-writable.js
  14. 6
      test/parallel/test-tls-cipher-list.js
  15. 2
      test/parallel/test-tls-client-verify.js
  16. 2
      test/sequential/test-process-warnings.js

9
.eslintrc

@ -30,6 +30,7 @@ rules:
# Best Practices # Best Practices
# http://eslint.org/docs/rules/#best-practices # http://eslint.org/docs/rules/#best-practices
dot-location: [2, property]
no-fallthrough: 2 no-fallthrough: 2
no-global-assign: 2 no-global-assign: 2
no-multi-spaces: 2 no-multi-spaces: 2
@ -37,6 +38,10 @@ rules:
no-redeclare: 2 no-redeclare: 2
no-self-assign: 2 no-self-assign: 2
no-unused-labels: 2 no-unused-labels: 2
no-useless-call: 2
no-useless-escape: 2
no-void: 2
no-with: 2
# Strict Mode # Strict Mode
# http://eslint.org/docs/rules/#strict-mode # http://eslint.org/docs/rules/#strict-mode
@ -64,6 +69,8 @@ rules:
# http://eslint.org/docs/rules/#stylistic-issues # http://eslint.org/docs/rules/#stylistic-issues
brace-style: [2, 1tbs, {allowSingleLine: true}] brace-style: [2, 1tbs, {allowSingleLine: true}]
comma-spacing: 2 comma-spacing: 2
comma-style: 2
computed-property-spacing: 2
eol-last: 2 eol-last: 2
func-call-spacing: 2 func-call-spacing: 2
indent: [2, 2, {SwitchCase: 1, MemberExpression: 1}] indent: [2, 2, {SwitchCase: 1, MemberExpression: 1}]
@ -74,9 +81,11 @@ rules:
new-parens: 2 new-parens: 2
no-mixed-spaces-and-tabs: 2 no-mixed-spaces-and-tabs: 2
no-multiple-empty-lines: [2, {max: 2}] no-multiple-empty-lines: [2, {max: 2}]
no-tabs: 2
no-trailing-spaces: 2 no-trailing-spaces: 2
quotes: [2, single, avoid-escape] quotes: [2, single, avoid-escape]
semi: 2 semi: 2
semi-spacing: 2
space-before-blocks: [2, always] space-before-blocks: [2, always]
space-before-function-paren: [2, never] space-before-function-paren: [2, never]
space-in-parens: [2, never] space-in-parens: [2, never]

4
benchmark/util/format.js

@ -4,8 +4,8 @@ const util = require('util');
const common = require('../common'); const common = require('../common');
const v8 = require('v8'); const v8 = require('v8');
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
n: [1e6] n: [1e6],
, type: ['string', type: ['string',
'number', 'number',
'object', 'object',
'unknown', 'unknown',

2
lib/_tls_wrap.js

@ -918,7 +918,7 @@ Server.prototype.addContext = function(servername, context) {
var re = new RegExp('^' + var re = new RegExp('^' +
servername.replace(/([\.^$+?\-\\[\]{}])/g, '\\$1') servername.replace(/([\.^$+?\-\\[\]{}])/g, '\\$1')
.replace(/\*/g, '[^\.]*') + .replace(/\*/g, '[^.]*') +
'$'); '$');
this._contexts.push([re, tls.createSecureContext(context).context]); this._contexts.push([re, tls.createSecureContext(context).context]);
}; };

2
lib/internal/bootstrap_node.js

@ -125,7 +125,7 @@
const filename = Module._resolveFilename(process.argv[1]); const filename = Module._resolveFilename(process.argv[1]);
var source = fs.readFileSync(filename, 'utf-8'); var source = fs.readFileSync(filename, 'utf-8');
// remove shebang and BOM // remove shebang and BOM
source = internalModule.stripBOM(source.replace(/^\#\!.*/, '')); source = internalModule.stripBOM(source.replace(/^#!.*/, ''));
// wrap it // wrap it
source = Module.wrap(source); source = Module.wrap(source);
// compile the script, this will throw if it fails // compile the script, this will throw if it fails

6
test/inspector/inspector-helper.js

@ -77,9 +77,9 @@ function checkHttpResponse(port, path, callback) {
http.get({port, path}, function(res) { http.get({port, path}, function(res) {
let response = ''; let response = '';
res.setEncoding('utf8'); res.setEncoding('utf8');
res. res
on('data', (data) => response += data.toString()). .on('data', (data) => response += data.toString())
on('end', () => callback(JSON.parse(response))); .on('end', () => callback(JSON.parse(response)));
}); });
} }

20
test/inspector/test-inspector.js

@ -85,9 +85,9 @@ function testBreakpointOnStart(session) {
{ 'method': 'Runtime.runIfWaitingForDebugger' } { 'method': 'Runtime.runIfWaitingForDebugger' }
]; ];
session. session
sendInspectorCommands(commands). .sendInspectorCommands(commands)
expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session)); .expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session));
} }
function testSetBreakpointAndResume(session) { function testSetBreakpointAndResume(session) {
@ -105,9 +105,9 @@ function testSetBreakpointAndResume(session) {
'params': { 'scriptId': session.mainScriptId } }, 'params': { 'scriptId': session.mainScriptId } },
expectMainScriptSource ], expectMainScriptSource ],
]; ];
session. session
sendInspectorCommands(commands). .sendInspectorCommands(commands)
expectMessages([ .expectMessages([
setupExpectConsoleOutput('log', ['A message', 5]), setupExpectConsoleOutput('log', ['A message', 5]),
setupExpectBreakOnLine(5, session.mainScriptPath, setupExpectBreakOnLine(5, session.mainScriptPath,
session, (id) => scopeId = id), session, (id) => scopeId = id),
@ -131,7 +131,7 @@ function testInspectScope(session) {
[ [
{ {
'method': 'Debugger.evaluateOnCallFrame', 'params': { 'method': 'Debugger.evaluateOnCallFrame', 'params': {
'callFrameId': '{\"ordinal\":0,\"injectedScriptId\":1}', 'callFrameId': '{"ordinal":0,"injectedScriptId":1}',
'expression': 'k + t', 'expression': 'k + t',
'objectGroup': 'console', 'objectGroup': 'console',
'includeCommandLineAPI': true, 'includeCommandLineAPI': true,
@ -153,9 +153,9 @@ function testInspectScope(session) {
function testWaitsForFrontendDisconnect(session, harness) { function testWaitsForFrontendDisconnect(session, harness) {
console.log('[test]', 'Verify node waits for the frontend to disconnect'); console.log('[test]', 'Verify node waits for the frontend to disconnect');
session.sendInspectorCommands({ 'method': 'Debugger.resume'}). session.sendInspectorCommands({ 'method': 'Debugger.resume'})
expectStderrOutput('Waiting for the debugger to disconnect...'). .expectStderrOutput('Waiting for the debugger to disconnect...')
disconnect(true); .disconnect(true);
} }
function runTests(harness) { function runTests(harness) {

2
test/message/throw_in_line_with_tabs.js

@ -1,4 +1,4 @@
/* eslint-disable indent */ /* eslint-disable indent, no-tabs */
'use strict'; 'use strict';
require('../common'); require('../common');

2
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-Length: ' + body.length + '\r\n' +
'Content-Type: text/plain;\r\n' + 'Content-Type: text/plain;\r\n' +
' x-unix-mode=0600;\r\n' + ' x-unix-mode=0600;\r\n' +
' name=\"hello.txt\"\r\n' + ' name="hello.txt"\r\n' +
'\r\n' + '\r\n' +
body; body;

2
test/parallel/test-http-response-multi-content-length.js

@ -27,7 +27,7 @@ const server = http.createServer((req, res) => {
var count = 0; var count = 0;
server.listen(0, common.mustCall(() => { 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 // This runs twice, the first time, the server will use
// setHeader, the second time it uses writeHead. In either // setHeader, the second time it uses writeHead. In either
// case, the error handler must be called because the client // case, the error handler must be called because the client

2
test/parallel/test-http-response-multiheaders.js

@ -48,7 +48,7 @@ const server = http.createServer(function(req, res) {
server.listen(0, common.mustCall(function() { server.listen(0, common.mustCall(function() {
var count = 0; 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 // this runs twice, the first time, the server will use
// setHeader, the second time it uses writeHead. The // setHeader, the second time it uses writeHead. The
// result on the client side should be the same in // result on the client side should be the same in

2
test/parallel/test-regress-GH-5727.js

@ -4,7 +4,7 @@ const assert = require('assert');
const net = require('net'); const net = require('net');
const invalidPort = -1 >>> 0; 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() { net.Server().listen(common.PORT, function() {
const address = this.address(); const address = this.address();

4
test/parallel/test-repl.js

@ -160,7 +160,7 @@ function error_test() {
// invalid RegExps are a special case of syntax error, // invalid RegExps are a special case of syntax error,
// should throw // should throw
{ client: client_unix, send: '/(/;', { client: client_unix, send: '/(/;',
expect: /\bSyntaxError: Invalid regular expression\:/ }, expect: /\bSyntaxError: Invalid regular expression:/ },
// invalid RegExp modifiers are a special case of syntax error, // invalid RegExp modifiers are a special case of syntax error,
// should throw (GH-4012) // should throw (GH-4012)
{ client: client_unix, send: 'new RegExp("foo", "wrong modifier");', { 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}", { client: client_unix, send: "function x(s) {\nreturn s.replace(/'/,'');\n}",
expect: prompt_multiline + prompt_multiline + expect: prompt_multiline + prompt_multiline +
'undefined\n' + prompt_unix }, '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 + expect: prompt_multiline + prompt_multiline +
'undefined\n' + prompt_unix }, '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}',

4
test/parallel/test-stream2-writable.js

@ -154,7 +154,7 @@ test('write bufferize', function(t) {
}); });
chunks.forEach(function(chunk, i) { chunks.forEach(function(chunk, i) {
var enc = encodings[ i % encodings.length ]; var enc = encodings[i % encodings.length];
chunk = Buffer.from(chunk); chunk = Buffer.from(chunk);
tw.write(chunk.toString(enc), enc); tw.write(chunk.toString(enc), enc);
}); });
@ -192,7 +192,7 @@ test('write no bufferize', function(t) {
}); });
chunks.forEach(function(chunk, i) { chunks.forEach(function(chunk, i) {
var enc = encodings[ i % encodings.length ]; var enc = encodings[i % encodings.length];
chunk = Buffer.from(chunk); chunk = Buffer.from(chunk);
tw.write(chunk.toString(enc), enc); tw.write(chunk.toString(enc), enc);
}); });

6
test/parallel/test-tls-cipher-list.js

@ -16,9 +16,9 @@ function doCheck(arg, check) {
'-pe', '-pe',
'require("crypto").constants.defaultCipherList' 'require("crypto").constants.defaultCipherList'
]); ]);
spawn(process.execPath, arg, {}). spawn(process.execPath, arg, {})
on('error', common.fail). .on('error', common.fail)
stdout.on('data', function(chunk) { .stdout.on('data', function(chunk) {
out += chunk; out += chunk;
}).on('end', function() { }).on('end', function() {
assert.equal(out.trim(), check); assert.equal(out.trim(), check);

2
test/parallel/test-tls-client-verify.js

@ -10,7 +10,7 @@ var tls = require('tls');
var fs = require('fs'); 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 = var testCases =
[{ ca: ['ca1-cert'], [{ ca: ['ca1-cert'],
key: 'agent2-key', key: 'agent2-key',

2
test/sequential/test-process-warnings.js

@ -29,5 +29,5 @@ execFile(node, traceWarn, function(er, stdout, stderr) {
assert.equal(er, null); assert.equal(er, null);
assert.equal(stdout, ''); assert.equal(stdout, '');
assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr)); assert(/^\(.+\)\sWarning: a bad practice warning/.test(stderr));
assert(/at Object\.\<anonymous\>\s\(.+warnings.js:3:9\)/.test(stderr)); assert(/at Object\.<anonymous>\s\(.+warnings.js:3:9\)/.test(stderr));
}); });

Loading…
Cancel
Save