Skip to content

Rule proposal: No promise inside if condition #365

Closed
@joshuaavalon

Description

@joshuaavalon

This rule proposal was original created at eslint/eslint#11525. However, due to the limited information that can get from static analysis in JavaScript, this proposal is now created on TypeScript instead.

Please describe what the rule should do:

The rule should warn about putting promise in a if condition because it always resolve to true.

In most of the cases, we want to use the result of the promise instead.

What category of rule is this? (place an "X" next to just one item)

[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Enforces code style (layout)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

async function isValid() {
  return false;
}

if (isValid()) { // This is most likely an error because promise always resolves to true
  // Do work
}

Why should this rule be included in ESLint (instead of a plugin)?

This is a common mistake instead of code style. I think it should be included in ESLint to avoid this mistake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions