Skip to content

Commit 04497da

Browse files
committed
📝 docs(vuepress): add no-missing-key rule documentation
1 parent 663b484 commit 04497da

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

docs/rules/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Available Rules
2+
3+
- :star: mark: the rule which is enabled by `vue-i18n/recommended` preset.
4+
- :black_nib: mark: the rule which is fixable by `eslint --fix` command.
5+
6+
## Possible Errors
7+
8+
| Rule ID | Description | |
9+
|:--------|:------------|:---|
10+
| [vue-i18n/<wbr>no-missing-key](./no-missing-key.html) | disallow missing locale message key at localization methods | :star: |
11+

docs/rules/no-missing-key.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# vue-i18n/no-missing-key
2+
3+
> disallow missing locale message key at localization methods
4+
5+
- :star: The `"extends": "plugin:vue-i18n/recommended"` property in a configuration file enables this rule.
6+
7+
This rule warns locale message key missing if the key does not exist in locale messages.
8+
9+
## :book: Rule Details
10+
11+
The methods that can be detected with this rule are as follows:
12+
13+
- `$t`
14+
- `t`
15+
- `$tc`
16+
- `tc`
17+
18+
:-1: Examples of **incorrect** code for this rule:
19+
20+
```js
21+
const localeMessages = {
22+
en: {
23+
hello: 'Hello! DIO!'
24+
}
25+
ja: {
26+
hello: 'こんにちは、DIO!'
27+
}
28+
}
29+
30+
const i18n = new VueI18n({
31+
locale: 'en',
32+
localeMessages
33+
})
34+
35+
/* ✗ BAD */
36+
i18n.t('hi')
37+
```
38+
39+
:+1: Examples of **correct** code for this rule:
40+
41+
```js
42+
const localeMessages = {
43+
en: {
44+
hello: 'Hello! DIO!'
45+
}
46+
ja: {
47+
hello: 'こんにちは、DIO!'
48+
}
49+
}
50+
51+
const i18n = new VueI18n({
52+
locale: 'en',
53+
localeMessages
54+
})
55+
56+
/* ✓ GOOD */
57+
i18n.t('hello')
58+
```

0 commit comments

Comments
 (0)