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: enable ESLint recommended rule set #41463

Merged
merged 6 commits into from
Jan 14, 2022
Merged
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
56 changes: 9 additions & 47 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Module._findPath = (request, paths, isMain) => {

module.exports = {
root: true,
extends: ['plugin:jsdoc/recommended'],
extends: ['eslint:recommended', 'plugin:jsdoc/recommended'],
plugins: ['jsdoc', 'markdown', 'node-core'],
parser: '@babel/eslint-parser',
parserOptions: {
Expand Down Expand Up @@ -142,17 +142,14 @@ module.exports = {
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': 'error',
'constructor-super': 'error',
'default-case-last': 'error',
'dot-location': ['error', 'property'],
'dot-notation': 'error',
'eol-last': 'error',
'eqeqeq': ['error', 'smart'],
'for-direction': 'error',
'func-call-spacing': 'error',
'func-name-matching': 'error',
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'getter-return': 'error',
'indent': ['error', 2, {
ArrayExpression: 'first',
CallExpression: { arguments: 'first' },
Expand All @@ -174,43 +171,17 @@ module.exports = {
tabWidth: 2,
}],
'new-parens': 'error',
'no-async-promise-executor': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-confusing-arrow': 'error',
'no-const-assign': 'error',
'no-constant-condition': ['error', { checkLoops: false }],
'no-constructor-return': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-keys': 'error',
'no-dupe-else-if': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
'no-else-return': ['error', { allowElseIf: true }],
'no-empty-character-class': 'error',
'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
'no-extra-parens': ['error', 'functions'],
'no-extra-semi': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-lonely-if': 'error',
'no-misleading-character-class': 'error',
'no-mixed-requires': 'error',
'no-mixed-spaces-and-tabs': 'error',
'no-multi-spaces': ['error', { ignoreEOLComments: true }],
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }],
'no-new-require': 'error',
'no-new-symbol': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-obj-calls': 'error',
'no-octal': 'error',
'no-path-concat': 'error',
'no-proto': 'error',
'no-redeclare': ['error', { 'builtinGlobals': false }],
Expand Down Expand Up @@ -270,40 +241,26 @@ module.exports = {
],
/* eslint-enable max-len */
'no-return-await': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
'no-setter-return': 'error',
'no-shadow-restricted-names': 'error',
'no-tabs': 'error',
'no-template-curly-in-string': 'error',
'no-this-before-super': 'error',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef': ['error', { typeof: true }],
'no-undef-init': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true }],
'no-unused-labels': 'error',
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }],
'no-use-before-define': ['error', {
classes: true,
functions: false,
variables: false,
}],
'no-useless-backreference': 'error',
'no-useless-call': 'error',
'no-useless-catch': 'error',
'no-useless-concat': 'error',
'no-useless-constructor': 'error',
'no-useless-escape': 'error',
'no-useless-return': 'error',
'no-void': 'error',
'no-whitespace-before-property': 'error',
'no-with': 'error',
'object-curly-newline': 'error',
'object-curly-spacing': ['error', 'always'],
'one-var': ['error', { initialized: 'never' }],
Expand Down Expand Up @@ -337,10 +294,15 @@ module.exports = {
'symbol-description': 'error',
'template-curly-spacing': 'error',
'unicode-bom': 'error',
'use-isnan': 'error',
'valid-typeof': ['error', { requireStringLiterals: true }],

// JSDoc rules
// ESLint recommended rules that we disable
'no-cond-assign': 'off',
'no-empty': 'off',
'no-inner-declarations': 'off',
'no-prototype-builtins': 'off',

// JSDoc recommended rules that we disable
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/newline-after-description': 'off',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/get_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const protocolHandlers = ObjectAssign(ObjectCreate(null), {
const { 1: mime } = RegExpPrototypeExec(
/^([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/,
parsed.pathname,
) || [, null];
) || [, null]; // eslint-disable-line no-sparse-arrays
const format = ({
'__proto__': null,
'text/javascript': 'module',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const strEscapeSequencesReplacerSingle = /[\x00-\x1f\x5c\x7f-\x9f]|[\ud800-\udbf
const keyStrRegExp = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
const numberRegExp = /^(0|[1-9][0-9]*)$/;

const coreModuleRegExp = /^ at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/;
const coreModuleRegExp = /^ {4}at (?:[^/\\(]+ \(|)node:(.+):\d+:\d+\)?$/;
const nodeModulesRegExp = /[/\\]node_modules[/\\](.+?)(?=[/\\])/g;

const classRegExp = /^(\s+[^(]*?)\s*{/;
Expand Down
2 changes: 2 additions & 0 deletions test/js-native-api/test_number/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ testNumber(-1233);
testNumber(986583);
testNumber(-976675);

/* eslint-disable no-loss-of-precision */
testNumber(
98765432213456789876546896323445679887645323232436587988766545658);
testNumber(
-4350987086545760976737453646576078997096876957864353245245769809);
/* eslint-enable no-loss-of-precision */
testNumber(Number.MIN_SAFE_INTEGER);
testNumber(Number.MAX_SAFE_INTEGER);
testNumber(Number.MAX_SAFE_INTEGER + 10);
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,10 @@ assertNotDeepOrStrict(

// Handle sparse arrays.
{
/* eslint-disable no-sparse-arrays */
assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
assertNotDeepOrStrict([1, , , 3], [1, , , 3, , , ]);
/* eslint-enable no-sparse-arrays */
const a = new Array(3);
const b = new Array(3);
a[2] = true;
Expand Down Expand Up @@ -1123,7 +1125,7 @@ assert.throws(
{
code: 'ERR_ASSERTION',
name: 'AssertionError',
message: /a: \[Getter: 5]\n- a: \[Getter: 6]\n /
message: /a: \[Getter: 5]\n- {3}a: \[Getter: 6]\n {2}/
}
);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ assert.throws(
assert.deepStrictEqual(Array(100).fill(1), 'foobar');
} catch (err) {
threw = true;
assert.match(inspect(err), /actual: \[Array],\n expected: 'foobar',/);
assert.match(inspect(err), /actual: \[Array],\n {2}expected: 'foobar',/);
}
assert(threw);
}
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-buffer-readdouble.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ assert.strictEqual(buffer.readDoubleLE(0), 1.0000000000000004);
buffer[0] = 1;
buffer[6] = 0;
buffer[7] = 0;
// eslint-disable-next-line no-loss-of-precision
assert.strictEqual(buffer.readDoubleBE(0), 7.291122019556398e-304);
assert.strictEqual(buffer.readDoubleLE(0), 5e-324);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-debugger-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function launchTarget(...args) {
.then(() => {
assert.match(
cli.output,
/> 3 \+\+x;/,
/> 3 {3}\+\+x;/,
'marks the 3rd line');
})
.then(() => cleanup())
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-events-uncaught-exception-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ process.on('uncaughtException', common.mustCall((err) => {
const lines = err.stack.split('\n');
assert.strictEqual(lines[0], 'Error');
lines.slice(1).forEach((line) => {
assert.match(line, /^ at/);
assert.match(line, /^ {4}at/);
});
}));

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http2-stream-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ server.on('stream', common.mustCall((stream) => {
assert.strictEqual(stream.aborted, false);
const insp = util.inspect(stream);
assert.match(insp, /Http2Stream {/);
assert.match(insp, / state:/);
assert.match(insp, / readableState:/);
assert.match(insp, / writableState:/);
assert.match(insp, / {2}state:/);
assert.match(insp, / {2}readableState:/);
assert.match(insp, / {2}writableState:/);
stream.end('ok');
}));
server.listen(0, common.mustCall(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-readable-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async function toReadableOnDataNonObject() {
}

async function destroysTheStreamWhenThrowing() {
async function* generate() {
async function* generate() { // eslint-disable-line require-yield
throw new Error('kaboom');
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-definecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ r.defineCommand('say2', function() {
});

inputStream.write('.help\n');
assert.match(output, /\n\.say1 help for say1\n/);
assert.match(output, /\n\.say1 {5}help for say1\n/);
assert.match(output, /\n\.say2\n/);
inputStream.write('.say1 node developer\n');
assert.ok(output.startsWith('hello node developer\n'),
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function testError() {
// The sync error, with individual property echoes
/^Uncaught Error: ENOENT: no such file or directory, scandir '.*nonexistent\?'/,
/Object\.readdirSync/,
/^ errno: -(2|4058),$/,
/^ {2}errno: -(2|4058),$/,
" syscall: 'scandir',",
" code: 'ENOENT',",
" path: '/nonexistent?'",
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,10 @@ const errorTests = [
/^Uncaught Error: Cannot find module 'internal\/repl'/,
/^Require stack:/,
/^- <repl>/,
/^ at .*/,
/^ at .*/,
/^ at .*/,
/^ at .*/,
/^ {4}at .*/,
/^ {4}at .*/,
/^ {4}at .*/,
/^ {4}at .*/,
" code: 'MODULE_NOT_FOUND',",
" requireStack: [ '<repl>' ]",
'}',
Expand Down Expand Up @@ -776,12 +776,12 @@ const errorTests = [
' group: [Function: group],',
' groupEnd: [Function: groupEnd],',
' table: [Function: table],',
/ debug: \[Function: (debug|log)],/,
/ info: \[Function: (info|log)],/,
/ dirxml: \[Function: (dirxml|log)],/,
/ error: \[Function: (error|warn)],/,
/ groupCollapsed: \[Function: (groupCollapsed|group)],/,
/ Console: \[Function: Console],?/,
/ {2}debug: \[Function: (debug|log)],/,
/ {2}info: \[Function: (info|log)],/,
/ {2}dirxml: \[Function: (dirxml|log)],/,
/ {2}error: \[Function: (error|warn)],/,
/ {2}groupCollapsed: \[Function: (groupCollapsed|group)],/,
/ {2}Console: \[Function: Console],?/,
...process.features.inspector ? [
' profile: [Function: profile],',
' profileEnd: [Function: profileEnd],',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const assert = require('assert');
callback(null, chunk);
})
}),
async function*(source) {
async function*(source) { // eslint-disable-line require-yield
let tmp = '';
for await (const chunk of source) {
tmp += chunk;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-duplex-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const { Duplex, Readable, Writable, pipeline } = require('stream');
}
yield rest;
}),
async function * (source) {
async function * (source) { // eslint-disable-line require-yield
let ret = '';
for await (const x of source) {
ret += x;
Expand Down
Loading