From 3ed69721677c9cc1261690fa8d3756ba95b83a56 Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Mon, 22 May 2023 01:54:49 +0200 Subject: [PATCH 1/3] refactor: fix eslint errors --- .../.vuepress/components/eslint-code-block.vue | 18 +++++++++++------- docs/.vuepress/config.js | 6 ++++-- lib/rules/key-format-style.ts | 3 ++- lib/rules/no-deprecated-i18n-component.ts | 3 ++- lib/rules/no-deprecated-i18n-place-attr.ts | 3 ++- lib/rules/no-deprecated-i18n-places-prop.ts | 3 ++- lib/rules/no-duplicate-keys-in-locale.ts | 8 +++++--- lib/rules/no-dynamic-keys.ts | 3 ++- lib/rules/no-html-messages.ts | 3 ++- lib/rules/no-i18n-t-path-prop.ts | 3 ++- lib/rules/no-missing-keys-in-other-locales.ts | 3 ++- lib/rules/no-missing-keys.ts | 5 +++-- lib/rules/no-unknown-locale.ts | 3 ++- lib/rules/no-unused-keys.ts | 3 ++- lib/rules/prefer-linked-key-with-paren.ts | 3 ++- lib/rules/prefer-sfc-lang-attr.ts | 6 +++--- lib/rules/sfc-locale-attr.ts | 3 ++- lib/rules/valid-message-syntax.ts | 13 ++++++++----- lib/types/eslint.ts | 4 +++- lib/utils/collect-keys.ts | 4 +++- lib/utils/glob-sync.ts | 2 +- lib/utils/glob-utils.ts | 6 +++--- lib/utils/ignored-paths.ts | 4 ++-- lib/utils/index.ts | 4 +++- lib/utils/message-compiler/parser-v8.ts | 4 +++- lib/utils/message-compiler/parser.ts | 4 +++- tests/lib/rules/no-unused-keys.ts | 3 +-- tests/lib/test-utils.ts | 4 +++- 28 files changed, 83 insertions(+), 48 deletions(-) diff --git a/docs/.vuepress/components/eslint-code-block.vue b/docs/.vuepress/components/eslint-code-block.vue index 11f057c9..f11810f5 100644 --- a/docs/.vuepress/components/eslint-code-block.vue +++ b/docs/.vuepress/components/eslint-code-block.vue @@ -192,13 +192,17 @@ export default { ) }) // Load linter. - const [{ Linter }, vueESLintParser, jsoncESLintParser, yamlESLintParser] = - await Promise.all([ - import('eslint'), - import('espree').then(() => import('vue-eslint-parser')), - import('espree').then(() => import('jsonc-eslint-parser')), - import('yaml-eslint-parser') - ]) + const [ + { Linter }, + vueESLintParser, + jsoncESLintParser, + yamlESLintParser + ] = await Promise.all([ + import('eslint'), + import('espree').then(() => import('vue-eslint-parser')), + import('espree').then(() => import('jsonc-eslint-parser')), + import('yaml-eslint-parser') + ]) const linter = (this.linter = new Linter({ cwd: '/path' })) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 3976a927..49484734 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -33,8 +33,10 @@ module.exports = { esquery$: require.resolve('esquery/dist/esquery'), parse5$: require.resolve('parse5'), fs: require.resolve('./shim/fs'), - [path.resolve(__dirname, '../../dist/utils/glob-utils')]: - require.resolve('./shim/eslint-plugin-vue-i18n/utils/glob-utils') + [path.resolve( + __dirname, + '../../dist/utils/glob-utils' + )]: require.resolve('./shim/eslint-plugin-vue-i18n/utils/glob-utils') } } } diff --git a/lib/rules/key-format-style.ts b/lib/rules/key-format-style.ts index 62c19d69..88abdc35 100644 --- a/lib/rules/key-format-style.ts +++ b/lib/rules/key-format-style.ts @@ -290,7 +290,8 @@ export = createRule({ docs: { description: 'enforce specific casing for localization keys', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/key-format-style.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/key-format-style.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-deprecated-i18n-component.ts b/lib/rules/no-deprecated-i18n-component.ts index 6d3676e1..d87be04a 100644 --- a/lib/rules/no-deprecated-i18n-component.ts +++ b/lib/rules/no-deprecated-i18n-component.ts @@ -89,7 +89,8 @@ export = createRule({ description: 'disallow using deprecated `` components (in Vue I18n 9.0.0+)', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-component.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-component.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/no-deprecated-i18n-place-attr.ts b/lib/rules/no-deprecated-i18n-place-attr.ts index 78c111f0..eeba7946 100644 --- a/lib/rules/no-deprecated-i18n-place-attr.ts +++ b/lib/rules/no-deprecated-i18n-place-attr.ts @@ -40,7 +40,8 @@ export = createRule({ description: 'disallow using deprecated `place` attribute (Removed in Vue I18n 9.0.0+)', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-place-attr.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-place-attr.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-deprecated-i18n-places-prop.ts b/lib/rules/no-deprecated-i18n-places-prop.ts index 795161b3..bc7a1ac9 100644 --- a/lib/rules/no-deprecated-i18n-places-prop.ts +++ b/lib/rules/no-deprecated-i18n-places-prop.ts @@ -35,7 +35,8 @@ export = createRule({ description: 'disallow using deprecated `places` prop (Removed in Vue I18n 9.0.0+)', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-places-prop.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-places-prop.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-duplicate-keys-in-locale.ts b/lib/rules/no-duplicate-keys-in-locale.ts index e2d5831d..c8965517 100644 --- a/lib/rules/no-duplicate-keys-in-locale.ts +++ b/lib/rules/no-duplicate-keys-in-locale.ts @@ -350,8 +350,9 @@ function create(context: RuleContext): RuleListener { } const sourceCode = context.getSourceCode() - const otherLocaleMessages: LocaleMessage[] = - localeMessages.localeMessages.filter(lm => lm !== targetLocaleMessage) + const otherLocaleMessages: LocaleMessage[] = localeMessages.localeMessages.filter( + lm => lm !== targetLocaleMessage + ) if (context.parserServices.isJSON) { return createVisitorForJson( @@ -380,7 +381,8 @@ export = createRule({ description: 'disallow duplicate localization keys within the same locale', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-duplicate-keys-in-locale.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-duplicate-keys-in-locale.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-dynamic-keys.ts b/lib/rules/no-dynamic-keys.ts index 7639adb4..1a1d5992 100644 --- a/lib/rules/no-dynamic-keys.ts +++ b/lib/rules/no-dynamic-keys.ts @@ -127,7 +127,8 @@ export = createRule({ docs: { description: 'disallow localization dynamic keys at localization methods', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-dynamic-keys.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-dynamic-keys.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-html-messages.ts b/lib/rules/no-html-messages.ts index 2cecb9e2..42a8ff22 100644 --- a/lib/rules/no-html-messages.ts +++ b/lib/rules/no-html-messages.ts @@ -123,7 +123,8 @@ export = createRule({ docs: { description: 'disallow use HTML localization messages', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-html-messages.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-html-messages.html', recommended: true }, fixable: null, diff --git a/lib/rules/no-i18n-t-path-prop.ts b/lib/rules/no-i18n-t-path-prop.ts index 0d4cbd49..21a508f6 100644 --- a/lib/rules/no-i18n-t-path-prop.ts +++ b/lib/rules/no-i18n-t-path-prop.ts @@ -41,7 +41,8 @@ export = createRule({ docs: { description: 'disallow using `path` prop with ``', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-i18n-t-path-prop.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-i18n-t-path-prop.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/no-missing-keys-in-other-locales.ts b/lib/rules/no-missing-keys-in-other-locales.ts index b876421d..aa4ec78e 100644 --- a/lib/rules/no-missing-keys-in-other-locales.ts +++ b/lib/rules/no-missing-keys-in-other-locales.ts @@ -333,7 +333,8 @@ export = createRule({ docs: { description: 'disallow missing locale message keys in other locales', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys-in-other-locales.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys-in-other-locales.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-missing-keys.ts b/lib/rules/no-missing-keys.ts index 0b98a68a..0bb9d022 100644 --- a/lib/rules/no-missing-keys.ts +++ b/lib/rules/no-missing-keys.ts @@ -24,7 +24,7 @@ function create(context: RuleContext): RuleListener { }, ["VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name='path']," + - "VElement[name=i18n-t] > VStartTag > VAttribute[key.name='keypath']"]( + "VElement[name=i18n-t] > VStartTag > VAttribute[key.name='keypath']"]( node: VAST.VAttribute ) { checkComponent(context, node) @@ -138,7 +138,8 @@ export = createRule({ description: 'disallow missing locale message key at localization methods', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys.html', recommended: true }, fixable: null, diff --git a/lib/rules/no-unknown-locale.ts b/lib/rules/no-unknown-locale.ts index 51169456..ccfadcef 100644 --- a/lib/rules/no-unknown-locale.ts +++ b/lib/rules/no-unknown-locale.ts @@ -244,7 +244,8 @@ export = createRule({ docs: { description: 'disallow unknown locale name', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unknown-locale.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unknown-locale.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-unused-keys.ts b/lib/rules/no-unused-keys.ts index da519d5a..7e02be67 100644 --- a/lib/rules/no-unused-keys.ts +++ b/lib/rules/no-unused-keys.ts @@ -566,7 +566,8 @@ export = createRule({ docs: { description: 'disallow unused localization keys', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unused-keys.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unused-keys.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/prefer-linked-key-with-paren.ts b/lib/rules/prefer-linked-key-with-paren.ts index ac550b23..aa16430c 100644 --- a/lib/rules/prefer-linked-key-with-paren.ts +++ b/lib/rules/prefer-linked-key-with-paren.ts @@ -247,7 +247,8 @@ export = createRule({ docs: { description: 'enforce linked key to be enclosed in parentheses', category: 'Stylistic Issues', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-linked-key-with-paren.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-linked-key-with-paren.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/prefer-sfc-lang-attr.ts b/lib/rules/prefer-sfc-lang-attr.ts index f9d80354..0f9b4aad 100644 --- a/lib/rules/prefer-sfc-lang-attr.ts +++ b/lib/rules/prefer-sfc-lang-attr.ts @@ -28,8 +28,7 @@ function create(context: RuleContext): RuleListener { if (langAttrs) { return fixer.replaceTextRange(langAttrs.range, 'lang="json"') } - const tokenStore = - context.parserServices.getTemplateBodyTokenStore() + const tokenStore = context.parserServices.getTemplateBodyTokenStore() const closeToken = tokenStore.getLastToken(i18n.startTag) const beforeToken = tokenStore.getTokenBefore(closeToken) return fixer.insertTextBeforeRange( @@ -51,7 +50,8 @@ export = createRule({ docs: { description: 'require lang attribute on `` block', category: 'Best Practices', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-sfc-lang-attr.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-sfc-lang-attr.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/sfc-locale-attr.ts b/lib/rules/sfc-locale-attr.ts index 7e796a0a..676e7e6a 100644 --- a/lib/rules/sfc-locale-attr.ts +++ b/lib/rules/sfc-locale-attr.ts @@ -8,7 +8,8 @@ export = createRule({ docs: { description: 'require or disallow the locale attribute on `` block', category: 'Stylistic Issues', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/sfc-locale-attr.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/sfc-locale-attr.html', recommended: false }, fixable: null, diff --git a/lib/rules/valid-message-syntax.ts b/lib/rules/valid-message-syntax.ts index fc8b043a..92ea2b21 100644 --- a/lib/rules/valid-message-syntax.ts +++ b/lib/rules/valid-message-syntax.ts @@ -75,8 +75,9 @@ function create(context: RuleContext): RuleListener { parent: JSONAST.JSONNode ) { let message - let getReportOffset: ((error: CompileError) => number | null) | null = - null + let getReportOffset: + | ((error: CompileError) => number | null) + | null = null if (node) { if ( node.type === 'JSONArrayExpression' || @@ -126,8 +127,9 @@ function create(context: RuleContext): RuleListener { parent: YAMLAST.YAMLNode ) { let message - let getReportOffset: ((error: CompileError) => number | null) | null = - null + let getReportOffset: + | ((error: CompileError) => number | null) + | null = null if (node) { const valueNode = node.type === 'YAMLWithMeta' ? node.value : node if ( @@ -203,7 +205,8 @@ export = createRule({ docs: { description: 'disallow invalid message syntax', category: 'Recommended', - url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/valid-message-syntax.html', + url: + 'https://eslint-plugin-vue-i18n.intlify.dev/rules/valid-message-syntax.html', // TODO To avoid breaking changes, include it in the configuration at the time of version upgrade. recommended: false }, diff --git a/lib/types/eslint.ts b/lib/types/eslint.ts index ca5256b6..5598ce2b 100644 --- a/lib/types/eslint.ts +++ b/lib/types/eslint.ts @@ -128,7 +128,9 @@ export interface SourceCode extends TokenStore { getText(node?: MaybeNode, beforeCount?: number, afterCount?: number): string getLines(): string[] getAllComments(): MaybeToken[] - getComments(node: MaybeNode): { + getComments( + node: MaybeNode + ): { leading: MaybeToken[] trailing: MaybeToken[] } diff --git a/lib/utils/collect-keys.ts b/lib/utils/collect-keys.ts index 1c5eb220..c858d9e1 100644 --- a/lib/utils/collect-keys.ts +++ b/lib/utils/collect-keys.ts @@ -73,7 +73,9 @@ function getKeyFromI18nComponent(node: VAST.VAttribute) { } } -function getParser(parser: string | undefined): { +function getParser( + parser: string | undefined +): { parseForESLint?: typeof parseForESLint parse: (code: string, options: unknown) => VAST.ESLintProgram } { diff --git a/lib/utils/glob-sync.ts b/lib/utils/glob-sync.ts index af513e76..1a0f1a4d 100644 --- a/lib/utils/glob-sync.ts +++ b/lib/utils/glob-sync.ts @@ -35,7 +35,7 @@ GlobSync.prototype._readdir = function (abs, inGlobStar) { return Sync.prototype._readdir.call(this, abs, inGlobStar) } -export default GlobSync as never as new ( +export default (GlobSync as never) as new ( pattern: string, options: IOptions, shouldIgnore: (absolutePath: string) => boolean diff --git a/lib/utils/glob-utils.ts b/lib/utils/glob-utils.ts index c97ac97d..99aa76e8 100644 --- a/lib/utils/glob-utils.ts +++ b/lib/utils/glob-utils.ts @@ -228,9 +228,9 @@ export function listFilesToProcess( pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE ) ) { - throw new ( - pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError - )(globPatterns[index]) + throw new (pathsForCurrentGlob.length + ? AllFilesIgnoredError + : NoFilesFoundError)(globPatterns[index]) } pathsForCurrentGlob.forEach(pathDescriptor => { diff --git a/lib/utils/ignored-paths.ts b/lib/utils/ignored-paths.ts index 71f9a894..628525f1 100644 --- a/lib/utils/ignored-paths.ts +++ b/lib/utils/ignored-paths.ts @@ -179,7 +179,7 @@ export class IgnoredPaths { ignorePath = options.ignorePath } catch ( // eslint-disable-next-line @typescript-eslint/no-explicit-any - e: any + e ) { e.message = `Cannot read ignore file: ${options.ignorePath}\nError: ${e.message}` throw e @@ -214,7 +214,7 @@ export class IgnoredPaths { ) } catch ( // eslint-disable-next-line @typescript-eslint/no-explicit-any - e: any + e ) { debug( 'Could not read package.json file to check eslintIgnore property' diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 71e32ec3..f106e11f 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -505,7 +505,9 @@ export function isI18nBlock( * Get the static attribute values from a given element. * @param element The element to get. */ -export function getStaticAttributes(element: VAST.VElement): { +export function getStaticAttributes( + element: VAST.VElement +): { [name: string]: string | undefined } { const attrs: { [name: string]: string | undefined } = {} diff --git a/lib/utils/message-compiler/parser-v8.ts b/lib/utils/message-compiler/parser-v8.ts index 30053ee0..38ab565e 100644 --- a/lib/utils/message-compiler/parser-v8.ts +++ b/lib/utils/message-compiler/parser-v8.ts @@ -18,7 +18,9 @@ import type { import lodash from 'lodash' import { NodeTypes } from './utils' -export function parse(code: string): { +export function parse( + code: string +): { ast: ResourceNode errors: CompileError[] } { diff --git a/lib/utils/message-compiler/parser.ts b/lib/utils/message-compiler/parser.ts index 4abc6f79..dbaf877f 100644 --- a/lib/utils/message-compiler/parser.ts +++ b/lib/utils/message-compiler/parser.ts @@ -1,7 +1,9 @@ import type { CompileError, ResourceNode } from '@intlify/message-compiler' import { createParser } from '@intlify/message-compiler' -export function parse(code: string): { +export function parse( + code: string +): { ast: ResourceNode errors: CompileError[] } { diff --git a/tests/lib/rules/no-unused-keys.ts b/tests/lib/rules/no-unused-keys.ts index b692d48b..07f35b4b 100644 --- a/tests/lib/rules/no-unused-keys.ts +++ b/tests/lib/rules/no-unused-keys.ts @@ -152,8 +152,7 @@ new RuleTester({ localeDir: { pattern: `./locales/**/*.{json,yaml,yml}`, localeKey: 'path', - localePattern: - /^.*\/(?[A-Za-z0-9-_]+)\/.*\.(json5?|ya?ml)$/ + localePattern: /^.*\/(?[A-Za-z0-9-_]+)\/.*\.(json5?|ya?ml)$/ }, options: [ { diff --git a/tests/lib/test-utils.ts b/tests/lib/test-utils.ts index a2cc0e4c..abc57227 100644 --- a/tests/lib/test-utils.ts +++ b/tests/lib/test-utils.ts @@ -77,7 +77,9 @@ const PARSERS = { '.yaml': require.resolve('yaml-eslint-parser'), '.yml': require.resolve('yaml-eslint-parser') } -function* extractTargetFiles(dir: string): IterableIterator<{ +function* extractTargetFiles( + dir: string +): IterableIterator<{ filename: string relative: string parser: string | undefined From 2ba792acb4295f986ae78e408e2d5923d9803ecc Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Mon, 22 May 2023 02:26:43 +0200 Subject: [PATCH 2/3] fix: format --- docs/rules/key-format-style.md | 2 +- lib/utils/ignored-paths.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/rules/key-format-style.md b/docs/rules/key-format-style.md index 7ba8a272..f038388b 100644 --- a/docs/rules/key-format-style.md +++ b/docs/rules/key-format-style.md @@ -50,7 +50,7 @@ Also, the following localization key definitions are reported as errors, because "camelCase" | "kebab-case" | "snake_case", { "allowArray": false, - "splitByDots": false, + "splitByDots": false } ] } diff --git a/lib/utils/ignored-paths.ts b/lib/utils/ignored-paths.ts index 628525f1..805fd3ac 100644 --- a/lib/utils/ignored-paths.ts +++ b/lib/utils/ignored-paths.ts @@ -178,8 +178,8 @@ export class IgnoredPaths { statSync(options.ignorePath) ignorePath = options.ignorePath } catch ( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - e + // eslint-disable-next-line @typescript-eslint/no-explicit-any, prettier/prettier + e: any ) { e.message = `Cannot read ignore file: ${options.ignorePath}\nError: ${e.message}` throw e @@ -213,8 +213,8 @@ export class IgnoredPaths { readFileSync(packageJSONPath, 'utf8') ) } catch ( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - e + // eslint-disable-next-line @typescript-eslint/no-explicit-any, prettier/prettier + e: any ) { debug( 'Could not read package.json file to check eslintIgnore property' From 0e043b7088a325ab5e27cad1db878eb3a002982b Mon Sep 17 00:00:00 2001 From: Jonas Thelemann Date: Mon, 22 May 2023 02:33:52 +0200 Subject: [PATCH 3/3] chore: lint fix --- .../.vuepress/components/eslint-code-block.vue | 18 +++++++----------- docs/.vuepress/config.js | 6 ++---- lib/rules/key-format-style.ts | 3 +-- lib/rules/no-deprecated-i18n-component.ts | 3 +-- lib/rules/no-deprecated-i18n-place-attr.ts | 3 +-- lib/rules/no-deprecated-i18n-places-prop.ts | 3 +-- lib/rules/no-duplicate-keys-in-locale.ts | 8 +++----- lib/rules/no-dynamic-keys.ts | 3 +-- lib/rules/no-html-messages.ts | 3 +-- lib/rules/no-i18n-t-path-prop.ts | 3 +-- lib/rules/no-missing-keys-in-other-locales.ts | 3 +-- lib/rules/no-missing-keys.ts | 5 ++--- lib/rules/no-unknown-locale.ts | 3 +-- lib/rules/no-unused-keys.ts | 3 +-- lib/rules/prefer-linked-key-with-paren.ts | 3 +-- lib/rules/prefer-sfc-lang-attr.ts | 6 +++--- lib/rules/sfc-locale-attr.ts | 3 +-- lib/rules/valid-message-syntax.ts | 13 +++++-------- lib/types/eslint.ts | 4 +--- lib/utils/collect-keys.ts | 4 +--- lib/utils/glob-sync.ts | 2 +- lib/utils/glob-utils.ts | 6 +++--- lib/utils/index.ts | 4 +--- lib/utils/message-compiler/parser-v8.ts | 4 +--- lib/utils/message-compiler/parser.ts | 4 +--- tests/lib/rules/no-unused-keys.ts | 3 ++- tests/lib/test-utils.ts | 4 +--- 27 files changed, 46 insertions(+), 81 deletions(-) diff --git a/docs/.vuepress/components/eslint-code-block.vue b/docs/.vuepress/components/eslint-code-block.vue index f11810f5..11f057c9 100644 --- a/docs/.vuepress/components/eslint-code-block.vue +++ b/docs/.vuepress/components/eslint-code-block.vue @@ -192,17 +192,13 @@ export default { ) }) // Load linter. - const [ - { Linter }, - vueESLintParser, - jsoncESLintParser, - yamlESLintParser - ] = await Promise.all([ - import('eslint'), - import('espree').then(() => import('vue-eslint-parser')), - import('espree').then(() => import('jsonc-eslint-parser')), - import('yaml-eslint-parser') - ]) + const [{ Linter }, vueESLintParser, jsoncESLintParser, yamlESLintParser] = + await Promise.all([ + import('eslint'), + import('espree').then(() => import('vue-eslint-parser')), + import('espree').then(() => import('jsonc-eslint-parser')), + import('yaml-eslint-parser') + ]) const linter = (this.linter = new Linter({ cwd: '/path' })) diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 49484734..3976a927 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -33,10 +33,8 @@ module.exports = { esquery$: require.resolve('esquery/dist/esquery'), parse5$: require.resolve('parse5'), fs: require.resolve('./shim/fs'), - [path.resolve( - __dirname, - '../../dist/utils/glob-utils' - )]: require.resolve('./shim/eslint-plugin-vue-i18n/utils/glob-utils') + [path.resolve(__dirname, '../../dist/utils/glob-utils')]: + require.resolve('./shim/eslint-plugin-vue-i18n/utils/glob-utils') } } } diff --git a/lib/rules/key-format-style.ts b/lib/rules/key-format-style.ts index 88abdc35..62c19d69 100644 --- a/lib/rules/key-format-style.ts +++ b/lib/rules/key-format-style.ts @@ -290,8 +290,7 @@ export = createRule({ docs: { description: 'enforce specific casing for localization keys', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/key-format-style.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/key-format-style.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-deprecated-i18n-component.ts b/lib/rules/no-deprecated-i18n-component.ts index d87be04a..6d3676e1 100644 --- a/lib/rules/no-deprecated-i18n-component.ts +++ b/lib/rules/no-deprecated-i18n-component.ts @@ -89,8 +89,7 @@ export = createRule({ description: 'disallow using deprecated `` components (in Vue I18n 9.0.0+)', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-component.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-component.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/no-deprecated-i18n-place-attr.ts b/lib/rules/no-deprecated-i18n-place-attr.ts index eeba7946..78c111f0 100644 --- a/lib/rules/no-deprecated-i18n-place-attr.ts +++ b/lib/rules/no-deprecated-i18n-place-attr.ts @@ -40,8 +40,7 @@ export = createRule({ description: 'disallow using deprecated `place` attribute (Removed in Vue I18n 9.0.0+)', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-place-attr.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-place-attr.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-deprecated-i18n-places-prop.ts b/lib/rules/no-deprecated-i18n-places-prop.ts index bc7a1ac9..795161b3 100644 --- a/lib/rules/no-deprecated-i18n-places-prop.ts +++ b/lib/rules/no-deprecated-i18n-places-prop.ts @@ -35,8 +35,7 @@ export = createRule({ description: 'disallow using deprecated `places` prop (Removed in Vue I18n 9.0.0+)', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-places-prop.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-i18n-places-prop.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-duplicate-keys-in-locale.ts b/lib/rules/no-duplicate-keys-in-locale.ts index c8965517..e2d5831d 100644 --- a/lib/rules/no-duplicate-keys-in-locale.ts +++ b/lib/rules/no-duplicate-keys-in-locale.ts @@ -350,9 +350,8 @@ function create(context: RuleContext): RuleListener { } const sourceCode = context.getSourceCode() - const otherLocaleMessages: LocaleMessage[] = localeMessages.localeMessages.filter( - lm => lm !== targetLocaleMessage - ) + const otherLocaleMessages: LocaleMessage[] = + localeMessages.localeMessages.filter(lm => lm !== targetLocaleMessage) if (context.parserServices.isJSON) { return createVisitorForJson( @@ -381,8 +380,7 @@ export = createRule({ description: 'disallow duplicate localization keys within the same locale', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-duplicate-keys-in-locale.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-duplicate-keys-in-locale.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-dynamic-keys.ts b/lib/rules/no-dynamic-keys.ts index 1a1d5992..7639adb4 100644 --- a/lib/rules/no-dynamic-keys.ts +++ b/lib/rules/no-dynamic-keys.ts @@ -127,8 +127,7 @@ export = createRule({ docs: { description: 'disallow localization dynamic keys at localization methods', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-dynamic-keys.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-dynamic-keys.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-html-messages.ts b/lib/rules/no-html-messages.ts index 42a8ff22..2cecb9e2 100644 --- a/lib/rules/no-html-messages.ts +++ b/lib/rules/no-html-messages.ts @@ -123,8 +123,7 @@ export = createRule({ docs: { description: 'disallow use HTML localization messages', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-html-messages.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-html-messages.html', recommended: true }, fixable: null, diff --git a/lib/rules/no-i18n-t-path-prop.ts b/lib/rules/no-i18n-t-path-prop.ts index 21a508f6..0d4cbd49 100644 --- a/lib/rules/no-i18n-t-path-prop.ts +++ b/lib/rules/no-i18n-t-path-prop.ts @@ -41,8 +41,7 @@ export = createRule({ docs: { description: 'disallow using `path` prop with ``', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-i18n-t-path-prop.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-i18n-t-path-prop.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/no-missing-keys-in-other-locales.ts b/lib/rules/no-missing-keys-in-other-locales.ts index aa4ec78e..b876421d 100644 --- a/lib/rules/no-missing-keys-in-other-locales.ts +++ b/lib/rules/no-missing-keys-in-other-locales.ts @@ -333,8 +333,7 @@ export = createRule({ docs: { description: 'disallow missing locale message keys in other locales', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys-in-other-locales.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys-in-other-locales.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-missing-keys.ts b/lib/rules/no-missing-keys.ts index 0bb9d022..0b98a68a 100644 --- a/lib/rules/no-missing-keys.ts +++ b/lib/rules/no-missing-keys.ts @@ -24,7 +24,7 @@ function create(context: RuleContext): RuleListener { }, ["VElement:matches([name=i18n], [name=i18n-t]) > VStartTag > VAttribute[key.name='path']," + - "VElement[name=i18n-t] > VStartTag > VAttribute[key.name='keypath']"]( + "VElement[name=i18n-t] > VStartTag > VAttribute[key.name='keypath']"]( node: VAST.VAttribute ) { checkComponent(context, node) @@ -138,8 +138,7 @@ export = createRule({ description: 'disallow missing locale message key at localization methods', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-missing-keys.html', recommended: true }, fixable: null, diff --git a/lib/rules/no-unknown-locale.ts b/lib/rules/no-unknown-locale.ts index ccfadcef..51169456 100644 --- a/lib/rules/no-unknown-locale.ts +++ b/lib/rules/no-unknown-locale.ts @@ -244,8 +244,7 @@ export = createRule({ docs: { description: 'disallow unknown locale name', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unknown-locale.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unknown-locale.html', recommended: false }, fixable: null, diff --git a/lib/rules/no-unused-keys.ts b/lib/rules/no-unused-keys.ts index 7e02be67..da519d5a 100644 --- a/lib/rules/no-unused-keys.ts +++ b/lib/rules/no-unused-keys.ts @@ -566,8 +566,7 @@ export = createRule({ docs: { description: 'disallow unused localization keys', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unused-keys.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-unused-keys.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/prefer-linked-key-with-paren.ts b/lib/rules/prefer-linked-key-with-paren.ts index aa16430c..ac550b23 100644 --- a/lib/rules/prefer-linked-key-with-paren.ts +++ b/lib/rules/prefer-linked-key-with-paren.ts @@ -247,8 +247,7 @@ export = createRule({ docs: { description: 'enforce linked key to be enclosed in parentheses', category: 'Stylistic Issues', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-linked-key-with-paren.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-linked-key-with-paren.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/prefer-sfc-lang-attr.ts b/lib/rules/prefer-sfc-lang-attr.ts index 0f9b4aad..f9d80354 100644 --- a/lib/rules/prefer-sfc-lang-attr.ts +++ b/lib/rules/prefer-sfc-lang-attr.ts @@ -28,7 +28,8 @@ function create(context: RuleContext): RuleListener { if (langAttrs) { return fixer.replaceTextRange(langAttrs.range, 'lang="json"') } - const tokenStore = context.parserServices.getTemplateBodyTokenStore() + const tokenStore = + context.parserServices.getTemplateBodyTokenStore() const closeToken = tokenStore.getLastToken(i18n.startTag) const beforeToken = tokenStore.getTokenBefore(closeToken) return fixer.insertTextBeforeRange( @@ -50,8 +51,7 @@ export = createRule({ docs: { description: 'require lang attribute on `` block', category: 'Best Practices', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-sfc-lang-attr.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/prefer-sfc-lang-attr.html', recommended: false }, fixable: 'code', diff --git a/lib/rules/sfc-locale-attr.ts b/lib/rules/sfc-locale-attr.ts index 676e7e6a..7e796a0a 100644 --- a/lib/rules/sfc-locale-attr.ts +++ b/lib/rules/sfc-locale-attr.ts @@ -8,8 +8,7 @@ export = createRule({ docs: { description: 'require or disallow the locale attribute on `` block', category: 'Stylistic Issues', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/sfc-locale-attr.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/sfc-locale-attr.html', recommended: false }, fixable: null, diff --git a/lib/rules/valid-message-syntax.ts b/lib/rules/valid-message-syntax.ts index 92ea2b21..fc8b043a 100644 --- a/lib/rules/valid-message-syntax.ts +++ b/lib/rules/valid-message-syntax.ts @@ -75,9 +75,8 @@ function create(context: RuleContext): RuleListener { parent: JSONAST.JSONNode ) { let message - let getReportOffset: - | ((error: CompileError) => number | null) - | null = null + let getReportOffset: ((error: CompileError) => number | null) | null = + null if (node) { if ( node.type === 'JSONArrayExpression' || @@ -127,9 +126,8 @@ function create(context: RuleContext): RuleListener { parent: YAMLAST.YAMLNode ) { let message - let getReportOffset: - | ((error: CompileError) => number | null) - | null = null + let getReportOffset: ((error: CompileError) => number | null) | null = + null if (node) { const valueNode = node.type === 'YAMLWithMeta' ? node.value : node if ( @@ -205,8 +203,7 @@ export = createRule({ docs: { description: 'disallow invalid message syntax', category: 'Recommended', - url: - 'https://eslint-plugin-vue-i18n.intlify.dev/rules/valid-message-syntax.html', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/valid-message-syntax.html', // TODO To avoid breaking changes, include it in the configuration at the time of version upgrade. recommended: false }, diff --git a/lib/types/eslint.ts b/lib/types/eslint.ts index 5598ce2b..ca5256b6 100644 --- a/lib/types/eslint.ts +++ b/lib/types/eslint.ts @@ -128,9 +128,7 @@ export interface SourceCode extends TokenStore { getText(node?: MaybeNode, beforeCount?: number, afterCount?: number): string getLines(): string[] getAllComments(): MaybeToken[] - getComments( - node: MaybeNode - ): { + getComments(node: MaybeNode): { leading: MaybeToken[] trailing: MaybeToken[] } diff --git a/lib/utils/collect-keys.ts b/lib/utils/collect-keys.ts index c858d9e1..1c5eb220 100644 --- a/lib/utils/collect-keys.ts +++ b/lib/utils/collect-keys.ts @@ -73,9 +73,7 @@ function getKeyFromI18nComponent(node: VAST.VAttribute) { } } -function getParser( - parser: string | undefined -): { +function getParser(parser: string | undefined): { parseForESLint?: typeof parseForESLint parse: (code: string, options: unknown) => VAST.ESLintProgram } { diff --git a/lib/utils/glob-sync.ts b/lib/utils/glob-sync.ts index 1a0f1a4d..af513e76 100644 --- a/lib/utils/glob-sync.ts +++ b/lib/utils/glob-sync.ts @@ -35,7 +35,7 @@ GlobSync.prototype._readdir = function (abs, inGlobStar) { return Sync.prototype._readdir.call(this, abs, inGlobStar) } -export default (GlobSync as never) as new ( +export default GlobSync as never as new ( pattern: string, options: IOptions, shouldIgnore: (absolutePath: string) => boolean diff --git a/lib/utils/glob-utils.ts b/lib/utils/glob-utils.ts index 99aa76e8..c97ac97d 100644 --- a/lib/utils/glob-utils.ts +++ b/lib/utils/glob-utils.ts @@ -228,9 +228,9 @@ export function listFilesToProcess( pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE ) ) { - throw new (pathsForCurrentGlob.length - ? AllFilesIgnoredError - : NoFilesFoundError)(globPatterns[index]) + throw new ( + pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError + )(globPatterns[index]) } pathsForCurrentGlob.forEach(pathDescriptor => { diff --git a/lib/utils/index.ts b/lib/utils/index.ts index f106e11f..71e32ec3 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -505,9 +505,7 @@ export function isI18nBlock( * Get the static attribute values from a given element. * @param element The element to get. */ -export function getStaticAttributes( - element: VAST.VElement -): { +export function getStaticAttributes(element: VAST.VElement): { [name: string]: string | undefined } { const attrs: { [name: string]: string | undefined } = {} diff --git a/lib/utils/message-compiler/parser-v8.ts b/lib/utils/message-compiler/parser-v8.ts index 38ab565e..30053ee0 100644 --- a/lib/utils/message-compiler/parser-v8.ts +++ b/lib/utils/message-compiler/parser-v8.ts @@ -18,9 +18,7 @@ import type { import lodash from 'lodash' import { NodeTypes } from './utils' -export function parse( - code: string -): { +export function parse(code: string): { ast: ResourceNode errors: CompileError[] } { diff --git a/lib/utils/message-compiler/parser.ts b/lib/utils/message-compiler/parser.ts index dbaf877f..4abc6f79 100644 --- a/lib/utils/message-compiler/parser.ts +++ b/lib/utils/message-compiler/parser.ts @@ -1,9 +1,7 @@ import type { CompileError, ResourceNode } from '@intlify/message-compiler' import { createParser } from '@intlify/message-compiler' -export function parse( - code: string -): { +export function parse(code: string): { ast: ResourceNode errors: CompileError[] } { diff --git a/tests/lib/rules/no-unused-keys.ts b/tests/lib/rules/no-unused-keys.ts index 07f35b4b..b692d48b 100644 --- a/tests/lib/rules/no-unused-keys.ts +++ b/tests/lib/rules/no-unused-keys.ts @@ -152,7 +152,8 @@ new RuleTester({ localeDir: { pattern: `./locales/**/*.{json,yaml,yml}`, localeKey: 'path', - localePattern: /^.*\/(?[A-Za-z0-9-_]+)\/.*\.(json5?|ya?ml)$/ + localePattern: + /^.*\/(?[A-Za-z0-9-_]+)\/.*\.(json5?|ya?ml)$/ }, options: [ { diff --git a/tests/lib/test-utils.ts b/tests/lib/test-utils.ts index abc57227..a2cc0e4c 100644 --- a/tests/lib/test-utils.ts +++ b/tests/lib/test-utils.ts @@ -77,9 +77,7 @@ const PARSERS = { '.yaml': require.resolve('yaml-eslint-parser'), '.yml': require.resolve('yaml-eslint-parser') } -function* extractTargetFiles( - dir: string -): IterableIterator<{ +function* extractTargetFiles(dir: string): IterableIterator<{ filename: string relative: string parser: string | undefined