Skip to content

Commit

Permalink
Add no-duplicate-keys-in-locale rule and change no-missing-keys r…
Browse files Browse the repository at this point in the history
…ule 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
  • Loading branch information
ota-meshi authored Aug 12, 2020
1 parent 9cf2243 commit 7614169
Show file tree
Hide file tree
Showing 33 changed files with 1,580 additions and 80 deletions.
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

0 comments on commit 7614169

Please sign in to comment.