fix(generic-spacing): avoid overriding extends

This commit is contained in:
Anthony Fu 2022-11-01 03:38:06 +08:00
parent 4b51ef2eba
commit 4119f52750
2 changed files with 4 additions and 2 deletions

View File

@ -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'],

View File

@ -48,7 +48,8 @@ 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({
@ -56,7 +57,7 @@ export default createEslintRule<Options, MessageIds>({
yield fixer.replaceTextRange([from, to], ' = ')
},
loc: {
start: node.name.loc.end,
start: endNode.loc.end,
end: node.default.loc.start,
},
messageId: 'genericSpacingMismatch',