diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index aa320996aa4b16..23d2184860b346 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -13,6 +13,7 @@ rules: prefer-common-mustnotcall: error crypto-check: error inspector-check: error + number-isnan: error ## common module is mandatory in tests required-modules: [error, common] diff --git a/test/parallel/test-eslint-number-isnan.js b/test/parallel/test-eslint-number-isnan.js new file mode 100644 index 00000000000000..deeac48bcccb68 --- /dev/null +++ b/test/parallel/test-eslint-number-isnan.js @@ -0,0 +1,20 @@ +'use strict'; + +require('../common'); + +const RuleTester = require('../../tools/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/tools/eslint-rules/number-isnan.js b/tools/eslint-rules/number-isnan.js new file mode 100644 index 00000000000000..885c38be8b2384 --- /dev/null +++ b/tools/eslint-rules/number-isnan.js @@ -0,0 +1,14 @@ +'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 + }; +};