@@ -16,6 +16,7 @@ import type {
1616import { joinPath } from '../utils/key-path'
1717import { getCwd } from '../utils/get-cwd'
1818import { createRule } from '../utils/rule'
19+ import { getFilename , getSourceCode } from '../utils/compat'
1920const debug = debugBuilder ( 'eslint-plugin-vue-i18n:no-duplicate-keys-in-locale' )
2021
2122interface DictData {
@@ -34,13 +35,14 @@ interface PathStack {
3435function getMessageFilepath ( fullPath : string , context : RuleContext ) {
3536 const cwd = getCwd ( context )
3637 if ( fullPath . startsWith ( cwd ) ) {
37- return fullPath . replace ( cwd + '/' , './' )
38+ return fullPath . replace ( ` ${ cwd } /` , './' )
3839 }
3940 return fullPath
4041}
4142
4243function create ( context : RuleContext ) : RuleListener {
43- const filename = context . getFilename ( )
44+ const filename = getFilename ( context )
45+ const sourceCode = getSourceCode ( context )
4446 const options = ( context . options && context . options [ 0 ] ) || { }
4547 const ignoreI18nBlock = Boolean ( options . ignoreI18nBlock )
4648
@@ -129,7 +131,7 @@ function create(context: RuleContext): RuleListener {
129131 }
130132 if ( typeof value . value !== 'object' ) {
131133 reportFiles . push (
132- '"' + getMessageFilepath ( value . source . fullpath , context ) + '"'
134+ `" ${ getMessageFilepath ( value . source . fullpath , context ) } "`
133135 )
134136 } else {
135137 nextOtherDictionaries . push ( {
@@ -145,7 +147,7 @@ function create(context: RuleContext): RuleListener {
145147 message : `duplicate key '${ keyPathStr } ' in '${ pathStack . locale } '. ${
146148 reportFiles . length === 0
147149 ? last
148- : reportFiles . join ( ', ' ) + ' , and ' + last
150+ : ` ${ reportFiles . join ( ', ' ) } , and ${ last } `
149151 } has the same key`,
150152 loc : reportNode . loc
151153 } )
@@ -316,7 +318,7 @@ function create(context: RuleContext): RuleListener {
316318 lm => lm !== targetLocaleMessage
317319 )
318320 return createVisitorForJson (
319- ctx . getSourceCode ( ) ,
321+ getSourceCode ( ctx ) ,
320322 targetLocaleMessage ,
321323 otherLocaleMessages
322324 )
@@ -335,31 +337,33 @@ function create(context: RuleContext): RuleListener {
335337 lm => lm !== targetLocaleMessage
336338 )
337339 return createVisitorForYaml (
338- ctx . getSourceCode ( ) ,
340+ getSourceCode ( ctx ) ,
339341 targetLocaleMessage ,
340342 otherLocaleMessages
341343 )
342344 }
343345 )
344- } else if ( context . parserServices . isJSON || context . parserServices . isYAML ) {
346+ } else if (
347+ sourceCode . parserServices . isJSON ||
348+ sourceCode . parserServices . isYAML
349+ ) {
345350 const localeMessages = getLocaleMessages ( context )
346351 const targetLocaleMessage = localeMessages . findExistLocaleMessage ( filename )
347352 if ( ! targetLocaleMessage ) {
348353 debug ( `ignore ${ filename } in no-duplicate-keys-in-locale` )
349354 return { }
350355 }
351356
352- const sourceCode = context . getSourceCode ( )
353357 const otherLocaleMessages : LocaleMessage [ ] =
354358 localeMessages . localeMessages . filter ( lm => lm !== targetLocaleMessage )
355359
356- if ( context . parserServices . isJSON ) {
360+ if ( sourceCode . parserServices . isJSON ) {
357361 return createVisitorForJson (
358362 sourceCode ,
359363 targetLocaleMessage ,
360364 otherLocaleMessages
361365 )
362- } else if ( context . parserServices . isYAML ) {
366+ } else if ( sourceCode . parserServices . isYAML ) {
363367 return createVisitorForYaml (
364368 sourceCode ,
365369 targetLocaleMessage ,
0 commit comments