Skip to content

Commit e7e25b8

Browse files
authored
prefer-number-properties: Fix some edge cases (sindresorhus#1170)
1 parent e67bd6d commit e7e25b8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

rules/prefer-number-properties.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ const propertiesSelector = [
3636
'MemberExpression[computed=false] > .property',
3737
'FunctionDeclaration > .id',
3838
'ClassDeclaration > .id',
39+
// TODO: remove `ClassProperty` when `babel` and `typescript` support `FieldDefinition`
3940
'ClassProperty[computed=false] > .key',
41+
'FieldDefinition[computed=false] > .key',
4042
'MethodDefinition[computed=false] > .key',
4143
'VariableDeclarator > .id',
4244
'Property[shorthand=false][computed=false] > .key',
45+
'LabeledStatement > .label',
46+
'ContinueStatement > .label',
47+
'BreakStatement > .label',
48+
'ExportSpecifier > .local',
49+
'ExportSpecifier > .exported',
50+
'ExportAllDeclaration > .exported',
51+
'ImportSpecifier > .local',
52+
'ImportSpecifier > .imported',
53+
'ImportNamespaceSpecifier > .local',
54+
'ImportDefaultSpecifier > .local',
4355
'TSDeclareFunction > .id',
4456
'TSEnumMember > .id',
4557
'TSPropertySignature > .key'

test/prefer-number-properties.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ test({
187187
'function NaN() {}',
188188
'class NaN {}',
189189
'class Foo {NaN(){}}',
190+
outdent`
191+
NaN: for (const foo of bar) {
192+
if (a) {
193+
continue NaN;
194+
} else {
195+
break NaN;
196+
}
197+
}
198+
`,
199+
'import {NaN} from "foo"',
200+
'import {NaN as NaN} from "foo"',
201+
'import NaN from "foo"',
202+
'import * as NaN from "foo"',
203+
'export {NaN} from "foo"',
204+
'export {NaN as NaN} from "foo"',
205+
'export * as NaN from "foo"',
190206

191207
'const foo = Number.POSITIVE_INFINITY;',
192208
'const foo = window.Number.POSITIVE_INFINITY;',

0 commit comments

Comments
 (0)