fix(generic-spacing): improve cases
This commit is contained in:
parent
e13613fd5f
commit
ff6a1fad6a
@ -13,12 +13,24 @@ type Foo<
|
|||||||
`function foo<
|
`function foo<
|
||||||
T
|
T
|
||||||
>() {}`,
|
>() {}`,
|
||||||
|
'const foo = <T>(name: T) => name',
|
||||||
|
`interface Log {
|
||||||
|
foo<T>(name: T): void
|
||||||
|
}`,
|
||||||
|
`interface Log {
|
||||||
|
<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'],
|
||||||
['type Foo<T,K> = T', 'type Foo<T, K> = T'],
|
['type Foo<T,K> = T', 'type Foo<T, K> = T'],
|
||||||
['type Foo<T=false,K=1|2> = T', 'type Foo<T = false, K = 1|2> = T', 3],
|
['type Foo<T=false,K=1|2> = T', 'type Foo<T = false, K = 1|2> = T', 3],
|
||||||
['function foo <T>() {}', 'function foo<T>() {}'],
|
['function foo <T>() {}', 'function foo<T>() {}'],
|
||||||
|
[`interface Log {
|
||||||
|
foo <T>(name: T): void
|
||||||
|
}`, `interface Log {
|
||||||
|
foo<T>(name: T): void
|
||||||
|
}`],
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
it('runs', () => {
|
it('runs', () => {
|
||||||
|
@ -23,6 +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)) {
|
||||||
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>
|
||||||
@ -35,6 +36,7 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add space between <T,K>
|
// add space between <T,K>
|
||||||
const params = node.params
|
const params = node.params
|
||||||
|
Loading…
Reference in New Issue
Block a user