@@ -68,6 +68,14 @@ export function getRuleFixturesRoot(ruleName: string): string {
6868 return path . resolve ( FIXTURES_ROOT , `./rules/${ ruleName } ` ) ;
6969}
7070
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+
7179/**
7280 * Load test cases
7381 */
@@ -118,11 +126,11 @@ export function loadTestCases(
118126 . filter ( filter )
119127 . map ( ( inputFile ) => {
120128 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 ) ;
123131 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 ) } `
126134 ) ;
127135
128136 if ( ! fs . existsSync ( errorFile ) ) {
@@ -193,7 +201,8 @@ function* itrListupInput(rootDir: string): IterableIterator<string> {
193201 continue ;
194202 }
195203 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 ) ;
197206 if ( baseFileName . endsWith ( 'input' ) || baseFileName . startsWith ( '+' ) ) {
198207 yield abs ;
199208 } else if ( fs . statSync ( abs ) . isDirectory ( ) ) {
@@ -217,12 +226,12 @@ function writeFixtures(
217226 { force } : { force ?: boolean } = { }
218227) {
219228 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' ) ;
221230
222231 const config = getConfig ( ruleName , inputFile ) ;
223232
224233 const parser =
225- path . extname ( inputFile ) === '.svelte'
234+ isSvelteFile ( inputFile )
226235 ? svelteParser
227236 : path . extname ( inputFile ) === '.ts'
228237 ? typescriptParser
@@ -298,11 +307,11 @@ function getConfig(ruleName: string, inputFile: string) {
298307 const code = fs . readFileSync ( inputFile , 'utf8' ) ;
299308 let config ;
300309 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' ) ,
302311 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' ) ,
304313 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' ) ,
306315 path . join ( path . dirname ( inputFile ) , '_config.cjs' )
307316 ] . find ( ( f ) => fs . existsSync ( f ) ) ;
308317 if ( configFile ) {
@@ -312,7 +321,7 @@ function getConfig(ruleName: string, inputFile: string) {
312321 : JSON . parse ( fs . readFileSync ( configFile , 'utf8' ) ) ;
313322 }
314323 const parser =
315- path . extname ( filename ) === '.svelte'
324+ isSvelteFile ( filename )
316325 ? svelteParser
317326 : path . extname ( inputFile ) === '.ts'
318327 ? typescriptParser
@@ -350,7 +359,7 @@ function getConfig(ruleName: string, inputFile: string) {
350359}
351360
352361function 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' ) ;
354363 if ( ! fs . existsSync ( requirementsFile ) ) {
355364 requirementsFile = path . join ( path . dirname ( inputFile ) , '_requirements.json' ) ;
356365 }
0 commit comments