lint: move eslint to new plugin system

PR-URL: https://github.com/nodejs/node/pull/18566
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
This commit is contained in:
Gus Caplan 2018-02-04 13:38:18 -06:00
parent 7514eb3cff
commit 6934792eb3
55 changed files with 366 additions and 293 deletions

View File

@ -11,3 +11,4 @@ tools/remark-*
node_modules
benchmark/tmp
doc/**/*.js
!.eslintrc.js

264
.eslintrc.js Normal file
View File

@ -0,0 +1,264 @@
'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,
internalBinding: false,
},
};

View File

@ -1,217 +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
internalBinding: false

2
.gitignore vendored
View File

@ -6,7 +6,7 @@
!tools/doc/node_modules/**/.*
!.editorconfig
!.eslintignore
!.eslintrc.yaml
!.eslintrc.js
!.gitattributes
!.github
!.gitignore

View File

@ -1101,7 +1101,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

View File

@ -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');

View File

@ -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);

View File

@ -1,7 +1,7 @@
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

View File

@ -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';

View File

@ -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 */

View File

@ -89,7 +89,7 @@ const kRefed = Symbol('refed');
// 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
// ║
@ -111,7 +111,7 @@ const kRefed = Symbol('refed');
// ║
// ╚════ > 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

View File

@ -633,7 +633,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);

View File

@ -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:

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
import assert from 'assert';
import binding from './build/binding.node';

View File

@ -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.
<!-- eslint-disable strict, required-modules -->
<!-- eslint-disable strict, node-core/required-modules -->
```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
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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`.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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`.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```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.
<!-- eslint-disable no-undef, no-unused-vars, required-modules, strict -->
<!-- eslint-disable no-undef, no-unused-vars, node-core/required-modules, strict -->
```js
socket.write(http2.kClientMagic);
```

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';

View File

@ -1,4 +1,5 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const assert = require('assert');

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const assert = require('assert');

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const { Duplex } = require('stream');
const assert = require('assert');

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const path = require('path');

View File

@ -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

View File

@ -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');

View File

@ -1,5 +1,5 @@
// Flags: --experimental-modules
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
import assert from 'assert';

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
// Utilities for internet-related tests

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const path = require('path');

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const fs = require('fs');

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
const assert = require('assert');

View File

@ -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');

View File

@ -1,3 +1,3 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';
module.exports = 1;

View File

@ -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';

View File

@ -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');

View File

@ -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';

View File

@ -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

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -1,5 +1,5 @@
// Flags: --experimental-modules
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
const isJs = true;
export default isJs;

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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;

View File

@ -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';

View File

@ -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');

View File

@ -23,7 +23,7 @@
'use strict';
/* eslint-disable prefer-common-expectserror */
/* eslint-disable node-core/prefer-common-expectserror */
const common = require('../common');
const assert = require('assert');

View File

@ -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');

View File

@ -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);

View File

@ -1,4 +1,4 @@
/* eslint-disable required-modules */
/* eslint-disable node-core/required-modules */
'use strict';

View File

@ -1,4 +1,4 @@
/* eslint-disable crypto-check */
/* eslint-disable node-core/crypto-check */
'use strict';

View File

@ -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': '' }],

View File

@ -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() {

View File

@ -92,7 +92,7 @@ function testInitialized(req, ctor_name) {
}
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,
@ -240,7 +240,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);

View File

@ -8,7 +8,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');

24
tools/node_modules/eslint-plugin-node-core/index.js generated vendored Normal file
View File

@ -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;
},
};

View File

@ -514,7 +514,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