|
| 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 checkCallExpression( |
| 11 | + context: RuleContext, |
| 12 | + node: VAST.ESLintCallExpression |
| 13 | +) { |
| 14 | + const funcName = |
| 15 | + (node.callee.type === 'MemberExpression' && |
| 16 | + node.callee.property.type === 'Identifier' && |
| 17 | + node.callee.property.name) || |
| 18 | + (node.callee.type === 'Identifier' && node.callee.name) || |
| 19 | + '' |
| 20 | + |
| 21 | + if (/^(\$tc|tc)$/.test(funcName)) { |
| 22 | + context.report({ |
| 23 | + node, |
| 24 | + message: `'${funcName}' is used, but it is deprecated. Use 't' or '$t' instead.` |
| 25 | + }) |
| 26 | + return |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +function create(context: RuleContext): RuleListener { |
| 31 | + return defineTemplateBodyVisitor( |
| 32 | + context, |
| 33 | + { |
| 34 | + CallExpression(node: VAST.ESLintCallExpression) { |
| 35 | + checkCallExpression(context, node) |
| 36 | + } |
| 37 | + }, |
| 38 | + { |
| 39 | + CallExpression(node: VAST.ESLintCallExpression) { |
| 40 | + checkCallExpression(context, node) |
| 41 | + } |
| 42 | + } |
| 43 | + ) |
| 44 | +} |
| 45 | + |
| 46 | +export = createRule({ |
| 47 | + meta: { |
| 48 | + type: 'suggestion', |
| 49 | + docs: { |
| 50 | + description: |
| 51 | + 'disallow using deprecated `tc` or `$tc` (Deprecated in Vue I18n 10.0.0, removed fully in Vue I18n 11.0.0)', |
| 52 | + category: 'Best Practices', |
| 53 | + url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-deprecated-tc.html', |
| 54 | + recommended: false |
| 55 | + }, |
| 56 | + fixable: null, |
| 57 | + schema: [] |
| 58 | + }, |
| 59 | + create |
| 60 | +}) |
0 commit comments