From 9c05ebf3fb34f9d04c201976eb74295ebb88ade1 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 5 Jan 2020 22:49:27 -0500 Subject: [PATCH] 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. --- .eslintrc.js | 4 ++++ lib/.eslintrc.yaml | 2 ++ test/.eslintrc.yaml | 1 - test/parallel/test-eslint-number-isnan.js | 24 ----------------------- test/root.status | 1 - tools/eslint-rules/number-isnan.js | 14 ------------- 6 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 test/parallel/test-eslint-number-isnan.js delete mode 100644 tools/eslint-rules/number-isnan.js diff --git a/.eslintrc.js b/.eslintrc.js index 8acba223d986eb..59d585b9d355bd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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', diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 04084df3fd9d57..35b78a41a1b403 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -57,6 +57,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 diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index 81e470322052f9..86d4b595e7dc9a 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -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 diff --git a/test/parallel/test-eslint-number-isnan.js b/test/parallel/test-eslint-number-isnan.js deleted file mode 100644 index 73359be3bcd37f..00000000000000 --- a/test/parallel/test-eslint-number-isnan.js +++ /dev/null @@ -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 }] - } - ] -}); diff --git a/test/root.status b/test/root.status index af4bc90e97c0fb..43e4aea29d9c4c 100644 --- a/test/root.status +++ b/test/root.status @@ -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 diff --git a/tools/eslint-rules/number-isnan.js b/tools/eslint-rules/number-isnan.js deleted file mode 100644 index 885c38be8b2384..00000000000000 --- a/tools/eslint-rules/number-isnan.js +++ /dev/null @@ -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 - }; -};