-
-
Notifications
You must be signed in to change notification settings - Fork 44
feat: add no-deprecated-v-t
rule
#580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
6921559
7e88518
38b45ff
e904aeb
75ef3f8
7e22f02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.2.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: | ||
|
||
<eslint-code-block> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```vue | ||
<script> | ||
/* eslint @intlify/vue-i18n/no-deprecated-v-t: 'error' */ | ||
</script> | ||
<template> | ||
<!-- ✗ BAD --> | ||
<p v-t="'banana'"></p> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
:+1: Examples of **correct** code for this rule: | ||
|
||
<eslint-code-block> | ||
|
||
<!-- eslint-skip --> | ||
|
||
```vue | ||
<script> | ||
/* eslint @intlify/vue-i18n/no-deprecated-v-t: 'error' */ | ||
</script> | ||
<template> | ||
<!-- ✓ GOOD --> | ||
<p>{{ $t('banana') }}</p> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :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) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing shareable configuration may be considered a breaking change.
Suggested change
I think that in the next major version we can clarify the versioning policy and allow configuration to change in minor versions. v10 of eslint-plugin-vue will do that too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree too. |
||||||
}, | ||||||
fixable: null, | ||||||
schema: [] | ||||||
}, | ||||||
create | ||||||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to be sure, could you add a test case to verify that other directives are not detected? |
||
invalid: [ | ||
{ | ||
code: `<template><p v-t="'banana'"></p></template>`, | ||
errors: [ | ||
`'v-t' custom directive is used, but it is deprecated. Use 't' or '$t' instead.` | ||
] | ||
} | ||
] | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added automatically upon release.