8000 Bug: [prefer-const] inconsistent `prefer-const` rule report · Issue #10426 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: [prefer-const] inconsistent prefer-const rule report #10426

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
mikededo opened this issue Nov 30, 2024 · 2 comments
Closed
4 tasks done

Bug: [prefer-const] inconsistent prefer-const rule report #10426

mikededo opened this issue Nov 30, 2024 · 2 comments
Labels
bug Something isn't working fix: user error issue was fixed by correcting the configuration / correcting the code 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 working as intended Issues that are closed as they are working as intended

Comments

@mikededo
Copy link

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

https://typescript-eslint.io/play#ts=5.6.2&fileType=.tsx&code=PQKgpgHgDg9gTgFzAEwAQEMTFQGzAjVAXlQCYBuIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQA7UQDNFoBaAYwHsA7ZAF3ShOkuknDAF8ROg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

// Using plain eslint, the following is not reported as an error

/* eslint/prefer-const: "error" */
/* exported a */ let a = 2;

// However, using this package, the same expression is reported as an error
/* exported a */ let a = 2; // 'a' is never reassigned. Use 'const' instead

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "prefer-const": "error",
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

In eslint-plugin-svelte, I am rewriting the prefer-const rule because, in Svelte, there are variable declarations that some users may prefer not to be reported as const. Since the svelte-eslint-plugin uses @typescript-eslint, I expect the base rule to exhibit the same behavior.

Actual Result

The rule report is inconsistent.

Additional Info

I've been researching for a bit and seems like typescript-eslint does not mark a Variable as eslintUsed the same way it does eslint, therefore comments such as /* exported do not set eslintUsed to true.

@mikededo mikededo 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 Nov 30, 2024
mikededo added a commit to mikededo/eslint-plugin-svelte that referenced this issue Nov 30, 2024
By adding the original rule tests, I was able to identify issues with
the rule, that had been caused because of the refactoring. Now, not only
I think the code is more readable and maintainable, but also the
behavior is as expected, and there are tests to ensure that.

There's a tests that has been skipped since it reporting a false
positive, which is dues to `@typescript-eslint`. I've reported the issue
in typescript-eslint/typescript-eslint#10426
@bradzacher
Copy link
Member

eslint playground

Looks like eslint core reports in exactly the same way.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Nov 30, 2024
@mikededo
Copy link
Author
mikededo commented Nov 30, 2024

True, now I see that it only works as expected when source type is set to script.

All good then, I did not take this into account.

@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended fix: user error issue was fixed by correcting the configuration / correcting the code and removed awaiting response Issues waiting for a reply from the OP or another party labels Nov 30, 2024
mikededo added a commit to mikededo/eslint-plugin-svelte that referenced this issue Nov 30, 2024
By adding the original rule tests, I was able to identify issues with
the rule, that had been caused because of the refactoring. Now, not only
I think the code is more readable and maintainable, but also the
behavior is as expected, and there are tests to ensure that.

There's a tests that has been skipped since it reporting a false
positive, which is dues to `@typescript-eslint`. I've reported the issue
in typescript-eslint/typescript-eslint#10426
mikededo added a commit to mikededo/eslint-plugin-svelte that referenced this issue Dec 2, 2024
By adding the original rule tests, I was able to identify issues with
the rule, that had been caused because of the refactoring. Now, not only
I think the code is more readable and maintainable, but also the
behavior is as expected, and there are tests to ensure that.

There's a tests that has been skipped since it reporting a false
positive, which is dues to `@typescript-eslint`. I've reported the issue
in typescript-eslint/typescript-eslint#10426
@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 Dec 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working fix: user error issue was fixed by correcting the configuration / correcting the code 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 working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants
0