feat(lint): add ignoreBooleanCoercion option to useNullishCoalescing#10595
feat(lint): add ignoreBooleanCoercion option to useNullishCoalescing#10595pkallos wants to merge 1 commit into
Conversation
- suppresses || and ||= when the value is boolean-coerced by an enclosing Boolean() call - walks out through parens and logical parents, so chained and && cases inside Boolean() are covered too - partially addresses biomejs#9232, follows on from biomejs#9974
🦋 Changeset detectedLatest commit: b6d02d6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (7)
WalkthroughThis PR adds a new Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
adds the
ignoreBooleanCoercionoption touseNullishCoalescing, partially addressing #9232. this follows on from #9974 which addedignoreMixedLogicalExpressions.when enabled,
||and||=are not reported if the value is boolean-coerced by an enclosingBoolean()call, since coalescing on falsy values is intentional in that spot. i kept the scope to just this one option so it stays easy to review. the remaining options from #9232 (ignorePrimitives,ignoreIfStatements) can come as separate PRs.the detection mirrors how the merged mixed-logical code reads: a small typed helper that scans ancestors, skips parens and logical parents (both
||and&&, since the coerced value still flows into the call), and then checks the first other ancestor is the argument of aBoolean()call.Test Plan
the spec snapshots cover this, but if you want to check it by hand:
biome.jsonenabling the rule and option:{ "linter": { "rules": { "nursery": { "useNullishCoalescing": { "level": "error", "options": { "ignoreBooleanCoercion": true } } } } } }test.ts:run
biome lint test.ts. onlyr4andr5should report.flip the option to
falseand re-run. nowr1,r2,r3should report too.things worth poking at for coverage:
||=insideBoolean()(e.g.Boolean(x ||= y)) should be quiet when the option is onBooleancallee (identity(...)) should still report, to confirm it's keyed on theBooleanname and not just "any call"new Boolean(a || b)still reports. i think that's right since it constructs an object rather than coercing, but worth a sanity checkDocs
the option is documented in the rule's rustdoc with invalid/valid examples and validated by
rules_check. no website PR needed while the rule is in nursery.