Skip to content

Commit 9fff541

Browse files
fix(valid-title): also allow string types with settings.typecheck (#682)
1 parent c808a21 commit 9fff541

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/rules/valid-title.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ function isClassType(type: ts.Type): boolean {
8686
|| ts.isClassExpression(declaration)) ?? false
8787
}
8888

89+
function isStringLikeType(type: ts.Type): boolean {
90+
return !!(type.flags & (ts.TypeFlags.StringLike))
91+
}
92+
8993
const compileMatcherPatterns = (matchers:
9094
| Partial<Record<MatcherGroups, string | MatcherAndMessage>>
9195
| MatcherAndMessage
@@ -213,7 +217,7 @@ export default createEslintRule<Options, MESSAGE_IDS>({
213217

214218
const type = services.getTypeAtLocation(argument)
215219

216-
if (isFunctionType(type) || isClassType(type)) return
220+
if (isFunctionType(type) || isClassType(type) || isStringLikeType(type)) return
217221
}
218222

219223
if (!argument || (allowArguments && argument.type === AST_NODE_TYPES.Identifier)) return

tests/valid-title.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ ruleTester.run(RULE_NAME, rule, {
3838
`,
3939
settings: { vitest: { typecheck: true } }
4040
},
41+
{
42+
code: `
43+
declare const outerName: string;
44+
describe(outerName, () => {
45+
test('item', () => {
46+
expect(0).toBe(0)
47+
})
48+
})
49+
`,
50+
settings: { vitest: { typecheck: true } }
51+
},
52+
{
53+
code: `
54+
declare const outerName: 'a';
55+
describe(outerName, () => {
56+
test('item', () => {
57+
expect(0).toBe(0)
58+
})
59+
})
60+
`,
61+
settings: { vitest: { typecheck: true } }
62+
},
63+
{
64+
code: `
65+
declare const outerName: \`\${'a'}\`;
66+
describe(outerName, () => {
67+
test('item', () => {
68+
expect(0).toBe(0)
69+
})
70+
})
71+
`,
72+
settings: { vitest: { typecheck: true } }
73+
},
4174
{
4275
code: `
4376
class foo{}

0 commit comments

Comments
 (0)