Skip to content

Commit 58a1509

Browse files
authored
Add @intlify/vue-i18n/key-format-style rule (#116)
* Add `@intlify/vue-i18n/key-format-style` rule * Update doc and meta
1 parent 3a7ea9a commit 58a1509

File tree

11 files changed

+999
-0
lines changed

11 files changed

+999
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

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

docs/rules/key-format-style.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# @intlify/vue-i18n/key-format-style
2+
3+
> enforce specific casing for localization keys
4+
5+
This rule aims to enforces specific casing for localization key names.
6+
7+
```yaml
8+
camelCaseKey: The key for this value is camel case.
9+
kebab-case-key: The key for this value is kebab case.
10+
snake_case_key: The key for this value is snake case.
11+
mixed_Case-key: Perhaps you don't want to use this casing.
12+
```
13+
14+
## :book: Rule Details
15+
16+
This rule reports localization keys other than the specific casing.
17+
Also, the following localization key definitions are reported as errors, because the casing cannot determine.
18+
19+
:-1: Examples of **incorrect** code for this rule:
20+
21+
```yaml
22+
# ✗ BAD: Use array elements.
23+
- message1
24+
- message2
25+
- message3
26+
...
27+
# ✗ BAD: Use object for key.
28+
{foo: bar}: message
29+
[1,2,3]: message
30+
```
31+
32+
## Options
33+
34+
```json
35+
{
36+
"@intlify/vue-i18n/key-format-style": ["error",
37+
"camelCase" | "kebab-case" | "snake_case",
38+
{
39+
"allowArray": false
40+
}
41+
]
42+
}
43+
```
44+
45+
- Primary Option: Select the casing you want to apply. It set to `"camelCase"` as default
46+
- `allowArray`: If `true`, allow the use of arrays. If `false`, disallow the use of arrays. It set to `false` as default.
47+
48+
:+1: Examples of **correct** code for this rule with `"camelCase"`:
49+
50+
```yaml
51+
# ✓ GOOD
52+
appTitle: I18N Management System
53+
```
54+
55+
:-1: Examples of **incorrect** code for this rule with `"camelCase"`:
56+
57+
```yaml
58+
# ✗ BAD
59+
app-title: I18N Management System
60+
app_title: I18N Management System
61+
```
62+
63+
:+1: Examples of **correct** code for this rule with `"kebab-case"`:
64+
65+
```yaml
66+
# ✓ GOOD
67+
app-title: I18N Management System
68+
```
69+
70+
:-1: Examples of **incorrect** code for this rule with `"kebab-case"`:
71+
72+
```yaml
73+
# ✗ BAD
74+
appTitle: I18N Management System
75+
app_title: I18N Management System
76+
```
77+
78+
:+1: Examples of **correct** code for this rule with `"snake_case"`:
79+
80+
```yaml
81+
# ✓ GOOD
82+
app_title: I18N Management System
83+
```
84+
85+
:-1: Examples of **incorrect** code for this rule with `"snake_case"`:
86+
87+
```yaml
88+
# ✗ BAD
89+
appTitle: I18N Management System
90+
app-title: I18N Management System
91+
```
92+
93+
:+1: Examples of **correct** code for this rule with `{"allowArray": true}`:
94+
95+
```yaml
96+
# ✓ GOOD
97+
- message1
98+
- message2
99+
- message3
100+
```

lib/rules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** DON'T EDIT THIS FILE; was created by scripts. */
2+
import keyFormatStyle from './rules/key-format-style'
23
import noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
34
import noDynamicKeys from './rules/no-dynamic-keys'
45
import noHtmlMessages from './rules/no-html-messages'
@@ -8,6 +9,7 @@ import noUnusedKeys from './rules/no-unused-keys'
89
import noVHtml from './rules/no-v-html'
910

1011
export = {
12+
'key-format-style': keyFormatStyle,
1113
'no-duplicate-keys-in-locale': noDuplicateKeysInLocale,
1214
'no-dynamic-keys': noDynamicKeys,
1315
'no-html-messages': noHtmlMessages,

0 commit comments

Comments
 (0)