Skip to content

Commit 60aafcb

Browse files
authored
fix(no-whitespace-before-property): detect whitespace in TSIndexedAccessType with parens (#1099)
1 parent 0b19e08 commit 60aafcb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/eslint-plugin/rules/no-whitespace-before-property/no-whitespace-before-property._ts_.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ run<RuleOptions, MessageIds>({
1212
`type Foo = A['B']`,
1313
`type Foo = A.B`,
1414
`type Foo = import(A).B`,
15+
// https://github.com/eslint-stylistic/eslint-stylistic/issues/1097
16+
`type Test = ( typeof arr )[ number ];`,
1517
],
1618

1719
invalid: [
@@ -30,5 +32,11 @@ run<RuleOptions, MessageIds>({
3032
output: `type Foo = import(A).B`,
3133
errors: [{ messageId: 'unexpectedWhitespace', data: { propName: 'B' } }],
3234
},
35+
// https://github.com/eslint-stylistic/eslint-stylistic/issues/1097
36+
{
37+
code: `type Test = ( typeof arr ) [ number ];`,
38+
output: `type Test = ( typeof arr )[ number ];`,
39+
errors: [{ messageId: 'unexpectedWhitespace', data: { propName: 'number' } }],
40+
},
3341
],
3442
})

packages/eslint-plugin/rules/no-whitespace-before-property/no-whitespace-before-property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export default createRule<RuleOptions, MessageIds>({
9999
})
100100
},
101101
TSIndexedAccessType(node) {
102-
const leftToken = node.objectType
103-
const rightToken = sourceCode.getTokenBefore(node.indexType)!
102+
const rightToken = sourceCode.getTokenBefore(node.indexType, isOpeningBracketToken)!
103+
const leftToken = sourceCode.getTokenBefore(rightToken)!
104104

105105
if (!sourceCode.isSpaceBetween(leftToken, rightToken))
106106
return

0 commit comments

Comments
 (0)