Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: new eslint rules #18831

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -165,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', {
Expand Down Expand Up @@ -211,10 +212,12 @@ 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': ['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'],
Expand Down
4 changes: 2 additions & 2 deletions benchmark/http/_chunky_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});

Expand Down
6 changes: 3 additions & 3 deletions benchmark/tls/tls-connect.js
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
1 change: 1 addition & 0 deletions doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
4 changes: 2 additions & 2 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
```

Expand Down
2 changes: 1 addition & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 22 additions & 23 deletions test/parallel/test-cluster-worker-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-eslint-require-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
});
2 changes: 1 addition & 1 deletion test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-https-agent-servername.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
};


Expand Down