Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add number-isnan eslint rule #17556

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
};