From 4119f5275036e2801dc6c15208bdd5e5e8f41f69 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 1 Nov 2022 03:38:06 +0800 Subject: [PATCH] fix(generic-spacing): avoid overriding extends --- .../eslint-plugin-antfu/src/rules/generic-spacing.test.ts | 1 + packages/eslint-plugin-antfu/src/rules/generic-spacing.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 9adb31c557..01b7735c7b 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 98426ba50b..0345c3a06e 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',