lib,tools,test: remove custom number-isnan rule

This commit removes the custom number-isnan ESLint rule in
favor of the no-restricted-syntax rule. It also applies the
rule across the entire codebase, instead of just the test/
directory.

PR-URL: https://github.com/nodejs/node/pull/31211
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
cjihrig 2020-01-05 22:49:27 -05:00
parent a494d12723
commit ba98d9ab2c
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
6 changed files with 6 additions and 40 deletions

View File

@ -244,6 +244,10 @@ module.exports = {
selector: "CallExpression[callee.property.name='strictEqual'][arguments.0.type='Literal']:not([arguments.1.type='Literal']):not([arguments.1.type='ObjectExpression']):not([arguments.1.type='ArrayExpression']):not([arguments.1.type='UnaryExpression'])",
message: 'The first argument should be the `actual`, not the `expected` value.',
},
{
selector: "CallExpression[callee.name='isNaN']",
message: 'Use Number.isNaN() instead of the global isNaN() function.',
},
],
/* eslint-enable max-len */
'no-return-await': 'error',

View File

@ -63,6 +63,8 @@ rules:
message: "Please use `require('internal/errors').hideStackFrames()` instead."
- selector: "AssignmentExpression:matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])"
message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'."
- selector: "CallExpression[callee.name='isNaN']"
message: "Use NumberIsNaN() primordial instead of the global isNaN() function."
# Custom rules in tools/eslint-rules
node-core/lowercase-name-for-primitive: error
node-core/non-ascii-character: error

View File

@ -18,7 +18,6 @@ rules:
node-core/crypto-check: error
node-core/eslint-check: error
node-core/inspector-check: error
node-core/number-isnan: error
## common module is mandatory in tests
node-core/required-modules:
- error

View File

@ -1,24 +0,0 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/number-isnan');
const message = 'Please use Number.isNaN instead of the global isNaN function';
new RuleTester().run('number-isnan', rule, {
valid: [
'Number.isNaN()'
],
invalid: [
{
code: 'isNaN()',
errors: [{ message }]
}
]
});

View File

@ -34,7 +34,6 @@ parallel/test-eslint-eslint-check: SLOW
parallel/test-eslint-inspector-check: SLOW
parallel/test-eslint-lowercase-name-for-primitive: SLOW
parallel/test-eslint-no-unescaped-regexp-dot: SLOW
parallel/test-eslint-number-isnan: SLOW
parallel/test-eslint-prefer-assert-iferror: SLOW
parallel/test-eslint-prefer-assert-methods: SLOW
parallel/test-eslint-prefer-common-mustnotcall: SLOW

View File

@ -1,14 +0,0 @@
'use strict';
const astSelector = "CallExpression[callee.name='isNaN']";
const msg = 'Please use Number.isNaN instead of the global isNaN function';
module.exports = function(context) {
function report(node) {
context.report(node, msg);
}
return {
[astSelector]: report
};
};