Skip to content

Commit 76653c9

Browse files
authored
fix(valid-title): Please allow function-typed variables and aliases as valid describe titles (#708)
* fix: add function type node check in isClassOrFunctionType * test: add test * refactor: fix lint error
1 parent 2818d59 commit 76653c9

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ const createConfig = <R extends Linter.RulesRecord>(rules: R) => (
7474
[`vitest/${ruleName}`]: rules[ruleName]
7575
}
7676
}, {})) as {
77-
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
78-
}
77+
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
78+
}
7979

8080
const createConfigLegacy = (rules: Record<string, string>) => ({
8181
plugins: ['@vitest'],

src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ export function isClassOrFunctionType(type: ts.Type): boolean {
8787
|| ts.isFunctionDeclaration(declaration)
8888
|| ts.isFunctionExpression(declaration)
8989
|| ts.isMethodDeclaration(declaration)
90+
|| ts.isFunctionTypeNode(declaration)
9091
) ?? false
9192
}

tests/valid-title.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ ruleTester.run(RULE_NAME, rule, {
8181
})
8282
`,
8383
settings: { vitest: { typecheck: true } }
84+
},
85+
{
86+
code: `
87+
type Func = (params: object) => void
88+
const func: Func = (params) => console.log(params)
89+
describe(func, () => {
90+
test('item', () => {
91+
expect(0).toBe(0)
92+
})
93+
});`,
94+
settings: { vitest: { typecheck: true } }
8495
}
8596
],
8697
invalid: [

0 commit comments

Comments
 (0)