-
-
Notifications
You must be signed in to change notification settings - Fork 794
feat(biome_js_analyze): implement noEqualsToNull rule
#8214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 73859c6 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 |
WalkthroughThis pull request introduces a new linter rule Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js (1)
1-3: Consider testing reversed order.The tests only show
foo == nullandfoo != null, but the rule implementation also handlesnull == fooandnull != foo. Adding reversed order cases would demonstrate comprehensive coverage./* should generate diagnostics */ foo == null; foo != null; +null == foo; +null != foo;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (7)
crates/biome_configuration/src/analyzer/linter/rules.rsis excluded by!**/rules.rsand included by**crates/biome_diagnostics_categories/src/categories.rsis excluded by!**/categories.rsand included by**crates/biome_js_analyze/src/lint/nursery.rsis excluded by!**/nursery.rsand included by**crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js.snapis excluded by!**/*.snapand included by**crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js.snapis excluded by!**/*.snapand included by**packages/@biomejs/backend-jsonrpc/src/workspace.tsis excluded by!**/backend-jsonrpc/src/workspace.tsand included by**packages/@biomejs/biome/configuration_schema.jsonis excluded by!**/configuration_schema.jsonand included by**
📒 Files selected for processing (6)
.changeset/legal-rice-clean.md(1 hunks)crates/biome_js_analyze/src/lint/nursery/no_equals_to_null.rs(1 hunks)crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js(1 hunks)crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js(1 hunks)crates/biome_rule_options/src/lib.rs(1 hunks)crates/biome_rule_options/src/no_equals_to_null.rs(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-21T01:10:53.036Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8171
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:125-137
Timestamp: 2025-11-21T01:10:53.036Z
Learning: In the Biome codebase, each lint rule has its own options type declaration (e.g., `type Options = RuleNameOptions`) as part of the codegen process, even if the options struct is empty or unused. This is standard practice and should not be flagged as an issue.
Applied to files:
crates/biome_rule_options/src/no_equals_to_null.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/no_equals_to_null.rs (1)
crates/biome_analyze/src/rule.rs (3)
sources(617-620)same(246-251)recommended(602-605)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: Test Node.js API
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Check JS Files
- GitHub Check: Documentation
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Check Dependencies
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: autofix
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_configuration)
🔇 Additional comments (10)
crates/biome_rule_options/src/lib.rs (1)
76-76: LGTM!Standard module declaration, correctly positioned alphabetically.
.changeset/legal-rice-clean.md (1)
1-19: LGTM!Clear, well-formatted changelog entry with accurate examples.
crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js (1)
1-3: LGTM!Appropriate test cases for strict equality comparisons with
null.crates/biome_rule_options/src/no_equals_to_null.rs (1)
1-6: LGTM!Standard options struct following the codebase pattern. Based on learnings.
crates/biome_js_analyze/src/lint/nursery/no_equals_to_null.rs (6)
1-14: LGTM!Appropriate imports for the rule implementation.
16-52: LGTM!Well-documented rule with appropriate metadata. The
Unsafefix kind correctly reflects that changing==to===can alter behaviour (e.g.,null == undefinedvsnull === undefined).
60-71: LGTM!Detection logic correctly identifies loose equality operators with
nullon either side.
73-82: LGTM!Clear diagnostic message that highlights the problematic operator.
99-106: LGTM!Helper function correctly identifies
nullliterals via pattern matching.
84-96: LGTM!Correct fix logic replacing
==with===and!=with!==. The action message clearly describes the change.
CodSpeed Performance ReportMerging #8214 will not alter performanceComparing Summary
Footnotes
|
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Summary
This PR adds the
noEqualsToNullrule, which enforces the use of===and!==for comparison withnullinstead of==or!=.Closes #8195.
Test Plan
Added:
crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.jscrates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js.snapcrates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.jscrates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js.snap