| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ rules: | |||
| 8 | 8 | ||
| 9 | 9 | # Custom rules in tools/eslint-rules | |
| 10 | 10 | prefer-common-mustnotcall: 2 | |
| 11 | + number-isnan: error | ||
| 11 | 12 | ||
| 12 | 13 | ## common module is mandatory in tests | |
| 13 | 14 | required-modules: [error, common] | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,12 +51,12 @@ function test(clazz) { | |||
| 51 | 51 | buffer[5] = 0xff; | |
| 52 | 52 | buffer[6] = 0x0f; | |
| 53 | 53 | buffer[7] = 0x00; | |
| 54 | - assert.ok(isNaN(buffer.readDoubleBE(0))); | ||
| 54 | + assert.ok(Number.isNaN(buffer.readDoubleBE(0))); | ||
| 55 | 55 | assert.strictEqual(2.225073858507201e-308, buffer.readDoubleLE(0)); | |
| 56 | 56 | ||
| 57 | 57 | buffer[6] = 0xef; | |
| 58 | 58 | buffer[7] = 0x7f; | |
| 59 | - assert.ok(isNaN(buffer.readDoubleBE(0))); | ||
| 59 | + assert.ok(Number.isNaN(buffer.readDoubleBE(0))); | ||
| 60 | 60 | assert.strictEqual(1.7976931348623157e+308, buffer.readDoubleLE(0)); | |
| 61 | 61 | ||
| 62 | 62 | buffer[0] = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,8 +106,8 @@ function test(clazz) { | |||
| 106 | 106 | // Darwin ia32 does the other kind of NaN. | |
| 107 | 107 | // Compiler bug. No one really cares. | |
| 108 | 108 | assert(0x7F === buffer[7] || 0xFF === buffer[7]); | |
| 109 | - assert.ok(isNaN(buffer.readFloatBE(0))); | ||
| 110 | - assert.ok(isNaN(buffer.readFloatLE(4))); | ||
| 109 | + assert.ok(Number.isNaN(buffer.readFloatBE(0))); | ||
| 110 | + assert.ok(Number.isNaN(buffer.readFloatLE(4))); | ||
| 111 | 111 | } | |
| 112 | 112 | ||
| 113 | 113 | ||
| Original file line number | Diff line number | Diff 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 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments