Skip to content

Commit 8a14d46

Browse files
authored
fix(consistent-test-filename): correct expected options type (#801)
1 parent 0b30e2a commit 8a14d46

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/rules/consistent-test-filename.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const defaultTestsPattern = /.*\.(test|spec)\.[tj]sx?$/
88
export default createEslintRule<
99
[
1010
Partial<{
11-
pattern: RegExp | string
12-
allTestPattern: RegExp | string
11+
pattern: string
12+
allTestPattern: string
1313
}>,
1414
],
1515
'consistentTestFilename'
@@ -46,25 +46,21 @@ export default createEslintRule<
4646
},
4747
defaultOptions: [
4848
{
49-
pattern: defaultPattern,
50-
allTestPattern: defaultTestsPattern,
49+
pattern: defaultPattern.source,
50+
allTestPattern: defaultTestsPattern.source,
5151
},
5252
],
5353

5454
create: (context, options) => {
5555
const { pattern: patternRaw, allTestPattern: allTestPatternRaw } =
5656
options[0]
5757

58-
const pattern =
59-
typeof patternRaw === 'string' ? new RegExp(patternRaw) : patternRaw!
60-
const testPattern =
61-
typeof allTestPatternRaw === 'string'
62-
? new RegExp(allTestPatternRaw)
63-
: allTestPatternRaw!
58+
const pattern = new RegExp(patternRaw!)
59+
const allTestPattern = new RegExp(allTestPatternRaw!)
6460

6561
const { filename } = context
6662

67-
if (!testPattern.test(filename)) return {}
63+
if (!allTestPattern.test(filename)) return {}
6864

6965
return {
7066
Program: (p) => {
@@ -73,7 +69,7 @@ export default createEslintRule<
7369
node: p,
7470
messageId: 'consistentTestFilename',
7571
data: {
76-
pattern: pattern.source,
72+
pattern: patternRaw,
7773
},
7874
})
7975
}

0 commit comments

Comments
 (0)