Skip to content

Commit

Permalink
fix: remove hack and add version check for vue-i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jul 8, 2024
1 parent 4515023 commit 22340e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/configs/vue-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import process from 'node:process';
import fs from 'node:fs';
import globals from 'globals';
import { GLOB_JSON, GLOB_JSON5, GLOB_TS, GLOB_VUE, GLOB_YAML } from '../globs';
import { ensurePackages, interopDefault } from '../utils';
Expand All @@ -15,6 +14,7 @@ export async function vueI18n(options: OptionsHasTypeScript & OptionsIsInEditor
localesDirectory = 'locales',
overrides = {},
src = 'src',
version = 9,
} = options;

const fileGlobs = files.map(x => `**/${src}/${x}`);
Expand Down Expand Up @@ -48,21 +48,6 @@ export async function vueI18n(options: OptionsHasTypeScript & OptionsIsInEditor
sourceType: 'module',
};

// needed for @intlify/vue-i18n/no-unused-keys that depends on legacy conf
// https://github.com/intlify/eslint-plugin-vue-i18n/blob/7042275c88eb8a3619a802354eb4f298a6d3e284/lib/utils/collect-keys.ts#L140
// if the plugin adds official support for flat config we can drop this.
const projectDir = path.join(process.cwd(), src, '..');
const legacyConfig = path.join(projectDir, '.eslintrc.json');
if (!fs.existsSync(legacyConfig)) {
fs.writeFileSync(legacyConfig, JSON.stringify({
parser: 'vue-eslint-parser',
parserOptions: {
...parserOptions,
...(options.typescript ? { parser: '@typescript-eslint/parser' } : {}),
},
}, null, 2));
}

return [
{
name: 'rotki/vue-i18n/setup',
Expand Down Expand Up @@ -109,6 +94,12 @@ export async function vueI18n(options: OptionsHasTypeScript & OptionsIsInEditor
},
],

...(version === 8
? {
'@intlify/vue-i18n/no-deprecated-i18n-component': 'off',
}
: {}),

...overrides,

},
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export interface OptionsVueI18n extends OptionsOverrides {
* Patterns that will be ignored by @intlify/vue-i18n/no-unused-keys.
*/
ignores?: string[];
/**
* Vue18n version. Apply different rules set from `@intlify/vue-i18n`.
*
* @default 9
*/
version?: 8 | 9;
}

export interface OptionsOverrides {
Expand Down

0 comments on commit 22340e7

Please sign in to comment.