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

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

Closed
wolfgangwalther opened this issue Nov 4, 2021 · 2 comments · Fixed by #256
Closed

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

wolfgangwalther opened this issue Nov 4, 2021 · 2 comments · Fixed by #256
Labels
Type: Bug Bug or Bug fixes

Comments

@wolfgangwalther
Copy link
Contributor

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.

@ota-meshi
Copy link
Member

Thank you for posting this issue!
Probably fix by #256.

@wolfgangwalther
Copy link
Contributor Author

Just realized the no-missing-keys rule has exactly the same problem with keys ending on a .. This results in a false positive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants