Skip to content

fix(linter): don't simplify logic expressions with right-side boolean literals#8976

Open
FrankFMY wants to merge 3 commits intobiomejs:mainfrom
FrankFMY:fix/use-simplified-logic-expression-false-positive
Open

fix(linter): don't simplify logic expressions with right-side boolean literals#8976
FrankFMY wants to merge 3 commits intobiomejs:mainfrom
FrankFMY:fix/use-simplified-logic-expression-false-positive

Conversation

@FrankFMY
Copy link
Contributor

@FrankFMY FrankFMY commented Feb 5, 2026

AI disclosure: This PR was authored with the assistance of Claude (Anthropic). Claude helped explore the codebase, analyze the issue, implement the fix, write tests, and prepare the PR.

Summary

Fixes #8577. The useSimplifiedLogicExpression rule incorrectly suggested removing boolean literals on the right side of logical expressions.

In JavaScript, logical operators (||, &&) return one of the operand values, not a boolean. Patterns like account?.test || false are intentional boolean coercion — || false ensures the result is always true or false rather than potentially undefined.

Removed simplification logic for right-side boolean literals in both || and && branches. Left-side simplifications (true && x, false || x) remain unchanged, since JS short-circuit semantics guarantee they are always safe.

Test Plan

  • cargo test -p biome_js_analyze -- use_simplified_logic_expression — 2 tests pass
  • cargo fmt -- --check — clean
  • Updated test cases: moved boolExp || true to valid, added x || false, x && true, x && false, and the original report case account?.test || false

Docs

No documentation changes needed — the rule behavior is corrected to match its documented intent.

… literals

Fixes biomejs#8577. The `useSimplifiedLogicExpression` rule incorrectly
suggested removing boolean literals on the right side of logical
expressions (e.g. `x || false` → `x`). In JavaScript, logical operators
return operand values rather than booleans, so `x || false` serves as a
boolean coercion pattern and is not redundant.

Only simplify when the boolean literal is on the left side, where JS
short-circuit semantics guarantee correctness.
@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: 606e92c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Feb 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

This change updates the useSimplifiedLogicExpression lint rule to stop proposing simplifications when a boolean literal appears on the right-hand side of a logical expression. Redundant right-side boolean-literal handling was removed from both OR and AND branches so only left-side boolean-literal simplifications are performed. Tests were adjusted: two invalid test lines that expected right-side simplification were removed and new valid cases were added (e.g. account?.test || false, boolExp || true, x && true, x && false). A changelog entry documents the fix (issue #8577).

Suggested reviewers

  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main change: preventing simplification of logic expressions with right-side boolean literals.
Description check ✅ Passed The description clearly relates to the changeset, explaining the fix for issue #8577 and the reasoning behind removing right-side boolean literal simplifications.
Linked Issues check ✅ Passed The code changes directly address #8577 by removing the redundant simplification logic for right-side boolean literals in both OR and AND branches, with corresponding test updates.
Out of Scope Changes check ✅ Passed All changes are in scope: the rule implementation fix, test updates validating the fix, and a changelog entry documenting the issue resolution.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ematipico
Copy link
Member

@FrankFMY

In all three PRs you just did:

  • restore the PR template and fill it
  • READ the template. There are instructions for a changeset, which is mandatory
  • add AI disclosure as per requirements

@FrankFMY
Copy link
Contributor Author

FrankFMY commented Feb 6, 2026

Sorry about that! I've updated all three PRs — added changesets, restored the PR template with all sections filled in, and included AI disclosure. Should be good now.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.changeset/use-simplified-logic-expression-false-positive.md:
- Line 5: Update the changelog sentence about `|| false` in the
`useSimplifiedLogicExpression` note to accurately describe its behavior: explain
that `x || false` preserves truthy values (returns the original truthy value,
e.g., `"hello" || false` → `"hello"`) and only coerces falsy values (including
`undefined`) to `false`, rather than performing full boolean coercion to
`true`/`false`; keep the existing example `account?.test || false` and the note
that right-side `|| false` is intentional boolean-coercion-for-falsy-values
while left-side simplifications (`true && x`, `false || x`) remain unchanged.

"@biomejs/biome": patch
---

Fixed [#8577](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` are intentional boolean coercion — `|| false` ensures the result is always `true` or `false` rather than potentially `undefined`. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify the behaviour of || false.

The description states that || false ensures the result is always true or false, but this isn't quite accurate. In JavaScript, x || false returns x unchanged if it's truthy (e.g., "hello" || false returns "hello", not true), and returns false only if x is falsy. The pattern preserves truthy values whilst coercing falsy values (including undefined) to false, rather than performing full boolean coercion.

📝 Suggested clarification
-Fixed [`#8577`](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` are intentional boolean coercion — `|| false` ensures the result is always `true` or `false` rather than potentially `undefined`. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
+Fixed [`#8577`](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` intentionally coerce falsy values (including `undefined` and `null`) to `false` whilst preserving truthy values — removing `|| false` would change the expression's result. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Fixed [#8577](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` are intentional boolean coercion — `|| false` ensures the result is always `true` or `false` rather than potentially `undefined`. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
Fixed [`#8577`](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` intentionally coerce falsy values (including `undefined` and `null`) to `false` whilst preserving truthy values — removing `|| false` would change the expression's result. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
🧰 Tools
🪛 LanguageTool

[formatting] ~5-~5: Did you mean “?”
Context: ...ral is on the right side. Patterns like account?.test || false are intentional boolean c...

(MULTIPLE_PUNCTATION_MARKS_1)

🤖 Prompt for AI Agents
In @.changeset/use-simplified-logic-expression-false-positive.md at line 5,
Update the changelog sentence about `|| false` in the
`useSimplifiedLogicExpression` note to accurately describe its behavior: explain
that `x || false` preserves truthy values (returns the original truthy value,
e.g., `"hello" || false` → `"hello"`) and only coerces falsy values (including
`undefined`) to `false`, rather than performing full boolean coercion to
`true`/`false`; keep the existing example `account?.test || false` and the note
that right-side `|| false` is intentional boolean-coercion-for-falsy-values
while left-side simplifications (`true && x`, `false || x`) remain unchanged.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing FrankFMY:fix/use-simplified-logic-expression-false-positive (606e92c) with main (2cba2b3)1

Summary

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks2

Footnotes

  1. No successful run was found on main (5a341b2) during the generation of this report, so 2cba2b3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

"@biomejs/biome": patch
---

Fixed [#8577](https://github.com/biomejs/biome/issues/8577): [`useSimplifiedLogicExpression`](https://biomejs.dev/linter/rules/use-simplified-logic-expression/) no longer suggests simplifying logical expressions when the boolean literal is on the right side. Patterns like `account?.test || false` are intentional boolean coercion — `|| false` ensures the result is always `true` or `false` rather than potentially `undefined`. Left-side simplifications (`true && x`, `false || x`) remain unchanged as they are always safe due to short-circuit semantics.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changeset is an overkill. We can use a more human-like wording, simpler. Maybe just one code snippet is enough

@FrankFMY
Copy link
Contributor Author

FrankFMY commented Feb 6, 2026

Simplified the changeset — just one sentence with one code snippet now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 Incorrectly suggest to discard redundant terms (useSimplifiedLogicExpression)

2 participants