Skip to content

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

Closed
@mikededo

Description

@mikededo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix: user errorissue was fixed by correcting the configuration / correcting the codelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions