Skip to content

Add @intlify/vue-i18n/key-format-style rule #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

| Rule ID | Description | |
|:--------|:------------|:---|
| [@intlify/vue-i18n/<wbr>key-format-style](./key-format-style.html) | enforce specific casing for localization keys | |
| [@intlify/vue-i18n/<wbr>no-duplicate-keys-in-locale](./no-duplicate-keys-in-locale.html) | disallow duplicate localization keys within the same locale | |
| [@intlify/vue-i18n/<wbr>no-dynamic-keys](./no-dynamic-keys.html) | disallow localization dynamic keys at localization methods | |
| [@intlify/vue-i18n/<wbr>no-unused-keys](./no-unused-keys.html) | disallow unused localization keys | :black_nib: |
Expand Down
100 changes: 100 additions & 0 deletions docs/rules/key-format-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# @intlify/vue-i18n/key-format-style

> enforce specific casing for localization keys

This rule aims to enforces specific casing for localization key names.

```yaml
camelCaseKey: The key for this value is camel case.
kebab-case-key: The key for this value is kebab case.
snake_case_key: The key for this value is snake case.
mixed_Case-key: Perhaps you don't want to use this casing.
```

## :book: Rule Details

This rule reports localization keys other than the specific casing.
Also, the following localization key definitions are reported as errors, because the casing cannot determine.

:-1: Examples of **incorrect** code for this rule:

```yaml
# ✗ BAD: Use array elements.
- message1
- message2
- message3
...
# ✗ BAD: Use object for key.
{foo: bar}: message
[1,2,3]: message
```

## Options

```json
{
"@intlify/vue-i18n/key-format-style": ["error",
"camelCase" | "kebab-case" | "snake_case",
{
"allowArray": false
}
]
}
```

- Primary Option: Select the casing you want to apply. It set to `"camelCase"` as default
- `allowArray`: If `true`, allow the use of arrays. If `false`, disallow the use of arrays. It set to `false` as default.

:+1: Examples of **correct** code for this rule with `"camelCase"`:

```yaml
# ✓ GOOD
appTitle: I18N Management System
```

:-1: Examples of **incorrect** code for this rule with `"camelCase"`:

```yaml
# ✗ BAD
app-title: I18N Management System
app_title: I18N Management System
```

:+1: Examples of **correct** code for this rule with `"kebab-case"`:

```yaml
# ✓ GOOD
app-title: I18N Management System
```

:-1: Examples of **incorrect** code for this rule with `"kebab-case"`:

```yaml
# ✗ BAD
appTitle: I18N Management System
app_title: I18N Management System
```

:+1: Examples of **correct** code for this rule with `"snake_case"`:

```yaml
# ✓ GOOD
app_title: I18N Management System
```

:-1: Examples of **incorrect** code for this rule with `"snake_case"`:

```yaml
# ✗ BAD
appTitle: I18N Management System
app-title: I18N Management System
```

:+1: Examples of **correct** code for this rule with `{"allowArray": true}`:

```yaml
# ✓ GOOD
- message1
- message2
- message3
```
2 changes: 2 additions & 0 deletions lib/rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** DON'T EDIT THIS FILE; was created by scripts. */
import keyFormatStyle from './rules/key-format-style'
import noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
import noDynamicKeys from './rules/no-dynamic-keys'
import noHtmlMessages from './rules/no-html-messages'
Expand All @@ -8,6 +9,7 @@ import noUnusedKeys from './rules/no-unused-keys'
import noVHtml from './rules/no-v-html'

export = {
'key-format-style': keyFormatStyle,
'no-duplicate-keys-in-locale': noDuplicateKeysInLocale,
'no-dynamic-keys': noDynamicKeys,
'no-html-messages': noHtmlMessages,
Expand Down
Loading