Skip to content

docs: [no-unused-vars] document ignoring _ prefixed variables #8464

@johnnyreilly

Description

@johnnyreilly

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.3.3&fileType=.tsx&code=MYewdgzgLgBA%2BgSwOZhAJwKYBMCCYsCSAshgIZhQAqIMAvDFGgK4YDcMQA&eslintrc=N4KABBYEQE4PZwC5QFxkTArgUwDTkigAcBDGAZ2xlWgAFEBPI7cgYxgEsjEBaFgGw4A7RAHpSFKlHyRoRfpgDmw8jQDaBCFHpMW7LrwHDkBALozC2AB6JsQgCaq0G2VCMiUMbKzgBbX3b22PbSmnIKykIoOsxsnNx85IIiol4%2B-oHBUGYWWlj8LDSgEAC%2BIGVAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const _ignoredAndIMeantTo = true;

ESLint Config

module.exports = {
    "root": true,
    "parser": "@typescript-eslint/parser",
    "plugins": [
    "@typescript-eslint"
  ],
    "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended"
  ],
    "rules": {
  }
};

tsconfig

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

Expected Result

I'm accustomed to the TypeScript default of accepting that variables prefixed with _ are treated as though they are intentionally ignored.

Actual Result

@typescript-eslint/no-unused-vars does not make use of the same default which I find surprising, and if I may be so bold, disappointing!

It's possible to get the desired behaviour using this rule customisation:

rules: {
        "@typescript-eslint/no-unused-vars": [
            "error",
            { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
        ],
    },

I'm just curious why typescript-eslint doesn't align with the TypeScript default for similar functionality?

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions