Skip to content

Rule proposal: [prefer-short-falsy | prefer-short-truthy] !a instead of a == false #5075

@jguddas

Description

@jguddas

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Please close if this is considered a formatting rule or if this has to much overlap with no-unnecessary-condition.

Fail Cases

if (foo == true) {}
if (foo != false) {}
if (!!foo) {}
declare const foo: boolean; if (foo === true) {}
declare const foo: []; if (foo.length !== 0) {}
declare const foo: true | 'bar' | undefined; if (foo !== undefined) {}

/* --- */

if (foo != true) {}
if (foo == false) {}
if (!!!foo) {}
declare const foo: boolean; if (foo === false) {}
declare const foo: []; if (foo.length === 0) {}
declare const foo: true | 'bar' | undefined; if (foo == undefined) {}

/* --- */

const x = foo == true
const x = foo == false
const x = !!!foo
// …

Pass Cases

if (foo) {}
if (foo) {}
if (foo) {}
declare const foo: boolean; if (foo) {}
declare const foo: []; if (foo.length) {}
declare const foo: true | 'bar' | undefined; if (foo) {}

/* --- */

if (!foo) {}
if (!foo) {}
if (!foo) {}
declare const foo: boolean; if (!foo) {}
declare const foo: []; if (!foo.length) {}
declare const foo: true | 'bar' | undefined; if (!foo) {}

/* --- */

const x = !!foo
const x = !foo
const x = !foo

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix: user errorissue was fixed by correcting the configuration / correcting the codepackage: 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