Skip to content
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

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

Merged
merged 2 commits into from
Aug 12, 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>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: |

68 changes: 68 additions & 0 deletions docs/rules/no-duplicate-keys-in-locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# @intlify/vue-i18n/no-duplicate-keys-in-locale

> disallow duplicate localization keys within the same locale

If you manage localization messages in multiple files, duplicate localization keys across multiple files can cause unexpected problems.

## :book: Rule Details

This rule reports duplicate localization keys within the same locale.

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

locale messages:

- `en.1.json`

```json5
// ✗ BAD
{
"hello": "Hello! DIO!", // duplicate.
"hello": "Hello! DIO!", // duplicate.
"good-bye": "Good bye! DIO!"
}
```

- `en.2.json`

```json5
// ✗ BAD
{
"good-bye": "Good bye! DIO!" // This same key exists in `en.1.json`.
}
```

:+1: Examples of **correct** code for this rule:

locale messages:

- `en.1.json`

```json5
// ✓ GOOD
{
"hello": "Hello! DIO!",
"hi": "Hi! DIO!"
}
```

- `en.2.json`

```json5
// ✓ GOOD
{
"good-bye": "Good bye! DIO!" // This same key exists in `en.1.json`.
}
```

## :gear: Options

```json
{
"@intlify/vue-i18n/no-duplicate-keys-in-locale": ["error", {
"ignoreI18nBlock": false
}]
}
```

- `ignoreI18nBlock`: If `true`, do not report key duplication between `<i18n>` blocks and other files, it set to `false` as default.
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 noDuplicateKeysInLocale from './rules/no-duplicate-keys-in-locale'
import noDynamicKeys from './rules/no-dynamic-keys'
import noHtmlMessages from './rules/no-html-messages'
import noMissingKeys from './rules/no-missing-keys'
Expand All @@ -7,6 +8,7 @@ import noUnusedKeys from './rules/no-unused-keys'
import noVHtml from './rules/no-v-html'

export = {
'no-duplicate-keys-in-locale': noDuplicateKeysInLocale,
'no-dynamic-keys': noDynamicKeys,
'no-html-messages': noHtmlMessages,
'no-missing-keys': noMissingKeys,
Expand Down
Loading