Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(generic-spacing): avoid overriding extends
  • Loading branch information
antfu committed Oct 31, 2022
1 parent 4b51ef2 commit 4119f52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Expand Up @@ -9,6 +9,7 @@ type Foo<
T = true,
K = false
> = T`,
'type Foo<T extends true = true> = T',
]
const invalids = [
['type Foo<T=true> = T', 'type Foo<T = true> = T'],
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin-antfu/src/rules/generic-spacing.ts
Expand Up @@ -48,15 +48,16 @@ export default createEslintRule<Options, MessageIds>({
TSTypeParameter: (node) => {
if (!node.default)
return
const from = node.name.range[1]
const endNode = node.constraint || node.name
const from = endNode.range[1]
const to = node.default.range[0]
if (sourceCode.text.slice(from, to) !== ' = ') {
context.report({
*fix(fixer) {
yield fixer.replaceTextRange([from, to], ' = ')
},
loc: {
start: node.name.loc.end,
start: endNode.loc.end,
end: node.default.loc.start,
},
messageId: 'genericSpacingMismatch',
Expand Down

0 comments on commit 4119f52

Please sign in to comment.