Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hirokiokada77
Copy link
Contributor

Summary

This PR adds the noEqualsToNull rule, which enforces the use of === and !== for comparison with null instead of == or !=.

Closes #8195.

Test Plan

Added:

  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js
  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js.snap
  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js
  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js.snap

@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2025

🦋 Changeset detected

Latest commit: 73859c6

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-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Nov 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Walkthrough

This pull request introduces a new linter rule noEqualsToNull that detects loose equality comparisons (== and !=) with null literals and suggests strict equality alternatives (=== and !==). The implementation includes the core lint rule, configuration options, test cases covering both invalid and valid patterns, and a changelog entry documenting the addition.

Suggested labels

A-Project, A-Linter, L-JavaScript, A-Diagnostic

Suggested reviewers

  • dyc3
  • ematipico

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: implementing a new noEqualsToNull linter rule.
Description check ✅ Passed The description is directly related to the changeset, explaining what the rule does and referencing the closed issue.
Linked Issues check ✅ Passed The PR successfully implements the noEqualsToNull rule as requested in issue #8195, porting ESLint's no-eq-null rule.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the noEqualsToNull rule with necessary test files and rule options.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

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: 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 == null and foo != null, but the rule implementation also handles null == foo and null != 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

📥 Commits

Reviewing files that changed from the base of the PR and between 182ecdc and a8116b0.

⛔ Files ignored due to path filters (7)
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_js_analyze/src/lint/nursery.rs is excluded by !**/nursery.rs and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/invalid.js.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/noEqualsToNull/valid.js.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and 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 Unsafe fix kind correctly reflects that changing == to === can alter behaviour (e.g., null == undefined vs null === undefined).


60-71: LGTM!

Detection logic correctly identifies loose equality operators with null on either side.


73-82: LGTM!

Clear diagnostic message that highlights the problematic operator.


99-106: LGTM!

Helper function correctly identifies null literals via pattern matching.


84-96: LGTM!

Correct fix logic replacing == with === and != with !==. The action message clearly describes the change.

@github-actions github-actions bot added the A-CLI Area: CLI label Nov 22, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 22, 2025

CodSpeed Performance Report

Merging #8214 will not alter performance

Comparing hirokiokada77:feat/no-equals-to-null (73859c6) with main (182ecdc)

Summary

✅ 58 untouched
⏩ 95 skipped1

Footnotes

  1. 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.

@dyc3 dyc3 added this pull request to the merge queue Nov 22, 2025
Merged via the queue into biomejs:main with commit 68c052e Nov 22, 2025
20 checks passed
@github-actions github-actions bot mentioned this pull request Nov 22, 2025
@hirokiokada77 hirokiokada77 deleted the feat/no-equals-to-null branch November 22, 2025 16:37
@github-actions github-actions bot mentioned this pull request Nov 25, 2025
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 port no-eq-null from eslint

2 participants