Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/rules/consistent-test-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
export default createEslintRule<
[
Partial<{
pattern: RegExp | string
allTestPattern: RegExp | string
pattern: string
allTestPattern: string
}>,
],
'consistentTestFilename'
>({
name: RULE_NAME,
meta: {

Check warning on line 18 in src/rules/consistent-test-filename.ts

View workflow job for this annotation

GitHub Actions / Lint

Rule with non-empty schema is missing a `meta.defaultOptions` property
type: 'problem',
docs: {
recommended: false,
Expand All @@ -30,15 +30,15 @@
type: 'object',
additionalProperties: false,
properties: {
pattern: {

Check warning on line 33 in src/rules/consistent-test-filename.ts

View workflow job for this annotation

GitHub Actions / Lint

Schema option is missing an ajv description
type: 'string',
format: 'regex',
default: defaultPattern.source,

Check warning on line 36 in src/rules/consistent-test-filename.ts

View workflow job for this annotation

GitHub Actions / Lint

Disallowed default value in schema
},
allTestPattern: {

Check warning on line 38 in src/rules/consistent-test-filename.ts

View workflow job for this annotation

GitHub Actions / Lint

Schema option is missing an ajv description
type: 'string',
format: 'regex',
default: defaultTestsPattern.source,

Check warning on line 41 in src/rules/consistent-test-filename.ts

View workflow job for this annotation

GitHub Actions / Lint

Disallowed default value in schema
},
},
},
Expand All @@ -46,25 +46,21 @@
},
defaultOptions: [
{
pattern: defaultPattern,
allTestPattern: defaultTestsPattern,
pattern: defaultPattern.source,
allTestPattern: defaultTestsPattern.source,
},
],

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

const pattern =
typeof patternRaw === 'string' ? new RegExp(patternRaw) : patternRaw!
const testPattern =
typeof allTestPatternRaw === 'string'
? new RegExp(allTestPatternRaw)
: allTestPatternRaw!
const pattern = new RegExp(patternRaw!)
const allTestPattern = new RegExp(allTestPatternRaw!)

const { filename } = context

if (!testPattern.test(filename)) return {}
if (!allTestPattern.test(filename)) return {}

return {
Program: (p) => {
Expand All @@ -73,7 +69,7 @@
node: p,
messageId: 'consistentTestFilename',
data: {
pattern: pattern.source,
pattern: patternRaw,
},
})
}
Expand Down
Loading