diff --git a/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts b/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts index 9adb31c..01b7735 100644 --- a/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts +++ b/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts @@ -9,6 +9,7 @@ type Foo< T = true, K = false > = T`, + 'type Foo = T', ] const invalids = [ ['type Foo = T', 'type Foo = T'], diff --git a/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts b/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts index 98426ba..0345c3a 100644 --- a/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts +++ b/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts @@ -48,7 +48,8 @@ export default createEslintRule({ 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({ yield fixer.replaceTextRange([from, to], ' = ') }, loc: { - start: node.name.loc.end, + start: endNode.loc.end, end: node.default.loc.start, }, messageId: 'genericSpacingMismatch',