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
AI acknowledgment
Additional comments
Related:
oxc-project/oxc#19825
oxc-project/oxc#19847
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
Currently doesn't report an error, despite
0 > 1always evaluating to false. Since this is a constant binary expression, I think makes semiWhat 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
Explaining that
0 > 1is a binary expression that always evaluates to the same value.Participation
AI acknowledgment
Additional comments
Related:
oxc-project/oxc#19825
oxc-project/oxc#19847