Skip to content

linter: expand eslint/no-constant-binary-expression to cover more cases #19847

Description

@camc314

Follow on from #19825

https://github.com/eslint/eslint/blob/46eea6d1cbed41d020cb76841ebba30710b0afd0/lib/rules/no-constant-binary-expression.js#L457-L486

Eslint currently only supports const binary conditions on ==, !=, ===, !== binary operators. We should expand this support for the full set to catch issues such as 1 > 0

  • Fails:
    • const a = 1 > 0
    • const b = 0 > 1
    • const shouldShowStreak = profile.streak ?? 0 > 1
  • Passes:
    • const a = x > 0
    • const a = foo() > 0
    • expressions with possible side effects in either operand
  • No double-report with no-constant-condition on if (1 > 0) {}.

Metadata

Metadata

Assignees

Labels

Fields

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions