@@ -11,9 +11,10 @@ import { ResourceLoader } from './resource-loader'
1111import { CacheLoader } from './cache-loader'
1212import { defineCacheFunction } from './cache-function'
1313import debugBuilder from 'debug'
14- import type { VisitorKeys } from '../types'
14+ import type { RuleContext , VisitorKeys } from '../types'
1515// @ts -expect-error -- ignore
1616import { Legacy } from '@eslint/eslintrc'
17+ import { getCwd } from './get-cwd'
1718const debug = debugBuilder ( 'eslint-plugin-vue-i18n:collect-keys' )
1819const { CascadingConfigArrayFactory } = Legacy
1920
@@ -246,16 +247,16 @@ export function collectKeysFromAST(
246247
247248class UsedKeysCache {
248249 private _targetFilesLoader : CacheLoader <
249- [ string [ ] , string [ ] , string ] ,
250+ [ string , string [ ] , string [ ] , string ] ,
250251 string [ ]
251252 >
252253 private _collectKeyResourcesFromFiles : (
253254 fileNames : string [ ] ,
254255 cwd : string
255256 ) => ResourceLoader < string [ ] > [ ]
256257 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 } )
259260 . filter ( f => ! f . ignored && extensions . includes ( extname ( f . filename ) ) )
260261 . map ( f => f . filename )
261262 } )
@@ -271,9 +272,13 @@ class UsedKeysCache {
271272 * @param {string[] } extensions
272273 * @returns {string[] }
273274 */
274- collectKeysFromFiles ( files : string [ ] , extensions : string [ ] ) {
275+ collectKeysFromFiles (
276+ files : string [ ] ,
277+ extensions : string [ ] ,
278+ context : RuleContext
279+ ) {
275280 const result = new Set < string > ( )
276- for ( const resource of this . _getKeyResources ( files , extensions ) ) {
281+ for ( const resource of this . _getKeyResources ( context , files , extensions ) ) {
277282 for ( const key of resource . getResource ( ) ) {
278283 result . add ( key )
279284 }
@@ -284,9 +289,13 @@ class UsedKeysCache {
284289 /**
285290 * @returns {ResourceLoader[] }
286291 */
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 )
290299 return this . _collectKeyResourcesFromFiles ( fileNames , cwd )
291300 }
292301}
0 commit comments