File tree 8 files changed +149
-0
lines changed
8 files changed +149
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @intlify/eslint-plugin-vue-i18n " : minor
3
+ ---
4
+
5
+ feat: add ` no-deprecated-v-t ` rule
Original file line number Diff line number Diff line change 13
13
| [ @intlify/vue-i18n /<wbr >no-deprecated-i18n-places-prop] ( ./no-deprecated-i18n-places-prop.html ) | disallow using deprecated ` places ` prop (Removed in Vue I18n 9.0.0+) | :star : |
14
14
| [ @intlify/vue-i18n /<wbr >no-deprecated-modulo-syntax] ( ./no-deprecated-modulo-syntax.html ) | enforce modulo interpolation to be named interpolation | :star ::black_nib : |
15
15
| [ @intlify/vue-i18n /<wbr >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 : |
16
+ | [ @intlify/vue-i18n /<wbr >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 : |
16
17
| [ @intlify/vue-i18n /<wbr >no-html-messages] ( ./no-html-messages.html ) | disallow use HTML localization messages | :star : |
17
18
| [ @intlify/vue-i18n /<wbr >no-i18n-t-path-prop] ( ./no-i18n-t-path-prop.html ) | disallow using ` path ` prop with ` <i18n-t> ` | :star ::black_nib : |
18
19
| [ @intlify/vue-i18n /<wbr >no-missing-keys] ( ./no-missing-keys.html ) | disallow missing locale message key at localization methods | :star : |
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : ' @intlify/vue-i18n/no-deprecated-v-t'
3
+ description : disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0)
4
+ since : v3.0.0
5
+ ---
6
+
7
+ # @intlify/vue-i18n /no-deprecated-v-t
8
+
9
+ > disallow using deprecated ` v-t ` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0)
10
+
11
+ - :star : The ` "extends": "plugin:@intlify/vue-i18n/recommended" ` or ` *.configs["flat/recommended"] ` property in a configuration file enables this rule.
12
+
13
+ If you are migrating from Vue I18n v10 to v11, ` v-t ` custom direcitve should be replaced with ` t ` or ` $t ` .
14
+
15
+ ## :book : Rule Details
16
+
17
+ 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)
18
+
19
+ :-1 : Examples of ** incorrect** code for this rule:
20
+
21
+ <eslint-code-block >
22
+
23
+ <!-- eslint-skip -->
24
+
25
+ ``` vue
26
+ <script>
27
+ /* eslint @intlify/vue-i18n/no-deprecated-v-t: 'error' */
28
+ </script>
29
+ <template>
30
+ <!-- ✗ BAD -->
31
+ <p v-t="'banana'"></p>
32
+ </template>
33
+ ```
34
+
35
+ </eslint-code-block >
36
+
37
+ :+1 : Examples of ** correct** code for this rule:
38
+
39
+ <eslint-code-block >
40
+
41
+ <!-- eslint-skip -->
42
+
43
+ ``` vue
44
+ <script>
45
+ /* eslint @intlify/vue-i18n/no-deprecated-v-t: 'error' */
46
+ </script>
47
+ <template>
48
+ <!-- ✓ GOOD -->
49
+ <p>{{ $t('banana') }}</p>
50
+ </template>
51
+ ```
52
+
53
+ </eslint-code-block >
54
+
55
+ ## :books : Further reading
56
+
57
+ - [ 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 )
58
+
59
+ ## :rocket : Version
60
+
61
+ This rule was introduced in ` @intlify/eslint-plugin-vue-i18n ` v3.0.0
62
+
63
+ ## :mag : Implementation
64
+
65
+ - [ Rule source] ( https://github.com/intlify/eslint-plugin-vue-i18n/blob/master/lib/rules/no-deprecated-v-t.ts )
66
+ - [ Test source] ( https://github.com/intlify/eslint-plugin-vue-i18n/tree/master/tests/lib/rules/no-deprecated-v-t.ts )
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export = [
24
24
'@intlify/vue-i18n/no-deprecated-i18n-places-prop' : 'warn' ,
25
25
'@intlify/vue-i18n/no-deprecated-modulo-syntax' : 'warn' ,
26
26
'@intlify/vue-i18n/no-deprecated-tc' : 'warn' ,
27
+ '@intlify/vue-i18n/no-deprecated-v-t' : 'warn' ,
27
28
'@intlify/vue-i18n/no-html-messages' : 'warn' ,
28
29
'@intlify/vue-i18n/no-i18n-t-path-prop' : 'warn' ,
29
30
'@intlify/vue-i18n/no-missing-keys' : 'warn' ,
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export = {
18
18
'@intlify/vue-i18n/no-deprecated-i18n-places-prop' : 'warn' ,
19
19
'@intlify/vue-i18n/no-deprecated-modulo-syntax' : 'warn' ,
20
20
'@intlify/vue-i18n/no-deprecated-tc' : 'warn' ,
21
+ '@intlify/vue-i18n/no-deprecated-v-t' : 'warn' ,
21
22
'@intlify/vue-i18n/no-html-messages' : 'warn' ,
22
23
'@intlify/vue-i18n/no-i18n-t-path-prop' : 'warn' ,
23
24
'@intlify/vue-i18n/no-missing-keys' : 'warn' ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import noDeprecatedI18nPlaceAttr from './rules/no-deprecated-i18n-place-attr'
12
12
import noDeprecatedI18nPlacesProp from './rules/no-deprecated-i18n-places-prop'
13
13
import noDeprecatedModuloSyntax from './rules/no-deprecated-modulo-syntax'
14
14
import noDeprecatedTc from './rules/no-deprecated-tc'
15
+ import noDeprecatedVT from './rules/no-deprecated-v-t'
15
16
import noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
16
17
import noDynamicKeys from './rules/no-dynamic-keys'
17
18
import noHtmlMessages from './rules/no-html-messages'
@@ -45,6 +46,7 @@ export = {
45
46
'no-deprecated-i18n-places-prop' : noDeprecatedI18nPlacesProp ,
46
47
'no-deprecated-modulo-syntax' : noDeprecatedModuloSyntax ,
47
48
'no-deprecated-tc' : noDeprecatedTc ,
49
+ 'no-deprecated-v-t' : noDeprecatedVT ,
48
50
'no-duplicate-keys-in-locale' : noDuplicateKeysInLocale ,
49
51
'no-dynamic-keys' : noDynamicKeys ,
50
52
'no-html-messages' : noHtmlMessages ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author kazuya kawaguchi (a.k.a. kazupon)
3
+ */
4
+ import { defineTemplateBodyVisitor } from '../utils/index'
5
+ import { createRule } from '../utils/rule'
6
+
7
+ import type { RuleContext , RuleListener } from '../types'
8
+ import type { AST as VAST } from 'vue-eslint-parser'
9
+
10
+ function checkDirective ( context : RuleContext , node : VAST . VDirective ) {
11
+ context . report ( {
12
+ node,
13
+ message : `'v-t' custom directive is used, but it is deprecated. Use 't' or '$t' instead.`
14
+ } )
15
+ }
16
+
17
+ function create ( context : RuleContext ) : RuleListener {
18
+ return defineTemplateBodyVisitor ( context , {
19
+ "VAttribute[directive=true][key.name='t']" ( node : VAST . VDirective ) {
20
+ checkDirective ( context , node )
21
+ } ,
22
+
23
+ "VAttribute[directive=true][key.name.name='t']" ( node : VAST . VDirective ) {
24
+ checkDirective ( context , node )
25
+ }
26
+ } )
27
+ }
28
+
29
+ export = createRule ( {
30
+ meta : {
31
+ type : 'problem' ,
32
+ docs : {
33
+ description :
34
+ 'disallow using deprecated `v-t` custom directive (Deprecated in Vue I18n 11.0.0, removed fully in Vue I18n 12.0.0)' ,
35
+ category : 'Recommended' ,
36
+ url : 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-v-t.html' ,
37
+ recommended : false
38
+ } ,
39
+ fixable : null ,
40
+ schema : [ ]
41
+ } ,
42
+ create
43
+ } )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author kazuya kawaguchi (a.k.a. kazupon)
3
+ */
4
+ import { RuleTester } from '../eslint-compat'
5
+ import rule from '../../../lib/rules/no-deprecated-v-t'
6
+ import * as vueParser from 'vue-eslint-parser'
7
+
8
+ const tester = new RuleTester ( {
9
+ languageOptions : {
10
+ parser : vueParser ,
11
+ ecmaVersion : 2020 ,
12
+ sourceType : 'module'
13
+ }
14
+ } )
15
+
16
+ tester . run ( 'no-deprecated-v-t' , rule as never , {
17
+ valid : [
18
+ {
19
+ code : `<template><p v-html="$t('hello')"></p></template>`
20
+ }
21
+ ] ,
22
+ invalid : [
23
+ {
24
+ code : `<template><p v-t="'banana'"></p></template>` ,
25
+ errors : [
26
+ `'v-t' custom directive is used, but it is deprecated. Use 't' or '$t' instead.`
27
+ ]
28
+ }
29
+ ]
30
+ } )
You can’t perform that action at this time.
0 commit comments