fix(generic-spacing): improve cases

This commit is contained in:
Anthony Fu 2022-11-07 21:03:56 +08:00
parent 54b234f4ef
commit 95e28e4a4a
2 changed files with 4 additions and 1 deletions

View File

@ -20,6 +20,9 @@ type Foo<
`interface Log { `interface Log {
<T>(name: T): void <T>(name: T): void
}`, }`,
`interface Foo {
foo?: <T>(name: T) => void
}`,
] ]
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

@ -23,7 +23,7 @@ export default createEslintRule<Options, MessageIds>({
const sourceCode = context.getSourceCode() const sourceCode = context.getSourceCode()
return { return {
TSTypeParameterDeclaration: (node) => { 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 pre = sourceCode.text.slice(0, node.range[0])
const preSpace = pre.match(/(\s+)$/)?.[0] const preSpace = pre.match(/(\s+)$/)?.[0]
// strip space before <T> // strip space before <T>