@@ -16,6 +16,7 @@ import type {
16
16
import { joinPath } from '../utils/key-path'
17
17
import { getCwd } from '../utils/get-cwd'
18
18
import { createRule } from '../utils/rule'
19
+ import { getFilename , getSourceCode } from '../utils/compat'
19
20
const debug = debugBuilder ( 'eslint-plugin-vue-i18n:no-duplicate-keys-in-locale' )
20
21
21
22
interface DictData {
@@ -34,13 +35,14 @@ interface PathStack {
34
35
function getMessageFilepath ( fullPath : string , context : RuleContext ) {
35
36
const cwd = getCwd ( context )
36
37
if ( fullPath . startsWith ( cwd ) ) {
37
- return fullPath . replace ( cwd + '/' , './' )
38
+ return fullPath . replace ( ` ${ cwd } /` , './' )
38
39
}
39
40
return fullPath
40
41
}
41
42
42
43
function create ( context : RuleContext ) : RuleListener {
43
- const filename = context . getFilename ( )
44
+ const filename = getFilename ( context )
45
+ const sourceCode = getSourceCode ( context )
44
46
const options = ( context . options && context . options [ 0 ] ) || { }
45
47
const ignoreI18nBlock = Boolean ( options . ignoreI18nBlock )
46
48
@@ -129,7 +131,7 @@ function create(context: RuleContext): RuleListener {
129
131
}
130
132
if ( typeof value . value !== 'object' ) {
131
133
reportFiles . push (
132
- '"' + getMessageFilepath ( value . source . fullpath , context ) + '"'
134
+ `" ${ getMessageFilepath ( value . source . fullpath , context ) } "`
133
135
)
134
136
} else {
135
137
nextOtherDictionaries . push ( {
@@ -145,7 +147,7 @@ function create(context: RuleContext): RuleListener {
145
147
message : `duplicate key '${ keyPathStr } ' in '${ pathStack . locale } '. ${
146
148
reportFiles . length === 0
147
149
? last
148
- : reportFiles . join ( ', ' ) + ' , and ' + last
150
+ : ` ${ reportFiles . join ( ', ' ) } , and ${ last } `
149
151
} has the same key`,
150
152
loc : reportNode . loc
151
153
} )
@@ -316,7 +318,7 @@ function create(context: RuleContext): RuleListener {
316
318
lm => lm !== targetLocaleMessage
317
319
)
318
320
return createVisitorForJson (
319
- ctx . getSourceCode ( ) ,
321
+ getSourceCode ( ctx ) ,
320
322
targetLocaleMessage ,
321
323
otherLocaleMessages
322
324
)
@@ -335,31 +337,33 @@ function create(context: RuleContext): RuleListener {
335
337
lm => lm !== targetLocaleMessage
336
338
)
337
339
return createVisitorForYaml (
338
- ctx . getSourceCode ( ) ,
340
+ getSourceCode ( ctx ) ,
339
341
targetLocaleMessage ,
340
342
otherLocaleMessages
341
343
)
342
344
}
343
345
)
344
- } else if ( context . parserServices . isJSON || context . parserServices . isYAML ) {
346
+ } else if (
347
+ sourceCode . parserServices . isJSON ||
348
+ sourceCode . parserServices . isYAML
349
+ ) {
345
350
const localeMessages = getLocaleMessages ( context )
346
351
const targetLocaleMessage = localeMessages . findExistLocaleMessage ( filename )
347
352
if ( ! targetLocaleMessage ) {
348
353
debug ( `ignore ${ filename } in no-duplicate-keys-in-locale` )
349
354
return { }
350
355
}
351
356
352
- const sourceCode = context . getSourceCode ( )
353
357
const otherLocaleMessages : LocaleMessage [ ] =
354
358
localeMessages . localeMessages . filter ( lm => lm !== targetLocaleMessage )
355
359
356
- if ( context . parserServices . isJSON ) {
360
+ if ( sourceCode . parserServices . isJSON ) {
357
361
return createVisitorForJson (
358
362
sourceCode ,
359
363
targetLocaleMessage ,
360
364
otherLocaleMessages
361
365
)
362
- } else if ( context . parserServices . isYAML ) {
366
+ } else if ( sourceCode . parserServices . isYAML ) {
363
367
return createVisitorForYaml (
364
368
sourceCode ,
365
369
targetLocaleMessage ,
0 commit comments