From 56b1761f4a50927a2abb55bf0e70b7667277afa5 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Tue, 20 Feb 2024 09:57:57 +0900 Subject: [PATCH] test: fix test cases --- CHANGELOG.md | 4 +- tests/lib/rules/no-missing-keys.ts | 7 - tests/lib/rules/no-unused-keys.ts | 899 ++++++++++++++++++++++++++++- 3 files changed, 886 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed208da9..1f568d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.0.0-next.2 +# @intlify/eslint-plugin-vue-i18n ## 3.0.0-next.6 @@ -28,6 +28,8 @@ - [#413](https://github.com/intlify/eslint-plugin-vue-i18n/pull/413) [`0fadd81`](https://github.com/intlify/eslint-plugin-vue-i18n/commit/0fadd81f0551c380514744573b4c3fdac9b9d4fa) Thanks [@dargmuesli](https://github.com/dargmuesli)! - Pin `@intlify` dependencies to tag `beta` to try to prevent renovate from downgrading. +## 3.0.0-next.2 + ### Patch Changes - [#394](https://github.com/intlify/eslint-plugin-vue-i18n/pull/394) [`3774e88`](https://github.com/intlify/eslint-plugin-vue-i18n/commit/3774e88ba06335efe2112594d0c92b8ac4e5d242) Thanks [@wolfgangwalther](https://github.com/wolfgangwalther)! - fix: no-missing-keys rule reports false positive with trailing dot diff --git a/tests/lib/rules/no-missing-keys.ts b/tests/lib/rules/no-missing-keys.ts index 24e8e57d..1b2e5d6e 100644 --- a/tests/lib/rules/no-missing-keys.ts +++ b/tests/lib/rules/no-missing-keys.ts @@ -297,13 +297,6 @@ tester.run('no-missing-keys', rule as never, { `'messages.missing' does not exist in localization message resources` ] }, - { - // nested missing - code: `$t('messages.missing')`, - errors: [ - `'messages.missing' does not exist in localization message resources` - ] - }, { // @ts-expect-error -- Type error for eslint v9 languageOptions: { diff --git a/tests/lib/rules/no-unused-keys.ts b/tests/lib/rules/no-unused-keys.ts index ca53f4e4..2664109f 100644 --- a/tests/lib/rules/no-unused-keys.ts +++ b/tests/lib/rules/no-unused-keys.ts @@ -1045,17 +1045,688 @@ ${' '.repeat(6)} } ] }, - "unused 'flow-block.unuse1' key", - "unused 'flow-block.unuse2' key", - "unused 'flow-seq[0]' key", - "unused 'flow-seq[1]' key", - "unused 'seq-unuse[0]' key", - "unused '{foo:bar}' key", - "unused 'hi' key", - "unused '[0]' key", - "unused 'hello' key", - "unused 'unuse' key", - "unused 'array-unuse[0]' key" + { + message: "unused 'flow-block.unuse1' key", + suggestions: [ + { + desc: "Remove the 'flow-block.unuse1' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'flow-block.unuse2' key", + suggestions: [ + { + desc: "Remove the 'flow-block.unuse2' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'flow-seq[0]' key", + suggestions: [ + { + desc: "Remove the 'flow-seq[0]' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'flow-seq[1]' key", + suggestions: [ + { + desc: "Remove the 'flow-seq[1]' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse" + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'seq-unuse[0]' key", + suggestions: [ + { + desc: "Remove the 'seq-unuse[0]' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: [] + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused '{foo:bar}' key", + suggestions: [ + { + desc: "Remove the '{foo:bar}' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + +${' '.repeat(6)} + flow-block: {} + flow-seq: [] + seq-unuse: [] + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'hi' key", + suggestions: [ + { + desc: "Remove the 'hi' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + {} + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused '[0]' key", + suggestions: [ + { + desc: "Remove the '[0]' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + [] + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + } + ] + }, + { + message: "unused 'hello' key", + suggestions: [ + { + desc: "Remove the 'hello' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + unuse: "unuse", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + {, + "array-unuse": [ + ] + } + + ` + } + ] + }, + { + message: "unused 'unuse' key", + suggestions: [ + { + desc: "Remove the 'unuse' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + "array-unuse": [ + "unuse" + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + {, + "array-unuse": [ + ] + } + + ` + } + ] + }, + { + message: "unused 'array-unuse[0]' key", + suggestions: [ + { + desc: "Remove the 'array-unuse[0]' key.", + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + { + hello: "hi DIO!", + unuse: "unuse", + "array-unuse": [ + ] + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + hello: "hi DIO!" + flow-block: { + "unuse1": "unuse", + "unuse2": "unuse" + } + flow-seq: [ + "unuse", + "unuse", + ] + seq-unuse: + - "unuse" + ? {foo:bar} + : value + + + hi: "你好" + + + - "하이" + + + {, + "array-unuse": [ + ] + } + + ` + } + ] + } ] }, { @@ -1112,7 +1783,23 @@ ${' '.repeat(6)} `, - errors: [`unused '["[{foo: bar}]"].foo' key`] + errors: [ + { + message: `unused '["[{foo: bar}]"].foo' key`, + suggestions: [ + { + desc: `Remove the '["[{foo: bar}]"].foo' key.`, + output: ` + + ? [{foo: bar}] + : {} + + + ` + } + ] + } + ] }, { filename: 'test.vue', @@ -1142,12 +1829,102 @@ ${' '.repeat(6)} { message: "unused 'bar.not_ignore' key", line: 8, - column: 9 + column: 9, + suggestions: [ + { + desc: "Remove the 'bar.not_ignore' key.", + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest", + "ignore": "ignore" + }, + "ignore": "ignore", + "not_ignore": "not_ignore", + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest" + } + } + + ` + } + ] }, { message: "unused 'not_ignore' key", line: 11, - column: 7 + column: 7, + suggestions: [ + { + desc: "Remove the 'not_ignore' key.", + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest", + "ignore": "ignore", + "not_ignore": "not_ignore", + }, + "ignore": "ignore" + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest" + } + } + + ` + } + ] } ] }, @@ -1179,12 +1956,102 @@ ${' '.repeat(6)} { message: "unused 'bar.no_hit_pattern_foo' key", line: 8, - column: 9 + column: 9, + suggestions: [ + { + desc: "Remove the 'bar.no_hit_pattern_foo' key.", + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest", + "ptn_foo": "ignore" + }, + "ptn_bar": "ignore", + "no_hit_pattern_bar": "not_ignore" + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest" + } + } + + ` + } + ] }, { message: "unused 'no_hit_pattern_bar' key", line: 11, - column: 7 + column: 7, + suggestions: [ + { + desc: "Remove the 'no_hit_pattern_bar' key.", + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest", + "ptn_foo": "ignore", + "no_hit_pattern_foo": "not_ignore" + }, + "ptn_bar": "ignore" + } + + ` + }, + { + desc: 'Remove all unused keys.', + output: ` + + { + "foo": "foo", + "bar": { + "nest": "nest" + } + } + + ` + } + ] } ] },