From 95e28e4a4ac582840d77ebf20fd585237bd4cc00 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 7 Nov 2022 21:03:56 +0800 Subject: [PATCH] fix(generic-spacing): improve cases --- packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts | 3 +++ packages/eslint-plugin-antfu/src/rules/generic-spacing.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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 dc98507..c3aa2d3 100644 --- a/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts +++ b/packages/eslint-plugin-antfu/src/rules/generic-spacing.test.ts @@ -20,6 +20,9 @@ type Foo< `interface Log { (name: T): void }`, +`interface Foo { + foo?: (name: T) => void +}`, ] 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 280d3e7..6df03f9 100644 --- a/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts +++ b/packages/eslint-plugin-antfu/src/rules/generic-spacing.ts @@ -23,7 +23,7 @@ export default createEslintRule({ const sourceCode = context.getSourceCode() return { TSTypeParameterDeclaration: (node) => { - if (!['TSCallSignatureDeclaration', 'ArrowFunctionExpression'].includes(node.parent.type)) { + if (!['TSCallSignatureDeclaration', 'ArrowFunctionExpression', 'TSFunctionType'].includes(node.parent.type)) { const pre = sourceCode.text.slice(0, node.range[0]) const preSpace = pre.match(/(\s+)$/)?.[0] // strip space before