@@ -68,6 +68,14 @@ export function getRuleFixturesRoot(ruleName: string): string {
68
68
return path . resolve ( FIXTURES_ROOT , `./rules/${ ruleName } ` ) ;
69
69
}
70
70
71
+ function fileNameSuffix ( fileName : string ) : string {
72
+ return fileName . match ( / \. s v e l t e \. (?: j | t ) s $ / u) ? fileName . slice ( fileName . length - 10 ) : path . extname ( fileName ) ;
73
+ }
74
+
75
+ function isSvelteFile ( fileName ) : boolean {
76
+ return fileName . match ( / \. s v e l t e (?: \. (?: j | t ) s ) ? $ / u) ;
77
+ }
78
+
71
79
/**
72
80
* Load test cases
73
81
*/
@@ -118,11 +126,11 @@ export function loadTestCases(
118
126
. filter ( filter )
119
127
. map ( ( inputFile ) => {
120
128
const config = getConfig ( ruleName , inputFile ) ;
121
- const errorFile = inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'errors.yaml' ) ;
122
- const outputExt = path . extname ( inputFile ) ;
129
+ const errorFile = inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'errors.yaml' ) ;
130
+ const outputSuffix = fileNameSuffix ( inputFile ) ;
123
131
const outputFile = inputFile . replace (
124
- / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u,
125
- `output.${ outputExt . slice ( 1 ) } `
132
+ / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u,
133
+ `output.${ outputSuffix . slice ( 1 ) } `
126
134
) ;
127
135
128
136
if ( ! fs . existsSync ( errorFile ) ) {
@@ -193,7 +201,8 @@ function* itrListupInput(rootDir: string): IterableIterator<string> {
193
201
continue ;
194
202
}
195
203
const abs = path . join ( rootDir , filename ) ;
196
- const baseFileName = path . basename ( filename , path . extname ( filename ) ) ;
204
+ const baseName = path . basename ( filename ) ;
205
+ const baseFileName = baseName . slice ( 0 , baseName . length - fileNameSuffix ( baseName ) . length ) ;
197
206
if ( baseFileName . endsWith ( 'input' ) || baseFileName . startsWith ( '+' ) ) {
198
207
yield abs ;
199
208
} else if ( fs . statSync ( abs ) . isDirectory ( ) ) {
@@ -217,12 +226,12 @@ function writeFixtures(
217
226
{ force } : { force ?: boolean } = { }
218
227
) {
219
228
const linter = new Linter ( ) ;
220
- const errorFile = inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'errors.yaml' ) ;
229
+ const errorFile = inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'errors.yaml' ) ;
221
230
222
231
const config = getConfig ( ruleName , inputFile ) ;
223
232
224
233
const parser =
225
- path . extname ( inputFile ) === '.svelte'
234
+ isSvelteFile ( inputFile )
226
235
? svelteParser
227
236
: path . extname ( inputFile ) === '.ts'
228
237
? typescriptParser
@@ -298,11 +307,11 @@ function getConfig(ruleName: string, inputFile: string) {
298
307
const code = fs . readFileSync ( inputFile , 'utf8' ) ;
299
308
let config ;
300
309
let configFile = [
301
- inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'config.json' ) ,
310
+ inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'config.json' ) ,
302
311
path . join ( path . dirname ( inputFile ) , '_config.json' ) ,
303
- inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'config.js' ) ,
312
+ inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'config.js' ) ,
304
313
path . join ( path . dirname ( inputFile ) , '_config.js' ) ,
305
- inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'config.cjs' ) ,
314
+ inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'config.cjs' ) ,
306
315
path . join ( path . dirname ( inputFile ) , '_config.cjs' )
307
316
] . find ( ( f ) => fs . existsSync ( f ) ) ;
308
317
if ( configFile ) {
@@ -312,7 +321,7 @@ function getConfig(ruleName: string, inputFile: string) {
312
321
: JSON . parse ( fs . readFileSync ( configFile , 'utf8' ) ) ;
313
322
}
314
323
const parser =
315
- path . extname ( filename ) === '.svelte'
324
+ isSvelteFile ( filename )
316
325
? svelteParser
317
326
: path . extname ( inputFile ) === '.ts'
318
327
? typescriptParser
@@ -350,7 +359,7 @@ function getConfig(ruleName: string, inputFile: string) {
350
359
}
351
360
352
361
function getRequirements ( inputFile : string ) : Record < string , string > {
353
- let requirementsFile : string = inputFile . replace ( / ( i n p u t | \+ .+ ) \. [ a - z ] + $ / u, 'requirements.json' ) ;
362
+ let requirementsFile : string = inputFile . replace ( / ( i n p u t | \+ .+ ) (?: \. [ a - z ] + ) + $ / u, 'requirements.json' ) ;
354
363
if ( ! fs . existsSync ( requirementsFile ) ) {
355
364
requirementsFile = path . join ( path . dirname ( inputFile ) , '_requirements.json' ) ;
356
365
}
0 commit comments