summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2017-12-11 17:20:39 -0500
committerGibson Fahnestock <gibfahn@gmail.com>2018-01-24 02:45:20 +0000
commit0e37054c9620d85bab94e7db98a48c1accd0ffed (patch)
tree167ef0c5ba511bc165ae4dc3c358e132e13705d4
parent2f3d91dc58ea710ca111f8006f74b18609c3470b (diff)
downloadnode-new-0e37054c9620d85bab94e7db98a48c1accd0ffed.tar.gz
tools: add number-isnan rule
PR-URL: https://github.com/nodejs/node/pull/17556 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r--test/.eslintrc.yaml1
-rw-r--r--test/parallel/test-eslint-number-isnan.js20
-rw-r--r--tools/eslint-rules/number-isnan.js14
3 files changed, 35 insertions, 0 deletions
diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml
index aa320996aa..23d2184860 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 0000000000..deeac48bcc
--- /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 0000000000..885c38be8b
--- /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
+ };
+};