Skip to content

Bug: [no-unnecessary-boolean-literal-compare] Quick Fix generates bug with instanceof #6567

@jeengbe

Description

@jeengbe

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=4.9.3&sourceType=module&code=CYUwxgNghgTiAEYD2A7AzgF3gDwNwFgAoIgSwDMAKbeE9DKFMEJM+AURhiRngF5-4ZKBDQgAlPADeAXyA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ARhw5IhTWo3yJoQ+LTIcAtsRGJ0UAO4imkcGAC+IM0A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn"
  }
}

Repro Code

declare const x;

if(x instanceof Error === false) {}

is turned into

declare const x;

if(!x instanceof Error) {}

which is semantically different:

Operator precedence: === < instanceof < !

Expected Result

Firstly, there should be an option to explicitly allow (identifier instanceof identifier === false).
I prefer it over (!(identifier instanceof identifier)).

As for the actual bug, the following code is expected (with the aforementioned example and the above option disabled):

declare const x;

if(!(x instanceof Error)) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershas prthere is a PR raised to close thispackage: 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