diff --git a/.eslintignore b/.eslintignore index 6dca769b45ccf6..3b9a2f9462f299 100644 --- a/.eslintignore +++ b/.eslintignore @@ -10,3 +10,4 @@ tools/remark-* node_modules benchmark/tmp doc/**/*.js +!.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000000..7526fe0dd8be98 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,263 @@ +'use strict'; + +const Module = require('module'); +const path = require('path'); + +const NodePlugin = require('./tools/node_modules/eslint-plugin-node-core'); +NodePlugin.RULES_DIR = path.resolve(__dirname, 'tools', 'eslint-rules'); + +const ModuleFindPath = Module._findPath; +const hacks = [ + 'eslint-plugin-node-core', + 'eslint-plugin-markdown', + 'babel-eslint', +]; +Module._findPath = (request, paths, isMain) => { + const r = ModuleFindPath(request, paths, isMain); + if (!r && hacks.includes(request)) { + try { + return require.resolve(`./tools/node_modules/${request}`); + } catch (err) { + return require.resolve( + `./tools/node_modules/eslint/node_modules/${request}`); + } + } + return r; +}; + +module.exports = { + root: true, + plugins: ['markdown', 'node-core'], + env: { node: true, es6: true }, + parser: 'babel-eslint', + parserOptions: { sourceType: 'script' }, + overrides: [ + { + files: [ + 'doc/api/esm.md', + '*.mjs', + 'test/es-module/test-esm-example-loader.js', + ], + parserOptions: { sourceType: 'module' }, + }, + ], + rules: { + // Possible Errors + // http://eslint.org/docs/rules/#possible-errors + 'for-direction': 'error', + 'no-control-regex': 'error', + 'no-debugger': 'error', + 'no-dupe-args': 'error', + 'no-dupe-keys': 'error', + 'no-duplicate-case': 'error', + 'no-empty-character-class': 'error', + 'no-ex-assign': 'error', + 'no-extra-boolean-cast': 'error', + 'no-extra-parens': ['error', 'functions'], + 'no-extra-semi': 'error', + 'no-func-assign': 'error', + 'no-invalid-regexp': 'error', + 'no-irregular-whitespace': 'error', + 'no-obj-calls': 'error', + 'no-template-curly-in-string': 'error', + 'no-unexpected-multiline': 'error', + 'no-unreachable': 'error', + 'no-unsafe-negation': 'error', + 'use-isnan': 'error', + 'valid-typeof': 'error', + + // Best Practices + // http://eslint.org/docs/rules/#best-practices + 'accessor-pairs': 'error', + 'array-callback-return': 'error', + 'dot-location': ['error', 'property'], + eqeqeq: ['error', 'smart'], + 'no-fallthrough': 'error', + 'no-global-assign': 'error', + 'no-multi-spaces': ['error', { ignoreEOLComments: true }], + 'no-octal': 'error', + 'no-proto': 'error', + 'no-redeclare': 'error', + 'no-restricted-properties': [ + 'error', + { + object: 'assert', + property: 'deepEqual', + message: 'Use assert.deepStrictEqual().', + }, + { + object: 'assert', + property: 'notDeepEqual', + message: 'Use assert.notDeepStrictEqual().', + }, + { + object: 'assert', + property: 'equal', + message: 'Use assert.astrictEqual() rather than assert.equal().', + }, + { + object: 'assert', + property: 'notEqual', + message: 'Use assert.notStrictEqual() rather than assert.notEqual().', + }, + { + property: '__defineGetter__', + message: '__defineGetter__ is deprecated.', + }, + { + property: '__defineSetter__', + message: '__defineSetter__ is deprecated.', + } + ], + 'no-return-await': 'error', + 'no-self-assign': 'error', + 'no-throw-literal': 'error', + 'no-unused-labels': 'error', + 'no-useless-call': 'error', + 'no-useless-concat': 'error', + 'no-useless-escape': 'error', + 'no-useless-return': 'error', + 'no-void': 'error', + 'no-with': 'error', + + // Strict Mode + // http://eslint.org/docs/rules/#strict-mode + strict: ['error', 'global'], + + // Variables + // http://eslint.org/docs/rules/#variables + 'no-delete-var': 'error', + 'no-undef': 'error', + 'no-unused-vars': ['error', { args: 'none' }], + 'no-use-before-define': ['error', { + classes: true, + functions: false, + variables: false, + }], + + // Node.js and CommonJS + // http://eslint.org/docs/rules/#nodejs-and-commonjs + 'no-mixed-requires': 'error', + 'no-new-require': 'error', + 'no-path-concat': 'error', + 'no-restricted-modules': ['error', 'sys'], + + // Stylistic Issues + // http://eslint.org/docs/rules/#stylistic-issues' + 'block-spacing': 'error', + 'brace-style': ['error', '1tbs', { allowSingleLine: true }], + 'comma-dangle': ['error', 'only-multiline'], + 'comma-spacing': 'error', + 'comma-style': 'error', + 'computed-property-spacing': 'error', + 'eol-last': 'error', + 'func-call-spacing': 'error', + 'func-name-matching': 'error', + 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], + indent: ['error', 2, { + ArrayExpression: 'first', + CallExpression: { arguments: 'first' }, + FunctionDeclaration: { parameters: 'first' }, + FunctionExpression: { parameters: 'first' }, + MemberExpression: 'off', + ObjectExpression: 'first', + SwitchCase: 1, + }], + 'key-spacing': ['error', { mode: 'minimum' }], + 'keyword-spacing': 'error', + 'linebreak-style': ['error', 'unix'], + 'max-len': ['error', { + code: 80, + ignorePattern: '^// Flags:', + ignoreRegExpLiterals: true, + ignoreUrls: true, + tabWidth: 2, + }], + 'new-parens': 'error', + 'no-lonely-if': 'error', + 'no-mixed-spaces-and-tabs': 'error', + 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0, maxBOF: 0 }], + /* eslint-disable max-len, quotes */ + 'no-restricted-syntax': [ + 'error', + { + selector: `CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])`, + message: 'use a regular expression for second argument of assert.throws()', + }, + { + selector: `CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]`, + message: 'assert.throws() must be invoked with at least two arguments.', + }, + { + selector: `CallExpression[callee.name='setTimeout'][arguments.length<2]`, + message: 'setTimeout() must be invoked with at least two arguments.', + }, + { + selector: `CallExpression[callee.name='setInterval'][arguments.length<2]`, + message: 'setInterval() must be invoked with at least 2 arguments.', + }, + { + selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]', + message: 'Use new keyword when throwing an Error.', + } + ], + /* eslint-enable max-len, quotes */ + 'no-tabs': 'error', + 'no-trailing-spaces': 'error', + 'object-curly-spacing': ['error', 'always'], + 'one-var-declaration-per-line': 'error', + 'operator-linebreak': ['error', 'after'], + quotes: ['error', 'single', 'avoid-escape'], + semi: 'error', + 'semi-spacing': 'error', + 'space-before-blocks': ['error', 'always'], + 'space-before-function-paren': ['error', { + anonymous: 'never', + named: 'never', + asyncArrow: 'always', + }], + 'space-in-parens': ['error', 'never'], + 'space-infix-ops': 'error', + 'space-unary-ops': 'error', + 'unicode-bom': 'error', + + // ECMAScript 6 + // http://eslint.org/docs/rules/#ecmascript-6 + 'arrow-parens': ['error', 'always'], + 'arrow-spacing': ['error', { before: true, after: true }], + 'constructor-super': 'error', + 'no-class-assign': 'error', + 'no-confusing-arrow': 'error', + 'no-const-assign': 'error', + 'no-dupe-class-members': 'error', + 'no-new-symbol': 'error', + 'no-this-before-super': 'error', + 'prefer-const': ['error', { ignoreReadBeforeAssign: true }], + 'rest-spread-spacing': 'error', + 'symbol-description': 'error', + 'template-curly-spacing': 'error', + + // Custom rules in from eslint-plugin-node-core + 'node-core/no-unescaped-regexp-dot': 'error', + }, + globals: { + COUNTER_HTTP_CLIENT_REQUEST: false, + COUNTER_HTTP_CLIENT_RESPONSE: false, + COUNTER_HTTP_SERVER_REQUEST: false, + COUNTER_HTTP_SERVER_RESPONSE: false, + COUNTER_NET_SERVER_CONNECTION: false, + COUNTER_NET_SERVER_CONNECTION_CLOSE: false, + DTRACE_HTTP_CLIENT_REQUEST: false, + DTRACE_HTTP_CLIENT_RESPONSE: false, + DTRACE_HTTP_SERVER_REQUEST: false, + DTRACE_HTTP_SERVER_RESPONSE: false, + DTRACE_NET_SERVER_CONNECTION: false, + DTRACE_NET_STREAM_END: false, + LTTNG_HTTP_CLIENT_REQUEST: false, + LTTNG_HTTP_CLIENT_RESPONSE: false, + LTTNG_HTTP_SERVER_REQUEST: false, + LTTNG_HTTP_SERVER_RESPONSE: false, + LTTNG_NET_SERVER_CONNECTION: false, + LTTNG_NET_STREAM_END: false + }, +}; diff --git a/.eslintrc.yaml b/.eslintrc.yaml deleted file mode 100644 index 201af11f017733..00000000000000 --- a/.eslintrc.yaml +++ /dev/null @@ -1,216 +0,0 @@ -root: true - -plugins: - - markdown - -env: - node: true - es6: true - -parser: babel-eslint - -parserOptions: - sourceType: script - -overrides: - - files: ["doc/api/esm.md", "*.mjs", "test/es-module/test-esm-example-loader.js"] - parserOptions: - sourceType: module - -rules: - # Possible Errors - # http://eslint.org/docs/rules/#possible-errors - for-direction: error - no-control-regex: error - no-debugger: error - no-dupe-args: error - no-dupe-keys: error - no-duplicate-case: error - no-empty-character-class: error - no-ex-assign: error - no-extra-boolean-cast: error - no-extra-parens: [error, functions] - no-extra-semi: error - no-func-assign: error - no-invalid-regexp: error - no-irregular-whitespace: error - no-obj-calls: error - no-template-curly-in-string: error - no-unexpected-multiline: error - no-unreachable: error - no-unsafe-negation: error - use-isnan: error - valid-typeof: error - - # Best Practices - # http://eslint.org/docs/rules/#best-practices - accessor-pairs: error - array-callback-return: error - dot-location: [error, property] - dot-notation: error - eqeqeq: [error, smart] - no-fallthrough: error - no-global-assign: error - no-multi-spaces: [error, {ignoreEOLComments: true}] - no-octal: error - no-proto: error - no-redeclare: error - no-restricted-properties: - - error - - object: assert - property: deepEqual - message: Use assert.deepStrictEqual(). - - object: assert - property: notDeepEqual - message: Use assert.notDeepStrictEqual(). - - object: assert - property: equal - message: Use assert.strictEqual() rather than assert.equal(). - - object: assert - property: notEqual - message: Use assert.notStrictEqual() rather than assert.notEqual(). - - property: __defineGetter__ - message: __defineGetter__ is deprecated. - - property: __defineSetter__ - message: __defineSetter__ is deprecated. - no-return-await: error - no-self-assign: error - no-self-compare: error - no-throw-literal: error - no-unused-labels: error - no-useless-call: error - no-useless-concat: error - no-useless-escape: error - no-useless-return: error - no-void: error - no-with: error - - # Strict Mode - # http://eslint.org/docs/rules/#strict-mode - strict: [error, global] - - # Variables - # http://eslint.org/docs/rules/#variables - no-delete-var: error - no-undef: error - no-unused-vars: [error, {args: none}] - no-use-before-define: [error, {classes: true, - functions: false, - variables: false}] - - # Node.js and CommonJS - # http://eslint.org/docs/rules/#nodejs-and-commonjs - no-mixed-requires: error - no-new-require: error - no-path-concat: error - no-restricted-modules: [error, sys] - - # Stylistic Issues - # http://eslint.org/docs/rules/#stylistic-issues - block-spacing: error - brace-style: [error, 1tbs, {allowSingleLine: true}] - comma-dangle: [error, only-multiline] - comma-spacing: error - comma-style: error - computed-property-spacing: error - eol-last: error - func-call-spacing: error - func-name-matching: error - func-style: [error, declaration, {allowArrowFunctions: true}] - indent: [error, 2, {ArrayExpression: first, - CallExpression: {arguments: first}, - FunctionDeclaration: {parameters: first}, - FunctionExpression: {parameters: first}, - MemberExpression: off, - ObjectExpression: first, - SwitchCase: 1}] - key-spacing: [error, {mode: minimum}] - keyword-spacing: error - linebreak-style: [error, unix] - max-len: [error, {code: 80, - ignorePattern: "^\/\/ Flags:", - ignoreRegExpLiterals: true, - ignoreUrls: true, - tabWidth: 2}] - new-parens: error - no-lonely-if: error - no-mixed-spaces-and-tabs: error - no-multiple-empty-lines: [error, {max: 2, maxEOF: 0, maxBOF: 0}] - no-restricted-syntax: [error, { - selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']", - message: "Please replace `assert.doesNotThrow()` and add a comment next to the code instead." - }, { - selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])", - message: "Use a regular expression for second argument of assert.throws()" - }, { - selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]", - message: "assert.throws() must be invoked with at least two arguments." - }, { - selector: "CallExpression[callee.name='setTimeout'][arguments.length<2]", - message: "setTimeout() must be invoked with at least two arguments." - }, { - selector: "CallExpression[callee.name='setInterval'][arguments.length<2]", - message: "setInterval() must be invoked with at least 2 arguments." - }, { - selector: "ThrowStatement > CallExpression[callee.name=/Error$/]", - message: "Use new keyword when throwing an Error." - }] - no-tabs: error - no-trailing-spaces: error - no-unsafe-finally: error - object-curly-spacing: [error, always] - one-var-declaration-per-line: error - operator-linebreak: [error, after] - quotes: [error, single, avoid-escape] - semi: error - semi-spacing: error - space-before-blocks: [error, always] - space-before-function-paren: [error, { - anonymous: never, - named: never, - asyncArrow: always - }] - space-in-parens: [error, never] - space-infix-ops: error - space-unary-ops: error - unicode-bom: error - - # ECMAScript 6 - # http://eslint.org/docs/rules/#ecmascript-6 - arrow-parens: [error, always] - arrow-spacing: [error, {before: true, after: true}] - constructor-super: error - no-class-assign: error - no-confusing-arrow: error - no-const-assign: error - no-dupe-class-members: error - no-new-symbol: error - no-this-before-super: error - prefer-const: [error, {ignoreReadBeforeAssign: true}] - rest-spread-spacing: error - symbol-description: error - template-curly-spacing: error - - # Custom rules in tools/eslint-rules - no-unescaped-regexp-dot: error - -# Global scoped method and vars -globals: - COUNTER_HTTP_CLIENT_REQUEST: false - COUNTER_HTTP_CLIENT_RESPONSE: false - COUNTER_HTTP_SERVER_REQUEST: false - COUNTER_HTTP_SERVER_RESPONSE: false - COUNTER_NET_SERVER_CONNECTION: false - COUNTER_NET_SERVER_CONNECTION_CLOSE: false - DTRACE_HTTP_CLIENT_REQUEST: false - DTRACE_HTTP_CLIENT_RESPONSE: false - DTRACE_HTTP_SERVER_REQUEST: false - DTRACE_HTTP_SERVER_RESPONSE: false - DTRACE_NET_SERVER_CONNECTION: false - DTRACE_NET_STREAM_END: false - LTTNG_HTTP_CLIENT_REQUEST: false - LTTNG_HTTP_CLIENT_RESPONSE: false - LTTNG_HTTP_SERVER_REQUEST: false - LTTNG_HTTP_SERVER_RESPONSE: false - LTTNG_NET_SERVER_CONNECTION: false - LTTNG_NET_STREAM_END: false diff --git a/.gitignore b/.gitignore index a9d428ad6abafc..7be817acce2349 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ !tools/doc/node_modules/**/.* !.editorconfig !.eslintignore -!.eslintrc.yaml +!.eslintrc.js !.gitattributes !.github !.gitignore diff --git a/Makefile b/Makefile index bde51631ff5871..6eb7cac6b1f86f 100644 --- a/Makefile +++ b/Makefile @@ -1108,7 +1108,7 @@ endif LINT_JS_TARGETS = benchmark doc lib test tools run-lint-js = tools/node_modules/eslint/bin/eslint.js --cache \ - --rulesdir=tools/eslint-rules --ext=.js,.mjs,.md $(LINT_JS_TARGETS) + --ext=.js,.mjs,.md $(LINT_JS_TARGETS) --ignore-pattern '!.eslintrc.js' run-lint-js-fix = $(run-lint-js) --fix .PHONY: lint-js-fix diff --git a/benchmark/buffers/buffer-base64-decode-wrapped.js b/benchmark/buffers/buffer-base64-decode-wrapped.js index 61e3bb654ee7c0..1e6f1fde0ae3c8 100644 --- a/benchmark/buffers/buffer-base64-decode-wrapped.js +++ b/benchmark/buffers/buffer-base64-decode-wrapped.js @@ -13,7 +13,7 @@ function main({ n }) { const line = `${'abcd'.repeat(charsPerLine / 4)}\n`; const data = line.repeat(linesCount); - // eslint-disable-next-line no-unescaped-regexp-dot + // eslint-disable-next-line node-core/no-unescaped-regexp-dot data.match(/./); // Flatten the string const buffer = Buffer.alloc(bytesCount, line, 'base64'); diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 492922fb2b6eac..1631ed4f089fd7 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -8,7 +8,7 @@ const bench = common.createBenchmark(main, { function main({ n }) { const s = 'abcd'.repeat(8 << 20); - // eslint-disable-next-line no-unescaped-regexp-dot + // eslint-disable-next-line node-core/no-unescaped-regexp-dot s.match(/./); // Flatten string. assert.strictEqual(s.length % 4, 0); const b = Buffer.allocUnsafe(s.length / 4 * 3); diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 4eebdb6617c101..6ec81a725d4736 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -1,10 +1,10 @@ rules: # Custom rules in tools/eslint-rules - require-buffer: error - buffer-constructor: error - no-let-in-for-declaration: error - lowercase-name-for-primitive: error - non-ascii-character: error + node-core/require-buffer: error + node-core/buffer-constructor: error + node-core/no-let-in-for-declaration: error + node-core/lowercase-name-for-primitive: error + node-core/non-ascii-character: error globals: CHECK: false CHECK_EQ: false diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 4b2aed31537ce7..f33df67af8c645 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1,6 +1,6 @@ -/* eslint documented-errors: "error" */ -/* eslint alphabetize-errors: "error" */ -/* eslint prefer-util-format-errors: "error" */ +/* eslint node-core/documented-errors: "error" */ +/* eslint node-core/alphabetize-errors: "error" */ +/* eslint node-core/prefer-util-format-errors: "error" */ 'use strict'; diff --git a/lib/internal/test/unicode.js b/lib/internal/test/unicode.js index 7172a43ec20a8a..451c3c4737898a 100644 --- a/lib/internal/test/unicode.js +++ b/lib/internal/test/unicode.js @@ -3,6 +3,6 @@ // This module exists entirely for regression testing purposes. // See `test/parallel/test-internal-unicode.js`. -/* eslint-disable non-ascii-character */ +/* eslint-disable node-core/non-ascii-character */ module.exports = '✓'; -/* eslint-enable non-ascii-character */ +/* eslint-enable node-core/non-ascii-character */ diff --git a/lib/timers.js b/lib/timers.js index 4d3f655a1a1271..97eb3f213a637d 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -96,7 +96,7 @@ const TIMEOUT_MAX = 2 ** 31 - 1; // TimerWrap C++ handle, which makes the call after the duration to process the // list it is attached to. // -/* eslint-disable non-ascii-character */ +/* eslint-disable node-core/non-ascii-character */ // // ╔════ > Object Map // ║ @@ -118,7 +118,7 @@ const TIMEOUT_MAX = 2 ** 31 - 1; // ║ // ╚════ > Linked List // -/* eslint-enable non-ascii-character */ +/* eslint-enable node-core/non-ascii-character */ // // With this, virtually constant-time insertion (append), removal, and timeout // is possible in the JavaScript layer. Any one list of timers is able to be diff --git a/lib/util.js b/lib/util.js index 70fd1a05564389..36c386f6e95d3c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -629,7 +629,7 @@ function formatPrimitive(fn, value, ctx) { // 2. If none matches, non-greedy match any text up to a whitespace or // the end of the string. // - // eslint-disable-next-line max-len, no-unescaped-regexp-dot + // eslint-disable-next-line max-len, node-core/no-unescaped-regexp-dot readableRegExps[divisor] = new RegExp(`(.|\\n){1,${divisor}}(\\s|$)|(\\n|.)+?(\\s|$)`, 'gm'); } const indent = ' '.repeat(ctx.indentationLvl); diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index dbcb8ea6e0aa87..a3fa2c2c8d0465 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -8,15 +8,15 @@ rules: symbol-description: off # Custom rules in tools/eslint-rules - prefer-assert-iferror: error - prefer-assert-methods: error - prefer-common-expectserror: error - prefer-common-mustnotcall: error - crypto-check: error - inspector-check: error - number-isnan: error + node-core/prefer-assert-iferror: error + node-core/prefer-assert-methods: error + node-core/prefer-common-expectserror: error + node-core/prefer-common-mustnotcall: error + node-core/crypto-check: error + node-core/inspector-check: error + node-core/number-isnan: error ## common module is mandatory in tests - required-modules: [error, common] + node-core/required-modules: [error, common] # Global scoped methods and vars globals: diff --git a/test/addons/hello-world-esm/test.mjs b/test/addons/hello-world-esm/test.mjs index 6e481ab4f72120..d98de5bf87c771 100644 --- a/test/addons/hello-world-esm/test.mjs +++ b/test/addons/hello-world-esm/test.mjs @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import assert from 'assert'; import binding from './build/binding.node'; diff --git a/test/common/README.md b/test/common/README.md index 8081091ed8ec52..01064a7a8b73f1 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -392,7 +392,7 @@ require a particular action to be taken after a given number of completed tasks (for instance, shutting down an HTTP server after a specific number of requests). The Countdown will fail the test if the remainder did not reach 0. - + ```js const Countdown = require('../common/countdown'); @@ -526,7 +526,7 @@ Returns the result of The http2.js module provides a handful of utilities for creating mock HTTP/2 frames for testing of HTTP/2 endpoints - + ```js const http2 = require('../common/http2'); ``` @@ -536,7 +536,7 @@ const http2 = require('../common/http2'); The `http2.Frame` is a base class that creates a `Buffer` containing a serialized HTTP/2 frame header. - + ```js // length is a 24-bit unsigned integer // type is an 8-bit unsigned integer identifying the frame type @@ -555,7 +555,7 @@ The serialized `Buffer` may be retrieved using the `frame.data` property. The `http2.DataFrame` is a subclass of `http2.Frame` that serializes a `DATA` frame. - + ```js // id is the 32-bit stream identifier // payload is a Buffer containing the DATA payload @@ -572,7 +572,7 @@ socket.write(frame.data); The `http2.HeadersFrame` is a subclass of `http2.Frame` that serializes a `HEADERS` frame. - + ```js // id is the 32-bit stream identifier // payload is a Buffer containing the HEADERS payload (see either @@ -590,7 +590,7 @@ socket.write(frame.data); The `http2.SettingsFrame` is a subclass of `http2.Frame` that serializes an empty `SETTINGS` frame. - + ```js // ack is a boolean indicating whether or not to set the ACK flag. const frame = new http2.SettingsFrame(ack); @@ -603,7 +603,7 @@ socket.write(frame.data); Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2 request headers to be used as the payload of a `http2.HeadersFrame`. - + ```js const frame = new http2.HeadersFrame(1, http2.kFakeRequestHeaders, 0, true); @@ -615,7 +615,7 @@ socket.write(frame.data); Set to a `Buffer` instance that contains a minimal set of serialized HTTP/2 response headers to be used as the payload a `http2.HeadersFrame`. - + ```js const frame = new http2.HeadersFrame(1, http2.kFakeResponseHeaders, 0, true); @@ -627,7 +627,7 @@ socket.write(frame.data); Set to a `Buffer` containing the preamble bytes an HTTP/2 client must send upon initial establishment of a connection. - + ```js socket.write(http2.kClientMagic); ``` diff --git a/test/common/benchmark.js b/test/common/benchmark.js index 6496da1cfb9fe5..1fd4476ba55a35 100644 --- a/test/common/benchmark.js +++ b/test/common/benchmark.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; diff --git a/test/common/countdown.js b/test/common/countdown.js index 5fcb77c4ed66a0..67252657ec28b7 100644 --- a/test/common/countdown.js +++ b/test/common/countdown.js @@ -1,4 +1,5 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ + 'use strict'; const assert = require('assert'); diff --git a/test/common/dns.js b/test/common/dns.js index 69c67ac541cf98..07f84d7a3703c1 100644 --- a/test/common/dns.js +++ b/test/common/dns.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const assert = require('assert'); diff --git a/test/common/duplexpair.js b/test/common/duplexpair.js index ea5bd86a041b24..fb4faca5483b76 100644 --- a/test/common/duplexpair.js +++ b/test/common/duplexpair.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const { Duplex } = require('stream'); const assert = require('assert'); diff --git a/test/common/fixtures.js b/test/common/fixtures.js index b4b7c042e805a9..b45e5bc8091865 100644 --- a/test/common/fixtures.js +++ b/test/common/fixtures.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const path = require('path'); diff --git a/test/common/http2.js b/test/common/http2.js index 1d4c269fffd5b5..0f3378e9b80f63 100644 --- a/test/common/http2.js +++ b/test/common/http2.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; // An HTTP/2 testing tool used to create mock frames for direct testing diff --git a/test/common/index.js b/test/common/index.js index 1fc029292abb10..54b146814a453a 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -19,7 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -/* eslint-disable required-modules, crypto-check */ +/* eslint-disable node-core/required-modules, node-core/crypto-check */ 'use strict'; const process = global.process; // Some tests tamper with the process global. const path = require('path'); diff --git a/test/common/index.mjs b/test/common/index.mjs index 00eceb79d4c003..6d6fe4997bdb71 100644 --- a/test/common/index.mjs +++ b/test/common/index.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import assert from 'assert'; diff --git a/test/common/internet.js b/test/common/internet.js index 48b532ca8e6606..3880aa114e3743 100644 --- a/test/common/internet.js +++ b/test/common/internet.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; // Utilities for internet-related tests diff --git a/test/common/shared-lib-util.js b/test/common/shared-lib-util.js index 89b1231e5cc66c..e9659091567fa8 100644 --- a/test/common/shared-lib-util.js +++ b/test/common/shared-lib-util.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const common = require('../common'); const path = require('path'); diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index ed731b3e7a1ffb..d0221abbb2f069 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const fs = require('fs'); diff --git a/test/common/wpt.js b/test/common/wpt.js index 52d8b7a580400c..7cd644dc88c097 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const assert = require('assert'); diff --git a/test/es-module/esm-snapshot-mutator.js b/test/es-module/esm-snapshot-mutator.js index a0dfa0c28a92bd..6c9a707306fe14 100644 --- a/test/es-module/esm-snapshot-mutator.js +++ b/test/es-module/esm-snapshot-mutator.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; const shouldSnapshotFilePath = require.resolve('./esm-snapshot.js'); require('./esm-snapshot.js'); diff --git a/test/es-module/esm-snapshot.js b/test/es-module/esm-snapshot.js index 2c3c3a459a738b..f52c6f3adff769 100644 --- a/test/es-module/esm-snapshot.js +++ b/test/es-module/esm-snapshot.js @@ -1,3 +1,3 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; module.exports = 1; diff --git a/test/es-module/test-esm-example-loader.js b/test/es-module/test-esm-example-loader.js index 9d1348292cd5a5..f7f0fd059a4d76 100644 --- a/test/es-module/test-esm-example-loader.js +++ b/test/es-module/test-esm-example-loader.js @@ -1,5 +1,5 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/example-loader.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import assert from 'assert'; import ok from './test-esm-ok.mjs'; diff --git a/test/es-module/test-esm-forbidden-globals.mjs b/test/es-module/test-esm-forbidden-globals.mjs index d3e92b9238adba..d92df1611f043e 100644 --- a/test/es-module/test-esm-forbidden-globals.mjs +++ b/test/es-module/test-esm-forbidden-globals.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ if (typeof arguments !== 'undefined') { throw new Error('not an ESM'); diff --git a/test/es-module/test-esm-json.mjs b/test/es-module/test-esm-json.mjs index 39279b74e5407c..5b432e03958600 100644 --- a/test/es-module/test-esm-json.mjs +++ b/test/es-module/test-esm-json.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import '../common/index'; import assert from 'assert'; import ok from './test-esm-ok.mjs'; diff --git a/test/es-module/test-esm-loader-dependency.mjs b/test/es-module/test-esm-loader-dependency.mjs index 5d05118dbf2879..260bf613a75ed8 100644 --- a/test/es-module/test-esm-loader-dependency.mjs +++ b/test/es-module/test-esm-loader-dependency.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import './test-esm-ok.mjs'; // We just test that this module doesn't fail loading diff --git a/test/es-module/test-esm-main-lookup.mjs b/test/es-module/test-esm-main-lookup.mjs index 7c81cb647cff38..12f12c845caedf 100644 --- a/test/es-module/test-esm-main-lookup.mjs +++ b/test/es-module/test-esm-main-lookup.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import assert from 'assert'; import main from '../fixtures/es-modules/pjson-main'; diff --git a/test/es-module/test-esm-named-exports.mjs b/test/es-module/test-esm-named-exports.mjs index c70e16e2167722..9698ae3d9c0907 100644 --- a/test/es-module/test-esm-named-exports.mjs +++ b/test/es-module/test-esm-named-exports.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import '../common/index'; import { readFile } from 'fs'; import assert from 'assert'; diff --git a/test/es-module/test-esm-namespace.mjs b/test/es-module/test-esm-namespace.mjs index f6e550c2e5245e..6a5ee28a54520f 100644 --- a/test/es-module/test-esm-namespace.mjs +++ b/test/es-module/test-esm-namespace.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import '../common/index'; import * as fs from 'fs'; diff --git a/test/es-module/test-esm-ok.mjs b/test/es-module/test-esm-ok.mjs index 6712e1ab7dfca1..49de5c47ec23e7 100644 --- a/test/es-module/test-esm-ok.mjs +++ b/test/es-module/test-esm-ok.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ const isJs = true; export default isJs; diff --git a/test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs b/test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs index bfeb71ef3a607a..2ca0f5658119e9 100644 --- a/test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs +++ b/test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs @@ -1,3 +1,3 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import './not-found.js'; diff --git a/test/es-module/test-esm-preserve-symlinks-not-found.mjs b/test/es-module/test-esm-preserve-symlinks-not-found.mjs index 22c888028e7ba3..5119957bae7c6a 100644 --- a/test/es-module/test-esm-preserve-symlinks-not-found.mjs +++ b/test/es-module/test-esm-preserve-symlinks-not-found.mjs @@ -1,3 +1,3 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import './not-found'; diff --git a/test/es-module/test-esm-resolve-hook.mjs b/test/es-module/test-esm-resolve-hook.mjs index dd7ac80bec4331..e2d20a42d425dc 100644 --- a/test/es-module/test-esm-resolve-hook.mjs +++ b/test/es-module/test-esm-resolve-hook.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/js-loader.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import { namedExport } from '../fixtures/es-module-loaders/js-as-esm.js'; import assert from 'assert'; import ok from './test-esm-ok.mjs'; diff --git a/test/es-module/test-esm-shared-loader-dep.mjs b/test/es-module/test-esm-shared-loader-dep.mjs index 970bfd7121a721..03668cbc993a2f 100644 --- a/test/es-module/test-esm-shared-loader-dep.mjs +++ b/test/es-module/test-esm-shared-loader-dep.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-shared-dep.mjs -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import assert from 'assert'; import './test-esm-ok.mjs'; import dep from '../fixtures/es-module-loaders/loader-dep.js'; diff --git a/test/es-module/test-esm-shebang.mjs b/test/es-module/test-esm-shebang.mjs index 43cc0f8367d8a2..96cec8ea98e921 100644 --- a/test/es-module/test-esm-shebang.mjs +++ b/test/es-module/test-esm-shebang.mjs @@ -1,6 +1,6 @@ #! }]) // isn't js // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ const isJs = true; export default isJs; diff --git a/test/es-module/test-esm-snapshot.mjs b/test/es-module/test-esm-snapshot.mjs index 878be79a34044c..4d3cf245a3ce9d 100644 --- a/test/es-module/test-esm-snapshot.mjs +++ b/test/es-module/test-esm-snapshot.mjs @@ -1,5 +1,5 @@ // Flags: --experimental-modules -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ import '../common/index'; import './esm-snapshot-mutator'; import one from './esm-snapshot'; diff --git a/test/parallel/test-accessor-properties.js b/test/parallel/test-accessor-properties.js index 13535ceda9667f..350e8125f8442c 100644 --- a/test/parallel/test-accessor-properties.js +++ b/test/parallel/test-accessor-properties.js @@ -51,7 +51,7 @@ const UDP = process.binding('udp_wrap').UDP; 'object' ); - if (common.hasCrypto) { // eslint-disable-line crypto-check + if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check // There are accessor properties in crypto too const crypto = process.binding('crypto'); diff --git a/test/parallel/test-assert-fail.js b/test/parallel/test-assert-fail.js index 8d67a6e63f51f5..bb8db335790785 100644 --- a/test/parallel/test-assert-fail.js +++ b/test/parallel/test-assert-fail.js @@ -1,6 +1,6 @@ 'use strict'; -/* eslint-disable prefer-common-expectserror */ +/* eslint-disable node-core/prefer-common-expectserror */ const common = require('../common'); const assert = require('assert'); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 6375311fa6e31c..65b9c05a0624d6 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -21,7 +21,7 @@ 'use strict'; -/* eslint-disable prefer-common-expectserror */ +/* eslint-disable node-core/prefer-common-expectserror */ const common = require('../common'); const assert = require('assert'); diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 20e91377cd7fdf..69e36b033e138d 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -915,7 +915,7 @@ common.expectsError( } } -if (common.hasCrypto) { // eslint-disable-line crypto-check +if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check // Test truncation after decode const crypto = require('crypto'); diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index fb290568309ee2..9d6c6c7d351e45 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -62,7 +62,7 @@ function assertWrongList(value) { }); } -// eslint-disable-next-line crypto-check +// eslint-disable-next-line node-core/crypto-check const random10 = common.hasCrypto ? require('crypto').randomBytes(10) : Buffer.alloc(10, 1); diff --git a/test/parallel/test-global-console-exists.js b/test/parallel/test-global-console-exists.js index 1434b76e12696e..f2e7ba5a9aa3a0 100644 --- a/test/parallel/test-global-console-exists.js +++ b/test/parallel/test-global-console-exists.js @@ -1,4 +1,4 @@ -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; diff --git a/test/parallel/test-http-invalid-urls.js b/test/parallel/test-http-invalid-urls.js index 51e680071a92a3..9a5567aab897f8 100644 --- a/test/parallel/test-http-invalid-urls.js +++ b/test/parallel/test-http-invalid-urls.js @@ -1,4 +1,4 @@ -/* eslint-disable crypto-check */ +/* eslint-disable node-core/crypto-check */ 'use strict'; diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 2090d76b75ee34..7b77a42a167525 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -125,9 +125,9 @@ const qsColonTestCases = [ function extendedFunction() {} extendedFunction.prototype = { a: 'b' }; const qsWeirdObjects = [ - // eslint-disable-next-line no-unescaped-regexp-dot + // eslint-disable-next-line node-core/no-unescaped-regexp-dot [{ regexp: /./g }, 'regexp=', { 'regexp': '' }], - // eslint-disable-next-line no-unescaped-regexp-dot + // eslint-disable-next-line node-core/no-unescaped-regexp-dot [{ regexp: new RegExp('.', 'g') }, 'regexp=', { 'regexp': '' }], [{ fn: () => {} }, 'fn=', { 'fn': '' }], [{ fn: new Function('') }, 'fn=', { 'fn': '' }], diff --git a/test/parallel/test-regression-object-prototype.js b/test/parallel/test-regression-object-prototype.js index 01de440344d352..821c2af584ae3b 100644 --- a/test/parallel/test-regression-object-prototype.js +++ b/test/parallel/test-regression-object-prototype.js @@ -19,7 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -/* eslint-disable required-modules */ +/* eslint-disable node-core/required-modules */ 'use strict'; Object.prototype.xadsadsdasasdxx = function() { diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 45f53ee9d7a82d..44a6bfaf0921f6 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -89,14 +89,14 @@ function testInitialized(req, ctor_name) { } -if (common.hasCrypto) { // eslint-disable-line crypto-check +if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check const tls = require('tls'); // SecurePair testInitialized(tls.createSecurePair().ssl, 'Connection'); } -if (common.hasCrypto) { // eslint-disable-line crypto-check +if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check const crypto = require('crypto'); // The handle for PBKDF2 and RandomBytes isn't returned by the function call, @@ -237,7 +237,7 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check } -if (common.hasCrypto) { // eslint-disable-line crypto-check +if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); const tcp = new TCP(TCPConstants.SOCKET); diff --git a/test/sequential/test-inspector-overwrite-config.js b/test/sequential/test-inspector-overwrite-config.js index 9aa3ca9d963828..8b641a0048484a 100644 --- a/test/sequential/test-inspector-overwrite-config.js +++ b/test/sequential/test-inspector-overwrite-config.js @@ -9,7 +9,7 @@ // We cannot do a check for the inspector because the configuration variables // were reset/removed by overwrite-config-preload-module.js. -/* eslint-disable inspector-check */ +/* eslint-disable node-core/inspector-check */ const common = require('../common'); const assert = require('assert'); diff --git a/tools/node_modules/eslint-plugin-node-core/index.js b/tools/node_modules/eslint-plugin-node-core/index.js new file mode 100644 index 00000000000000..e27945688ee691 --- /dev/null +++ b/tools/node_modules/eslint-plugin-node-core/index.js @@ -0,0 +1,24 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +let cache; +module.exports = { + get rules() { + const RULES_DIR = module.exports.RULES_DIR; + if (!RULES_DIR) + return {}; + + if (!cache) { + cache = {}; + const files = fs.readdirSync(RULES_DIR) + .filter(filename => filename.endsWith('.js')) + for (const file of files) { + const name = file.slice(0, -3); + cache[name] = require(path.resolve(RULES_DIR, file)); + } + } + return cache; + }, +}; diff --git a/vcbuild.bat b/vcbuild.bat index a2aa4061ae4464..5a46c5d05f9b73 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -557,7 +557,7 @@ if defined lint_js_ci goto lint-js-ci if not defined lint_js goto exit if not exist tools\node_modules\eslint goto no-lint echo running lint-js -%config%\node tools\node_modules\eslint\bin\eslint.js --cache --rule "linebreak-style: 0" --rulesdir=tools\eslint-rules --ext=.js,.mjs,.md benchmark doc lib test tools +%config%\node tools\node_modules\eslint\bin\eslint.js --cache --rule "linebreak-style: 0" --ext=.js,.mjs,.md benchmark doc lib test tools goto exit :lint-js-ci