Skip to content

Commit

Permalink
tools: switch to explicit number-isnan rule
Browse files Browse the repository at this point in the history
  • Loading branch information
maclover7 committed Dec 14, 2017
1 parent 4d7d595 commit 301cc7a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ rules:
}, {
selector: "ThrowStatement > CallExpression[callee.name=/Error$/]",
message: "Use new keyword when throwing an Error."
}, {
selector: "CallExpression[callee.name='isNaN']",
message: "Please use Number.isNaN instead of the global isNaN function"
}]
no-tabs: error
no-trailing-spaces: error
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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]

Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-eslint-number-isnan.js
Original file line number Diff line number Diff line change
@@ -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 }]
}
]
});
14 changes: 14 additions & 0 deletions tools/eslint-rules/number-isnan.js
Original file line number Diff line number Diff line change
@@ -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
};
};

0 comments on commit 301cc7a

Please sign in to comment.