Skip to content

Commit

Permalink
tools: add additional ESLint rules
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
not-an-aardvark committed Sep 21, 2016
1 parent 66df5d1 commit b1b1978
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 33 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ 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
no-octal: 2
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
Expand Down Expand Up @@ -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}]
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions benchmark/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});
}

Expand Down
20 changes: 10 additions & 10 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/message/throw_in_line_with_tabs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable indent */
/* eslint-disable indent, no-tabs */
'use strict';
require('../common');

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-debug-protocol-execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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$/
);
2 changes: 1 addition & 1 deletion test/parallel/test-http-multi-line-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-response-multi-content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-response-multiheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-regress-GH-5727.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");',
Expand Down Expand Up @@ -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}',
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream2-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-tls-cipher-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-client-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-process-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\.\<anonymous\>\s\(.+warnings.js:3:9\)/.test(stderr));
assert(/at Object\.<anonymous>\s\(.+warnings.js:3:9\)/.test(stderr));
});

0 comments on commit b1b1978

Please sign in to comment.