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, T = true,
K = false K = false
> = T`, > = T`,
'type Foo<T extends true = true> = T',
] ]
const invalids = [ const invalids = [
['type Foo<T=true> = T', 'type Foo<T = true> = T'], ['type Foo<T=true> = T', 'type Foo<T = true> = T'],

View File

@ -48,7 +48,8 @@ export default createEslintRule<Options, MessageIds>({
TSTypeParameter: (node) => { TSTypeParameter: (node) => {
if (!node.default) if (!node.default)
return return
const from = node.name.range[1] const endNode = node.constraint || node.name
const from = endNode.range[1]
const to = node.default.range[0] const to = node.default.range[0]
if (sourceCode.text.slice(from, to) !== ' = ') { if (sourceCode.text.slice(from, to) !== ' = ') {
context.report({ context.report({
@ -56,7 +57,7 @@ export default createEslintRule<Options, MessageIds>({
yield fixer.replaceTextRange([from, to], ' = ') yield fixer.replaceTextRange([from, to], ' = ')
}, },
loc: { loc: {
start: node.name.loc.end, start: endNode.loc.end,
end: node.default.loc.start, end: node.default.loc.start,
}, },
messageId: 'genericSpacingMismatch', messageId: 'genericSpacingMismatch',