@@ -11,9 +11,10 @@ import { ResourceLoader } from './resource-loader'
11
11
import { CacheLoader } from './cache-loader'
12
12
import { defineCacheFunction } from './cache-function'
13
13
import debugBuilder from 'debug'
14
- import type { VisitorKeys } from '../types'
14
+ import type { RuleContext , VisitorKeys } from '../types'
15
15
// @ts -expect-error -- ignore
16
16
import { Legacy } from '@eslint/eslintrc'
17
+ import { getCwd } from './get-cwd'
17
18
const debug = debugBuilder ( 'eslint-plugin-vue-i18n:collect-keys' )
18
19
const { CascadingConfigArrayFactory } = Legacy
19
20
@@ -246,16 +247,16 @@ export function collectKeysFromAST(
246
247
247
248
class UsedKeysCache {
248
249
private _targetFilesLoader : CacheLoader <
249
- [ string [ ] , string [ ] , string ] ,
250
+ [ string , string [ ] , string [ ] , string ] ,
250
251
string [ ]
251
252
>
252
253
private _collectKeyResourcesFromFiles : (
253
254
fileNames : string [ ] ,
254
255
cwd : string
255
256
) => ResourceLoader < string [ ] > [ ]
256
257
constructor ( ) {
257
- this . _targetFilesLoader = new CacheLoader ( ( files , extensions ) => {
258
- return listFilesToProcess ( files , { extensions } )
258
+ this . _targetFilesLoader = new CacheLoader ( ( cwd , files , extensions ) => {
259
+ return listFilesToProcess ( files , { cwd , extensions } )
259
260
. filter ( f => ! f . ignored && extensions . includes ( extname ( f . filename ) ) )
260
261
. map ( f => f . filename )
261
262
} )
@@ -271,9 +272,13 @@ class UsedKeysCache {
271
272
* @param {string[] } extensions
272
273
* @returns {string[] }
273
274
*/
274
- collectKeysFromFiles ( files : string [ ] , extensions : string [ ] ) {
275
+ collectKeysFromFiles (
276
+ files : string [ ] ,
277
+ extensions : string [ ] ,
278
+ context : RuleContext
279
+ ) {
275
280
const result = new Set < string > ( )
276
- for ( const resource of this . _getKeyResources ( files , extensions ) ) {
281
+ for ( const resource of this . _getKeyResources ( context , files , extensions ) ) {
277
282
for ( const key of resource . getResource ( ) ) {
278
283
result . add ( key )
279
284
}
@@ -284,9 +289,13 @@ class UsedKeysCache {
284
289
/**
285
290
* @returns {ResourceLoader[] }
286
291
*/
287
- _getKeyResources ( files : string [ ] , extensions : string [ ] ) {
288
- const cwd = process . cwd ( )
289
- const fileNames = this . _targetFilesLoader . get ( files , extensions , cwd )
292
+ _getKeyResources (
293
+ context : RuleContext ,
294
+ files : string [ ] ,
295
+ extensions : string [ ]
296
+ ) {
297
+ const cwd = getCwd ( context )
298
+ const fileNames = this . _targetFilesLoader . get ( cwd , files , extensions , cwd )
290
299
return this . _collectKeyResourcesFromFiles ( fileNames , cwd )
291
300
}
292
301
}
0 commit comments