Skip to content

Commit 301cc7a

Browse files
committed
tools: switch to explicit number-isnan rule
1 parent 4d7d595 commit 301cc7a

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

.eslintrc.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ rules:
146146
}, {
147147
selector: "ThrowStatement > CallExpression[callee.name=/Error$/]",
148148
message: "Use new keyword when throwing an Error."
149-
}, {
150-
selector: "CallExpression[callee.name='isNaN']",
151-
message: "Please use Number.isNaN instead of the global isNaN function"
152149
}]
153150
no-tabs: error
154151
no-trailing-spaces: error

test/.eslintrc.yaml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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)