Skip to content

[no-unsafe-negation] Duplicates TypeScript's TS2358, TS2360, and TS2365 errors (?) #1146

Closed
@glen-84

Description

@glen-84

Repro

{
  "rules": {
    "no-unsafe-negation": ["error", { "enforceForOrderingRelations": true }],
  }
}
const a = 1;
const b = 2;
let foo;

if (!a < b) {
    /**/
}

while (!a > b) {
    /**/
}

foo = !a <= b;

foo = !a >= b;

const myObject = {};
const key = "";
const Ctor = Function;

if (!key in myObject) {
    // operator precedence makes it equivalent to (!key) in object
    // and type conversion makes it equivalent to (key ? "false" : "true") in object
}

if (!myObject instanceof Ctor) {
    // operator precedence makes it equivalent to (!obj) instanceof Ctor
    // and it equivalent to always false since boolean values are not objects.
}

Expected Result

TS errors only.

Actual Result

TS and ESLint errors.

image

Additional Info

enforceForOrderingRelations is actually off by default, so technically TS2365 is probably not being duplicated.

Versions

package version
@typescript-eslint/eslint-plugin 2.5.0
@typescript-eslint/parser 2.5.0
TypeScript 3.5.3
ESLint 6.6.0
node 12.13.0
npm 6.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeThis change will require a new major version to be releasedpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginrecommended-rulesDiscussion about recommended rule sets

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions