-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathno-i18n-t-path-prop.ts
55 lines (53 loc) · 1.39 KB
/
no-i18n-t-path-prop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @author Yosuke Ota
*/
import {
defineTemplateBodyVisitor,
getAttribute,
getDirective
} from '../utils/index'
import type { RuleContext, RuleListener } from '../types'
import type { AST as VAST } from 'vue-eslint-parser'
import { createRule } from '../utils/rule'
function create(context: RuleContext): RuleListener {
return defineTemplateBodyVisitor(context, {
VElement(node: VAST.VElement) {
if (node.name !== 'i18n-t') {
return
}
const pathProp =
getAttribute(node, 'path') || getDirective(node, 'bind', 'path')
if (pathProp) {
context.report({
node: pathProp.key,
messageId: 'disallow',
fix(fixer) {
if (pathProp.directive) {
return fixer.replaceText(pathProp.key.argument!, 'keypath')
} else {
return fixer.replaceText(pathProp.key, 'keypath')
}
}
})
}
}
})
}
export default createRule({
meta: {
type: 'problem',
docs: {
description: 'disallow using `path` prop with `<i18n-t>`',
category: 'Recommended',
url: 'https://eslint-plugin-vue-i18n.intlify.dev/rules/no-i18n-t-path-prop.html',
recommended: false
},
fixable: 'code',
schema: [],
messages: {
disallow:
'Cannot use `path` prop with `<i18n-t>` component. Use `keypath` prop instead.'
}
},
create
})