Skip to content

Commit 7614169

Browse files
authored
Add no-duplicate-keys-in-locale rule and change no-missing-keys rule to not report if there is one matching key in each locale (#112)
* Add no-duplicate-keys-in-locale rule and change no-missing-keys rule to not report if there is one matching key in each locale. * fixed testcase
1 parent 9cf2243 commit 7614169

File tree

33 files changed

+1580
-80
lines changed

33 files changed

+1580
-80
lines changed

Diff for: docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
| Rule ID | Description | |
1818
|:--------|:------------|:---|
19+
| [@intlify/vue-i18n/<wbr>no-duplicate-keys-in-locale](./no-duplicate-keys-in-locale.html) | disallow duplicate localization keys within the same locale | |
1920
| [@intlify/vue-i18n/<wbr>no-dynamic-keys](./no-dynamic-keys.html) | disallow localization dynamic keys at localization methods | |
2021
| [@intlify/vue-i18n/<wbr>no-unused-keys](./no-unused-keys.html) | disallow unused localization keys | :black_nib: |
2122

Diff for: docs/rules/no-duplicate-keys-in-locale.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# @intlify/vue-i18n/no-duplicate-keys-in-locale
2+
3+
> disallow duplicate localization keys within the same locale
4+
5+
If you manage localization messages in multiple files, duplicate localization keys across multiple files can cause unexpected problems.
6+
7+
## :book: Rule Details
8+
9+
This rule reports duplicate localization keys within the same locale.
10+
11+
:-1: Examples of **incorrect** code for this rule:
12+
13+
locale messages:
14+
15+
- `en.1.json`
16+
17+
```json5
18+
// ✗ BAD
19+
{
20+
"hello": "Hello! DIO!", // duplicate.
21+
"hello": "Hello! DIO!", // duplicate.
22+
"good-bye": "Good bye! DIO!"
23+
}
24+
```
25+
26+
- `en.2.json`
27+
28+
```json5
29+
// ✗ BAD
30+
{
31+
"good-bye": "Good bye! DIO!" // This same key exists in `en.1.json`.
32+
}
33+
```
34+
35+
:+1: Examples of **correct** code for this rule:
36+
37+
locale messages:
38+
39+
- `en.1.json`
40+
41+
```json5
42+
// ✓ GOOD
43+
{
44+
"hello": "Hello! DIO!",
45+
"hi": "Hi! DIO!"
46+
}
47+
```
48+
49+
- `en.2.json`
50+
51+
```json5
52+
// ✓ GOOD
53+
{
54+
"good-bye": "Good bye! DIO!" // This same key exists in `en.1.json`.
55+
}
56+
```
57+
58+
## :gear: Options
59+
60+
```json
61+
{
62+
"@intlify/vue-i18n/no-duplicate-keys-in-locale": ["error", {
63+
"ignoreI18nBlock": false
64+
}]
65+
}
66+
```
67+
68+
- `ignoreI18nBlock`: If `true`, do not report key duplication between `<i18n>` blocks and other files, it set to `false` as default.

Diff for: lib/rules.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** DON'T EDIT THIS FILE; was created by scripts. */
2+
import noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
23
import noDynamicKeys from './rules/no-dynamic-keys'
34
import noHtmlMessages from './rules/no-html-messages'
45
import noMissingKeys from './rules/no-missing-keys'
@@ -7,6 +8,7 @@ import noUnusedKeys from './rules/no-unused-keys'
78
import noVHtml from './rules/no-v-html'
89

910
export = {
11+
'no-duplicate-keys-in-locale': noDuplicateKeysInLocale,
1012
'no-dynamic-keys': noDynamicKeys,
1113
'no-html-messages': noHtmlMessages,
1214
'no-missing-keys': noMissingKeys,

0 commit comments

Comments
 (0)