Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: intlify/eslint-plugin-vue-i18n
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0-next.11
Choose a base ref
...
head repository: intlify/eslint-plugin-vue-i18n
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.0.0-next.12
Choose a head ref
  • 6 commits
  • 11 files changed
  • 6 contributors

Commits on Apr 23, 2024

  1. docs: enable local search (#504)

    vintagesucks authored Apr 23, 2024
    Copy the full SHA
    138448c View commit details
  2. chore(deps): update dependency monaco-editor to ^0.48.0

    renovate[bot] committed Apr 23, 2024
    Copy the full SHA
    70187f8 View commit details

Commits on Apr 30, 2024

  1. chore(deps): update pnpm to v8.15.8

    renovate[bot] committed Apr 30, 2024
    Copy the full SHA
    4a966e1 View commit details

Commits on May 10, 2024

  1. feat: add no-deprecated-tc rule (#510)

    * feat: add `no-deprecated-tc` rule
    
    * Create new-apples-ring.md
    kazupon authored May 10, 2024
    Copy the full SHA
    61b0c94 View commit details
  2. Update new-apples-ring.md

    ota-meshi authored May 10, 2024
    Copy the full SHA
    1e7ab15 View commit details
  3. chore: release @intlify/eslint-plugin-vue-i18n (next) (#511)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored May 10, 2024
    Copy the full SHA
    3be0121 View commit details
Showing with 187 additions and 7 deletions.
  1. +5 −0 .changeset/new-apples-ring.md
  2. +1 −0 .changeset/pre.json
  3. +6 −0 CHANGELOG.md
  4. +3 −0 docs/.vitepress/config.mts
  5. +1 −0 docs/rules/index.md
  6. +64 −0 docs/rules/no-deprecated-tc.md
  7. +2 −0 lib/index.ts
  8. +60 −0 lib/rules/no-deprecated-tc.ts
  9. +3 −3 package.json
  10. +4 −4 pnpm-lock.yaml
  11. +38 −0 tests/lib/rules/no-deprecated-tc.ts
5 changes: 5 additions & 0 deletions .changeset/new-apples-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@intlify/eslint-plugin-vue-i18n": minor
---

feat: add `no-deprecated-tc` rule
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
"grumpy-forks-brake",
"khaki-eyes-serve",
"modern-apricots-flash",
"new-apples-ring",
"ninety-snakes-scream",
"olive-chairs-invent",
"pink-hairs-fail",
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @intlify/eslint-plugin-vue-i18n

## 3.0.0-next.12

### Minor Changes

- [#510](https://github.com/intlify/eslint-plugin-vue-i18n/pull/510) [`61b0c94`](https://github.com/intlify/eslint-plugin-vue-i18n/commit/61b0c944ada23408b8943658e4e9473af3733202) Thanks [@kazupon](https://github.com/kazupon)! - feat: add `no-deprecated-tc` rule

## 3.0.0-next.11

### Minor Changes
3 changes: 3 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@ export default async () => {
'https://github.com/intlify/eslint-plugin-vue-i18n/edit/master/docs/:path',
text: 'Edit this page on GitHub'
},
search: {
provider: 'local'
},
nav: [
{
text: 'Support Intlify',
1 change: 1 addition & 0 deletions docs/rules/index.md
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
| Rule ID | Description | |
|:--------|:------------|:---|
| [@intlify/vue-i18n/<wbr>key-format-style](./key-format-style.html) | enforce specific casing for localization keys | |
| [@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) | |
| [@intlify/vue-i18n/<wbr>no-duplicate-keys-in-locale](./no-duplicate-keys-in-locale.html) | disallow duplicate localization keys within the same locale | |
| [@intlify/vue-i18n/<wbr>no-dynamic-keys](./no-dynamic-keys.html) | disallow localization dynamic keys at localization methods | |
| [@intlify/vue-i18n/<wbr>no-missing-keys-in-other-locales](./no-missing-keys-in-other-locales.html) | disallow missing locale message keys in other locales | |
64 changes: 64 additions & 0 deletions docs/rules/no-deprecated-tc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: '@intlify/vue-i18n/no-deprecated-tc'
description: disallow using deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0)
since: v3.0.0
---

# @intlify/vue-i18n/no-deprecated-tc

> disallow using deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0)
If you are migrating from Vue I18n v9 to v10, `tc` or `$tc` should be replaced with `t` or `$t`.

## :book: Rule Details

This rule reports use of deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0)

:-1: Examples of **incorrect** code for this rule:

<eslint-code-block>

<!-- eslint-skip -->

```vue
<script>
/* eslint @intlify/vue-i18n/no-deprecated-tc: 'error' */
</script>
<template>
<!-- ✗ BAD -->
<p>{{ $tc('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-tc: 'error' */
</script>
<template>
<!-- ✓ GOOD -->
<p>{{ $t('banana', 1) }}</p>
</template>
```

</eslint-code-block>

## :books: Further reading

- [Vue I18n > Breaking Changes in v10 - Deprecate tc and $tc for Legacy API mode](https://vue-i18n.intlify.dev/guide/migration/breaking10.html#deprecate-tc-and-tc-for-legacy-api-mode)

## :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-tc.ts)
- [Test source](https://github.com/intlify/eslint-plugin-vue-i18n/tree/master/tests/lib/rules/no-deprecated-tc.ts)
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import noDeprecatedI18nComponent from './rules/no-deprecated-i18n-component'
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 noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
import noDynamicKeys from './rules/no-dynamic-keys'
import noHtmlMessages from './rules/no-html-messages'
@@ -43,6 +44,7 @@ export = {
'no-deprecated-i18n-place-attr': noDeprecatedI18nPlaceAttr,
'no-deprecated-i18n-places-prop': noDeprecatedI18nPlacesProp,
'no-deprecated-modulo-syntax': noDeprecatedModuloSyntax,
'no-deprecated-tc': noDeprecatedTc,
'no-duplicate-keys-in-locale': noDuplicateKeysInLocale,
'no-dynamic-keys': noDynamicKeys,
'no-html-messages': noHtmlMessages,
60 changes: 60 additions & 0 deletions lib/rules/no-deprecated-tc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @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 checkCallExpression(
context: RuleContext,
node: VAST.ESLintCallExpression
) {
const funcName =
(node.callee.type === 'MemberExpression' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name) ||
(node.callee.type === 'Identifier' && node.callee.name) ||
''

if (/^(\$tc|tc)$/.test(funcName)) {
context.report({
node,
message: `'${funcName}' is used, but it is deprecated. Use 't' or '$t' instead.`
})
return
}
}

function create(context: RuleContext): RuleListener {
return defineTemplateBodyVisitor(
context,
{
CallExpression(node: VAST.ESLintCallExpression) {
checkCallExpression(context, node)
}
},
{
CallExpression(node: VAST.ESLintCallExpression) {
checkCallExpression(context, node)
}
}
)
}

export = createRule({
meta: {
type: 'suggestion',
docs: {
description:
'disallow using deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0)',
category: 'Best Practices',
url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-tc.html',
recommended: false
},
fixable: null,
schema: []
},
create
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@intlify/eslint-plugin-vue-i18n",
"description": "ESLint plugin for Vue I18n",
"version": "3.0.0-next.11",
"version": "3.0.0-next.12",
"license": "MIT",
"homepage": "https://github.com/intlify/eslint-plugin-vue-i18n#readme",
"keywords": [
@@ -29,7 +29,7 @@
"engines": {
"node": ">=16.0.0"
},
"packageManager": "pnpm@8.15.7",
"packageManager": "pnpm@8.15.8",
"type": "commonjs",
"files": [
"dist"
@@ -109,7 +109,7 @@
"json-schema": "^0.4.0",
"lint-staged": "^15.0.0",
"mocha": "^10.2.0",
"monaco-editor": "^0.47.0",
"monaco-editor": "^0.48.0",
"npm-run-all2": "6.1.2",
"nyc": "^15.1.0",
"opener": "^1.5.2",
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions tests/lib/rules/no-deprecated-tc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @author kazuya kawaguchi (a.k.a. kazupon)
*/
import { RuleTester } from '../eslint-compat'
import rule from '../../../lib/rules/no-deprecated-tc'
import * as vueParser from 'vue-eslint-parser'

const tester = new RuleTester({
languageOptions: { parser: vueParser, ecmaVersion: 2015 }
})

tester.run('no-deprecated-tc', rule as never, {
valid: [],
invalid: [
{
// tc key
code: `tc('banana')`,
errors: [`'tc' is used, but it is deprecated. Use 't' or '$t' instead.`]
},
{
// $tc key
code: `$tc('banana')`,
errors: [`'$tc' is used, but it is deprecated. Use 't' or '$t' instead.`]
},
{
// via i18n instance
code: `i18n.tc('banana')`,
errors: [`'tc' is used, but it is deprecated. Use 't' or '$t' instead.`]
},
{
// using mustaches in template block
code: `<template>
<p>{{ $tc('banana') }}</p>
</template>`,
errors: [`'$tc' is used, but it is deprecated. Use 't' or '$t' instead.`]
}
]
})