Skip to content

Enhancement: [strict-boolean-expressions] allowAlwaysTrueConditions #11318

Closed as not planned
@peterHakio

Description

@peterHakio

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

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/strict-boolean-expressions/

Description

By using "strict-boolean-expressions" you are implicitly to enabling "no-unnecessary-condition" since:

const a = {}
if (a) {
  console.log("a")
}

will raise an error for "Unexpected object value in conditional. The condition is always true @typescript-eslint/strict-boolean-expressions"

I would like to have an option to not get these warnings. I practice I have a legacy code base with 1000 errors of this type if I enable it. So i would very much like to be able to enable or disable this feature. So that I can you the feature for what is meant for.

Fail

const a = {}
const b:number|null = 0
if (a) {
  console.log(b?"a":"b")
}

Pass

const replace = 'me';
const a = {}
if (a) {
  console.log("a")
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked 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-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions