Skip to content

Commit e86bef1

Browse files
committed
turn on by default
1 parent f544b63 commit e86bef1

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

docs/rules/prefer-number-properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const isNegativeZero = value => value === 0 && 1 / value === Number.NEGATIVE_INF
130130
### checkNaN
131131

132132
Type: `boolean`\
133-
Default: `false`
133+
Default: `true`
134134

135135
Pass `checkNaN: false` to disable check on `NaN`.
136136

rules/prefer-number-properties.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const create = context => {
8080
checkNaN,
8181
} = {
8282
checkInfinity: false,
83-
checkNaN: false,
83+
checkNaN: true,
8484
...context.options[0],
8585
};
8686
const {sourceCode} = context;
@@ -117,7 +117,7 @@ const schema = [
117117
},
118118
checkNaN: {
119119
type: 'boolean',
120-
default: false,
120+
default: true,
121121
},
122122
},
123123
},

test/prefer-number-properties.mjs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ function withCheckInfinity(code) {
209209
};
210210
}
211211

212-
function withCheckNaN(code) {
213-
return {
214-
code,
215-
options: [{checkNaN: true}],
216-
};
217-
}
218-
219212
test({
220213
valid: [
221214
'const foo = Number.NaN;',
@@ -288,52 +281,54 @@ test({
288281
'class Foo { Infinity(){}}',
289282
'const foo = Infinity;',
290283
'const foo = -Infinity;',
291-
'const foo = NaN;',
292-
'const foo = -NaN;',
284+
{
285+
code: 'const foo = NaN',
286+
options: [{checkNaN: false}],
287+
},
293288
],
294289
invalid: [
295290
{
296-
...withCheckNaN('const foo = NaN;'),
291+
code: 'const foo = NaN;',
297292
output: 'const foo = Number.NaN;',
298293
errors: errorNaN,
299294
},
300295
{
301-
...withCheckNaN('if (Number.isNaN(NaN)) {}'),
296+
code: 'if (Number.isNaN(NaN)) {}',
302297
output: 'if (Number.isNaN(Number.NaN)) {}',
303298
errors: errorNaN,
304299
},
305300
{
306-
...withCheckNaN('if (Object.is(foo, NaN)) {}'),
301+
code: 'if (Object.is(foo, NaN)) {}',
307302
output: 'if (Object.is(foo, Number.NaN)) {}',
308303
errors: errorNaN,
309304
},
310305
{
311-
...withCheckNaN('const foo = bar[NaN];'),
306+
code: 'const foo = bar[NaN];',
312307
output: 'const foo = bar[Number.NaN];',
313308
errors: errorNaN,
314309
},
315310
{
316-
...withCheckNaN('const foo = {NaN};'),
311+
code: 'const foo = {NaN};',
317312
output: 'const foo = {NaN: Number.NaN};',
318313
errors: errorNaN,
319314
},
320315
{
321-
...withCheckNaN('const foo = {NaN: NaN};'),
316+
code: 'const foo = {NaN: NaN};',
322317
output: 'const foo = {NaN: Number.NaN};',
323318
errors: errorNaN,
324319
},
325320
{
326-
...withCheckNaN('const {foo = NaN} = {};'),
321+
code: 'const {foo = NaN} = {};',
327322
output: 'const {foo = Number.NaN} = {};',
328323
errors: errorNaN,
329324
},
330325
{
331-
...withCheckNaN('const foo = NaN.toString();'),
326+
code: 'const foo = NaN.toString();',
332327
output: 'const foo = Number.NaN.toString();',
333328
errors: errorNaN,
334329
},
335330
{
336-
...withCheckNaN('class Foo3 {[NaN] = 1}'),
331+
code: 'class Foo3 {[NaN] = 1}',
337332
output: 'class Foo3 {[Number.NaN] = 1}',
338333
errors: errorNaN,
339334
},
@@ -356,7 +351,7 @@ test.babel({
356351
],
357352
invalid: [
358353
{
359-
...withCheckNaN('class Foo2 {[NaN] = 1}'),
354+
code: 'class Foo2 {[NaN] = 1}',
360355
output: 'class Foo2 {[Number.NaN] = 1}',
361356
errors: 1,
362357
},
@@ -391,7 +386,7 @@ test.typescript({
391386
],
392387
invalid: [
393388
{
394-
...withCheckNaN('class Foo {[NaN] = 1}'),
389+
code: 'class Foo {[NaN] = 1}',
395390
output: 'class Foo {[Number.NaN] = 1}',
396391
errors: 1,
397392
},
@@ -405,11 +400,11 @@ test.snapshot({
405400
'const foo = -(--Infinity);',
406401
],
407402
invalid: [
408-
withCheckNaN('const foo = {[NaN]: 1}'),
409-
withCheckNaN('const foo = {[NaN]() {}}'),
410-
withCheckNaN('foo[NaN] = 1;'),
411-
withCheckNaN('class A {[NaN](){}}'),
412-
withCheckNaN('foo = {[NaN]: 1}'),
403+
'const foo = {[NaN]: 1}',
404+
'const foo = {[NaN]() {}}',
405+
'foo[NaN] = 1;',
406+
'class A {[NaN](){}}',
407+
'foo = {[NaN]: 1}',
413408
withCheckInfinity('const foo = Infinity;'),
414409
withCheckInfinity('if (Number.isNaN(Infinity)) {}'),
415410
withCheckInfinity('if (Object.is(foo, Infinity)) {}'),
@@ -432,12 +427,12 @@ test.snapshot({
432427
withCheckInfinity('const foo = 1 - -Infinity;'),
433428
withCheckInfinity('const isPositiveZero = value => value === 0 && 1 / value === Infinity;'),
434429
withCheckInfinity('const isNegativeZero = value => value === 0 && 1 / value === -Infinity;'),
435-
withCheckNaN('const {a = NaN} = {};'),
436-
withCheckNaN('const {[NaN]: a = NaN} = {};'),
437-
withCheckNaN('const [a = NaN] = [];'),
438-
withCheckNaN('function foo({a = NaN}) {}'),
439-
withCheckNaN('function foo({[NaN]: a = NaN}) {}'),
440-
withCheckNaN('function foo([a = NaN]) {}'),
430+
'const {a = NaN} = {};',
431+
'const {[NaN]: a = NaN} = {};',
432+
'const [a = NaN] = [];',
433+
'function foo({a = NaN}) {}',
434+
'function foo({[NaN]: a = NaN}) {}',
435+
'function foo([a = NaN]) {}',
441436

442437
// Space after keywords
443438
withCheckInfinity('function foo() {return-Infinity}'),
@@ -450,7 +445,7 @@ test.snapshot({
450445
'global.parseFloat(foo);',
451446
'window.parseFloat(foo);',
452447
'self.parseFloat(foo);',
453-
withCheckNaN('globalThis.NaN'),
448+
'globalThis.NaN',
454449
withCheckInfinity('-globalThis.Infinity'),
455450

456451
// Not a call

0 commit comments

Comments
 (0)