Skip to content

Rule Change: support more binary operators #20573

Description

@camc314

What rule do you want to change?

no-constant-binary-expressions

What change do you want to make?

Generate more warnings

How do you think the change should be implemented?

A new default behavior

Example code

const shouldShowStreak = profile.streak ?? 0 > 1

Currently doesn't report an error, despite 0 > 1 always evaluating to false. Since this is a constant binary expression, I think makes semi

What does the rule currently do for this code?

Reports no error:

https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgbm8tY29uc3RhbnQtY29uZGl0aW9uOiBcImVycm9yXCIsIFxuICAgICAgICAgbm8tY29uc3RhbnQtYmluYXJ5LWV4cHJlc3Npb246IFwiZXJyb3JcIiAqL1xuXG5jb25zdCBzaG91bGRTaG93U3RyZWFrID0gcHJvZmlsZS5zdHJlYWsgPz8gMCA+IDE7XG5cbmNvbnN0IGFsd2F5c1RydWUgPSAxID4gMDtcblxuXG5pZiAodHJ1ZSkge31cbmNvbnN0IHggPSAxID09PSAyOyIsIm9wdGlvbnMiOnsicnVsZXMiOnt9LCJsYW5ndWFnZU9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hRmVhdHVyZXMiOnt9fX19fQ==

What will the rule do after it's changed?

Report an error on code such as

const shouldShowStreak = profile.streak ?? 0 > 1

Explaining that 0 > 1 is a binary expression that always evaluates to the same value.

Participation

  • I am willing to submit a pull request to implement this change.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

Related:

oxc-project/oxc#19825
oxc-project/oxc#19847

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions