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 <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
maclover7 authored and MylesBorins committed Jan 23, 2018
1 parent 7fa140f commit a84d145
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 @@ -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]

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 a84d145

Please sign in to comment.