Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [no-unused-vars] varsIgnorePattern is broken on v8 beta #9383

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

Closed
4 tasks done
ottomated opened this issue Jun 18, 2024 · 8 comments
Closed
4 tasks done

Bug: [no-unused-vars] varsIgnorePattern is broken on v8 beta #9383

ottomated opened this issue Jun 18, 2024 · 8 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ottomated
Copy link

ottomated commented Jun 18, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

CodeSandbox (your playground does not support v8)

Repro Code

try {
  throw new Error();
} catch (_) {}

ESLint Config

import js from "@eslint/js";
import ts from "typescript-eslint";

export default ts.config(
  js.configs.recommended,
  ...ts.configs.recommended,
  {
    rules: {
      "@typescript-eslint/no-unused-vars": [
        "warn",
        {
          argsIgnorePattern: "^_",
          varsIgnorePattern: "^_",
        },
      ],
    },
  },
);

tsconfig

No response

Expected Result

I expect no errors or warnings to be printed.

Actual Result

warning  '_' is defined but never used. Allowed unused vars must match /^_/u  @typescript-eslint/no-unused-vars

Additional Info

Using version 8.0.0-alpha.30 with eslint 9.5.0.

@ottomated ottomated added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 18, 2024
@ottomated
Copy link
Author

Realizing now that this works with caughtErrorsIgnorePattern, but it appears that the lint message is reporting the pattern from varsIgnorePattern incorrectly.

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Jun 18, 2024

Realizing now that this works with caughtErrorsIgnorePattern, but it appears that the lint message is reporting the pattern from varsIgnorePattern incorrectly.

@ottomated This was a helpful detail!

This does seem wrong; I should think the description for a caught variable would say something like "caught variables" instead of "args" to distinguish it from caught variables (and avoid this very confusion).

Note that this same behavior currently exists in the base rule:
https://github.com/eslint/eslint/blob/97ce45bcdaf2320efd59bb7974e0c8e073aab672/lib/rules/no-unused-vars.js#L168-L171

And in our fork:

if (
defType === TSESLint.Scope.DefinitionType.CatchClause &&
options.caughtErrorsIgnorePattern
) {
type = 'args';
pattern = options.caughtErrorsIgnorePattern.toString();

So, maybe this should be reported in eslint first/instead/as well? Interested what @bradzacher thinks is best here.

@bradzacher
Copy link
Member

bradzacher commented Jun 18, 2024

#9324 / #9325 / #9326 will sync us with upstream proper.

@bradzacher
Copy link
Member

But yes - this is likely a bug upstream as the label is wrong. We can sync it as part of the above PRs.

@kirkwaiblinger
Copy link
Member

Actually, looking closer, it is not just that the label is wrong - the conditions in that if/elseif chain are wrong, too. When no caughtErrorsIgnorePattern is present, it continues through the else ifs to the defType !== TSESLint.Scope.DefinitionType.Parameter && options.varsIgnorePattern condition, and provides a message about unused vars... which is irrelevant. It should just have no message about "Allowed unused {{type}} must match {{pattern}}" in that case, since there isn't any pattern to match. Will file upstream.

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Jun 19, 2024

the conditions in that if/elseif chain are wrong, too.

Ah! But they're fixed in #9324 🎉 So the main bug being reported here will indeed already be solved once the PRs Brad mentioned get merged 🙂

Will file upstream.

Only applies to the labelling as "arg" instead of "caught error" now.

@kirkwaiblinger
Copy link
Member

eslint/eslint#18606

@JoshuaKGoldberg
Copy link
Member

Sounds like this is a dup that will be fixed by existing issues -> PRs. Great! Thanks all!

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@JoshuaKGoldberg JoshuaKGoldberg added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels Jun 28, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jul 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants