Skip to content

Commit 6531401

Browse files
maclover7MylesBorins
authored andcommitted
tools: add number-isnan rule
PR-URL: #17556 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 7d03567 commit 6531401

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

test/.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rules:
1414
prefer-common-mustnotcall: error
1515
crypto-check: error
1616
inspector-check: error
17+
number-isnan: error
1718
## common module is mandatory in tests
1819
required-modules: [error, common]
1920

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const RuleTester = require('../../tools/eslint').RuleTester;
6+
const rule = require('../../tools/eslint-rules/number-isnan');
7+
8+
const message = 'Please use Number.isNaN instead of the global isNaN function';
9+
10+
new RuleTester().run('number-isnan', rule, {
11+
valid: [
12+
'Number.isNaN()'
13+
],
14+
invalid: [
15+
{
16+
code: 'isNaN()',
17+
errors: [{ message }]
18+
}
19+
]
20+
});

tools/eslint-rules/number-isnan.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const astSelector = "CallExpression[callee.name='isNaN']";
4+
const msg = 'Please use Number.isNaN instead of the global isNaN function';
5+
6+
module.exports = function(context) {
7+
function report(node) {
8+
context.report(node, msg);
9+
}
10+
11+
return {
12+
[astSelector]: report
13+
};
14+
};

0 commit comments

Comments
 (0)