From 692155900f3018e9d710d85e205419aa3f76eabe Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 6 Dec 2024 16:04:28 +0900 Subject: [PATCH 1/6] feat: add `no-deprecated-v-t` rule --- docs/rules/index.md | 1 + docs/rules/no-deprecated-v-t.md | 66 ++++++++++++++++++++++++++++ lib/configs/flat/recommended.ts | 1 + lib/configs/recommended.ts | 1 + lib/index.ts | 2 + lib/rules/no-deprecated-v-t.ts | 43 ++++++++++++++++++ tests/lib/rules/no-deprecated-v-t.ts | 26 +++++++++++ 7 files changed, 140 insertions(+) create mode 100644 docs/rules/no-deprecated-v-t.md create mode 100644 lib/rules/no-deprecated-v-t.ts create mode 100644 tests/lib/rules/no-deprecated-v-t.ts diff --git a/docs/rules/index.md b/docs/rules/index.md index 93c5d881..8ae409ca 100644 --- a/docs/rules/index.md +++ b/docs/rules/index.md @@ -13,6 +13,7 @@ | [@intlify/vue-i18n/no-deprecated-i18n-places-prop](./no-deprecated-i18n-places-prop.html) | disallow using deprecated `places` prop (Removed in Vue I18n 9.0.0+) | :star: | | [@intlify/vue-i18n/no-deprecated-modulo-syntax](./no-deprecated-modulo-syntax.html) | enforce modulo interpolation to be named interpolation | :star::black_nib: | | [@intlify/vue-i18n/no-deprecated-tc](./no-deprecated-tc.html) | disallow using deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0) | :star: | +| [@intlify/vue-i18n/no-deprecated-v-t](./no-deprecated-v-t.html) | disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) | :star: | | [@intlify/vue-i18n/no-html-messages](./no-html-messages.html) | disallow use HTML localization messages | :star: | | [@intlify/vue-i18n/no-i18n-t-path-prop](./no-i18n-t-path-prop.html) | disallow using `path` prop with `` | :star::black_nib: | | [@intlify/vue-i18n/no-missing-keys](./no-missing-keys.html) | disallow missing locale message key at localization methods | :star: | diff --git a/docs/rules/no-deprecated-v-t.md b/docs/rules/no-deprecated-v-t.md new file mode 100644 index 00000000..af57694d --- /dev/null +++ b/docs/rules/no-deprecated-v-t.md @@ -0,0 +1,66 @@ +--- +title: '@intlify/vue-i18n/no-deprecated-v-t' +description: disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) +since: v3.0.0 +--- + +# @intlify/vue-i18n/no-deprecated-v-t + +> disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) + +- :star: The `"extends": "plugin:@intlify/vue-i18n/recommended"` or `*.configs["flat/recommended"]` property in a configuration file enables this rule. + +If you are migrating from Vue I18n v10 to v11, `v-t` custom direcitve should be replaced with `t` or `$t`. + +## :book: Rule Details + +This rule reports use of deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) + +:-1: Examples of **incorrect** code for this rule: + + + + + +```vue + + +``` + + + +:+1: Examples of **correct** code for this rule: + + + + + +```vue + + +``` + + + +## :books: Further reading + +- [Vue I18n > Breaking Changes in v11 - Deprecate Custom Directive `v-t`](https://vue-i18n.intlify.dev/guide/migration/breaking11.html#deprecate-custom-directive-v-t) + +## :rocket: Version + +This rule was introduced in `@intlify/eslint-plugin-vue-i18n` v3.0.0 + +## :mag: Implementation + +- [Rule source](https://github.com/intlify/eslint-plugin-vue-i18n/blob/master/lib/rules/no-deprecated-v-t.ts) +- [Test source](https://github.com/intlify/eslint-plugin-vue-i18n/tree/master/tests/lib/rules/no-deprecated-v-t.ts) diff --git a/lib/configs/flat/recommended.ts b/lib/configs/flat/recommended.ts index f1e538af..280d1f9b 100644 --- a/lib/configs/flat/recommended.ts +++ b/lib/configs/flat/recommended.ts @@ -24,6 +24,7 @@ export = [ '@intlify/vue-i18n/no-deprecated-i18n-places-prop': 'warn', '@intlify/vue-i18n/no-deprecated-modulo-syntax': 'warn', '@intlify/vue-i18n/no-deprecated-tc': 'warn', + '@intlify/vue-i18n/no-deprecated-v-t': 'warn', '@intlify/vue-i18n/no-html-messages': 'warn', '@intlify/vue-i18n/no-i18n-t-path-prop': 'warn', '@intlify/vue-i18n/no-missing-keys': 'warn', diff --git a/lib/configs/recommended.ts b/lib/configs/recommended.ts index ababfea3..f56b0d22 100644 --- a/lib/configs/recommended.ts +++ b/lib/configs/recommended.ts @@ -18,6 +18,7 @@ export = { '@intlify/vue-i18n/no-deprecated-i18n-places-prop': 'warn', '@intlify/vue-i18n/no-deprecated-modulo-syntax': 'warn', '@intlify/vue-i18n/no-deprecated-tc': 'warn', + '@intlify/vue-i18n/no-deprecated-v-t': 'warn', '@intlify/vue-i18n/no-html-messages': 'warn', '@intlify/vue-i18n/no-i18n-t-path-prop': 'warn', '@intlify/vue-i18n/no-missing-keys': 'warn', diff --git a/lib/index.ts b/lib/index.ts index 3bad70a2..75ef61b5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -12,6 +12,7 @@ import noDeprecatedI18nPlaceAttr from './rules/no-deprecated-i18n-place-attr' import noDeprecatedI18nPlacesProp from './rules/no-deprecated-i18n-places-prop' import noDeprecatedModuloSyntax from './rules/no-deprecated-modulo-syntax' import noDeprecatedTc from './rules/no-deprecated-tc' +import noDeprecatedVT from './rules/no-deprecated-v-t' import noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale' import noDynamicKeys from './rules/no-dynamic-keys' import noHtmlMessages from './rules/no-html-messages' @@ -45,6 +46,7 @@ export = { 'no-deprecated-i18n-places-prop': noDeprecatedI18nPlacesProp, 'no-deprecated-modulo-syntax': noDeprecatedModuloSyntax, 'no-deprecated-tc': noDeprecatedTc, + 'no-deprecated-v-t': noDeprecatedVT, 'no-duplicate-keys-in-locale': noDuplicateKeysInLocale, 'no-dynamic-keys': noDynamicKeys, 'no-html-messages': noHtmlMessages, diff --git a/lib/rules/no-deprecated-v-t.ts b/lib/rules/no-deprecated-v-t.ts new file mode 100644 index 00000000..9485a303 --- /dev/null +++ b/lib/rules/no-deprecated-v-t.ts @@ -0,0 +1,43 @@ +/** + * @author kazuya kawaguchi (a.k.a. kazupon) + */ +import { defineTemplateBodyVisitor } from '../utils/index' +import { createRule } from '../utils/rule' + +import type { RuleContext, RuleListener } from '../types' +import type { AST as VAST } from 'vue-eslint-parser' + +function checkDirective(context: RuleContext, node: VAST.VDirective) { + context.report({ + node, + message: `'v-t' custom directive is used, but it is deprecated. Use 't' or '$t' instead.` + }) +} + +function create(context: RuleContext): RuleListener { + return defineTemplateBodyVisitor(context, { + "VAttribute[directive=true][key.name='t']"(node: VAST.VDirective) { + checkDirective(context, node) + }, + + "VAttribute[directive=true][key.name.name='t']"(node: VAST.VDirective) { + checkDirective(context, node) + } + }) +} + +export = createRule({ + meta: { + type: 'problem', + docs: { + description: + 'disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0)', + category: 'Recommended', + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-v-t.html', + recommended: true + }, + fixable: null, + schema: [] + }, + create +}) diff --git a/tests/lib/rules/no-deprecated-v-t.ts b/tests/lib/rules/no-deprecated-v-t.ts new file mode 100644 index 00000000..097bca0d --- /dev/null +++ b/tests/lib/rules/no-deprecated-v-t.ts @@ -0,0 +1,26 @@ +/** + * @author kazuya kawaguchi (a.k.a. kazupon) + */ +import { RuleTester } from '../eslint-compat' +import rule from '../../../lib/rules/no-deprecated-v-t' +import * as vueParser from 'vue-eslint-parser' + +const tester = new RuleTester({ + languageOptions: { + parser: vueParser, + ecmaVersion: 2020, + sourceType: 'module' + } +}) + +tester.run('no-deprecated-v-t', rule as never, { + valid: [], + invalid: [ + { + code: ``, + errors: [ + `'v-t' custom directive is used, but it is deprecated. Use 't' or '$t' instead.` + ] + } + ] +}) From 7e88518e24160dc8a016e55c369203b7dce5d89a Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 6 Dec 2024 18:09:46 +0900 Subject: [PATCH 2/6] docs: fix version --- docs/rules/no-deprecated-v-t.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/no-deprecated-v-t.md b/docs/rules/no-deprecated-v-t.md index af57694d..36f78c2d 100644 --- a/docs/rules/no-deprecated-v-t.md +++ b/docs/rules/no-deprecated-v-t.md @@ -1,7 +1,7 @@ --- title: '@intlify/vue-i18n/no-deprecated-v-t' description: disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) -since: v3.0.0 +since: v3.2.0 --- # @intlify/vue-i18n/no-deprecated-v-t From 38b45ff87ebad4238377c65dae944ba3963d6900 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 6 Dec 2024 19:07:44 +0900 Subject: [PATCH 3/6] Create chilled-colts-destroy.md --- .changeset/chilled-colts-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilled-colts-destroy.md diff --git a/.changeset/chilled-colts-destroy.md b/.changeset/chilled-colts-destroy.md new file mode 100644 index 00000000..57a61aed --- /dev/null +++ b/.changeset/chilled-colts-destroy.md @@ -0,0 +1,5 @@ +--- +"@intlify/eslint-plugin-vue-i18n": minor +--- + +feat: add `no-deprecated-v-t` rule From e904aeb200f314fd5f4fcbfeda5a624ce578f980 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 8 Dec 2024 15:38:01 +0900 Subject: [PATCH 4/6] Revert "docs: fix version" This reverts commit 7e88518e24160dc8a016e55c369203b7dce5d89a. --- docs/rules/no-deprecated-v-t.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/no-deprecated-v-t.md b/docs/rules/no-deprecated-v-t.md index 36f78c2d..af57694d 100644 --- a/docs/rules/no-deprecated-v-t.md +++ b/docs/rules/no-deprecated-v-t.md @@ -1,7 +1,7 @@ --- title: '@intlify/vue-i18n/no-deprecated-v-t' description: disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0) -since: v3.2.0 +since: v3.0.0 --- # @intlify/vue-i18n/no-deprecated-v-t From 75ef3f82ecdd25a74555a24b110f6f19c8011270 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 8 Dec 2024 15:43:39 +0900 Subject: [PATCH 5/6] fix: ref https://github.com/intlify/eslint-plugin-vue-i18n/pull/580#discussion_r1872975168 --- lib/rules/no-deprecated-v-t.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/no-deprecated-v-t.ts b/lib/rules/no-deprecated-v-t.ts index 9485a303..f34fae95 100644 --- a/lib/rules/no-deprecated-v-t.ts +++ b/lib/rules/no-deprecated-v-t.ts @@ -34,7 +34,7 @@ export = createRule({ 'disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0)', category: 'Recommended', url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-v-t.html', - recommended: true + recommended: false }, fixable: null, schema: [] From 7e22f0280663509560f4017633706c59dee382cf Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 8 Dec 2024 15:45:06 +0900 Subject: [PATCH 6/6] fix: add valid test --- tests/lib/rules/no-deprecated-v-t.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/lib/rules/no-deprecated-v-t.ts b/tests/lib/rules/no-deprecated-v-t.ts index 097bca0d..b27d3960 100644 --- a/tests/lib/rules/no-deprecated-v-t.ts +++ b/tests/lib/rules/no-deprecated-v-t.ts @@ -14,7 +14,11 @@ const tester = new RuleTester({ }) tester.run('no-deprecated-v-t', rule as never, { - valid: [], + valid: [ + { + code: `` + } + ], invalid: [ { code: ``,