Skip to content

no-unused-keys false negative with . in key #260

Closed
@wolfgangwalther

Description

@wolfgangwalther

Reproduced with the unit tests in this repo, simply add a dot to one of the keys in tests/lib/rules/no-unused-keys.ts.

diff --git a/tests/lib/rules/no-unused-keys.ts b/tests/lib/rules/no-unused-keys.ts
index b923ba8..cf550b8 100644
--- a/tests/lib/rules/no-unused-keys.ts
+++ b/tests/lib/rules/no-unused-keys.ts
@@ -25,7 +25,7 @@ new RuleTester({
         "link": "@:messages.hello"
       },
       "hello_dio": "hello underscore DIO!",
-      "hello {name}": "hello {name}!"
+      "hello {name}.": "hello {name}!"
     }
     </i18n>
     <template>
@@ -36,7 +36,7 @@ new RuleTester({
     <script>
     export default {
       created () {
-        this.$i18n.t('hello {name}', { name: 'DIO' })
+        this.$i18n.t('hello {name}.', { name: 'DIO' })
         this.$t('hello')
       }
     }

This will now yield:

  398 passing (1s)
  1 failing

  1) no-unused-keys
       valid

    <i18n locale="en">
    {
      "hello": "hello world",
      "messages": {
        "hello": "hi DIO!",
        "link": "@:messages.hello"
      },
      "hello_dio": "hello underscore DIO!",
      "hello {name}.": "hello {name}!"
    }
    </i18n>
    <template>
      <div id="app">
        <p v-t="'hello_dio'">{{ $t('messages.link') }}</p>
      </div>
    </template>
    <script>
    export default {
      created () {
        this.$i18n.t('hello {name}.', { name: 'DIO' })
        this.$t('hello')
      }
    }
    </script>:

      AssertionError [ERR_ASSERTION]: Should have no errors but had 1: [
  {
    ruleId: 'no-unused-keys',
    severity: 1,
    message: `unused '["hello {name}."]' key`,
    line: 10,
    column: 7,
    nodeType: null,
    endLine: 10,
    endColumn: 22,
    suggestions: [ [Object] ]
  }
]
      + expected - actual

      -1
      +0

      at testValidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:697:20)
      at Context.<anonymous> (node_modules/eslint/lib/rule-tester/rule-tester.js:972:29)
      at processImmediate (node:internal/timers:464:21)

i.e. hello {name}. is reported as unused, even though it's not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions