Skip to content

Commit

Permalink
tools: add number-isnan rule
Browse files Browse the repository at this point in the history
PR-URL: #17556
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
maclover7 committed Dec 19, 2017
1 parent 3b8da4c commit e554bc8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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 e554bc8

Please sign in to comment.