Skip to content

feat(biome-js-analyze): add useConsistentBooleanProps rule#8120

Open
vladimir-ivanov wants to merge 11 commits intobiomejs:mainfrom
vladimir-ivanov:feat/use_consistent_boolean_props-2
Open

feat(biome-js-analyze): add useConsistentBooleanProps rule#8120
vladimir-ivanov wants to merge 11 commits intobiomejs:mainfrom
vladimir-ivanov:feat/use_consistent_boolean_props-2

Conversation

@vladimir-ivanov
Copy link
Contributor

@vladimir-ivanov vladimir-ivanov commented Nov 16, 2025

Summary

Added useConsistentBooleanProps rule.
This rule enforces consistent usage of boolean props in JSX.
Depending on the selected mode, the rule reports when boolean props are written implicitly or explicitly in a way that does not match the configuration.
• mode: "implicit" — encourages <input disabled />
• mode: "explicit" — encourages <input disabled={true} />

Examples

Valid (mode: implicit)

<input disabled />;

Valid (mode: explicit)

<input disabled={true} />;

closes #5095

@changeset-bot
Copy link

changeset-bot bot commented Nov 16, 2025

🦋 Changeset detected

Latest commit: 13e833c

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 16, 2025
@vladimir-ivanov vladimir-ivanov changed the title feat(biome-js-analyze): Add useConsistentBooleanProps rule feat(biome-js-analyze): add useConsistentBooleanProps rule Nov 16, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

Walkthrough

Adds a nursery JSX lint rule useConsistentBooleanProps that enforces consistent boolean prop syntax with two modes: Implicit and Explicit. Implements diagnostics and safe fixes to either remove {true} or insert ={true} as needed, exposes a helper is_true_literal, introduces configuration types (UseConsistentBooleanPropsOptions, BooleanPropMode) and exports the new options module, and adds test cases and changeset metadata for both modes.

Possibly related PRs

Suggested reviewers

  • dyc3

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: adding the useConsistentBooleanProps lint rule to biome-js-analyze.
Description check ✅ Passed The description accurately explains the new rule's functionality, supported modes, and provides valid examples for each mode configuration.
Linked Issues check ✅ Passed The PR implements the core requirement from #5095 but with an enhanced, configurable approach. The new useConsistentBooleanProps rule supports both implicit and explicit modes, effectively addressing the issue's request for enforcing implicit booleans while providing flexibility.
Out of Scope Changes check ✅ Passed All changes are in scope: the new rule implementation, options configuration, comprehensive test cases, and supporting infrastructure. No unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 (2)
crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.jsx (1)

1-3: Consider adding more test cases.

The current coverage handles comments well but could be more comprehensive. Consider adding:

  • Multiple implicit props on the same element
  • Nested components with implicit props
  • Implicit props in fragments

Example additions:

<input disabled readOnly required />;
<MyComponent disabled someProp />;
<>
  <input disabled />
  <button accept />
</>;
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)

207-213: Use AST node type checking instead of text comparison.

The current implementation uses text_trimmed() == "true", which could theoretically match non-boolean-literal expressions with that text. A more robust approach would verify it's actually a JsBooleanLiteralExpression with value true.

-fn is_true_literal(jsx_attribute_initializer_clause: &JsxAttributeInitializerClause) -> bool {
-    if let Ok(expr) = jsx_attribute_initializer_clause.value()
-        && let Some(lit_expr) = expr.as_jsx_expression_attribute_value()
-        && let Ok(expression) = lit_expr.expression()
-    {
-        return expression.syntax().text_trimmed() == "true";
-    }
-
-    false
+fn is_true_literal(jsx_attribute_initializer_clause: &JsxAttributeInitializerClause) -> bool {
+    if let Ok(expr) = jsx_attribute_initializer_clause.value()
+        && let Some(lit_expr) = expr.as_jsx_expression_attribute_value()
+        && let Ok(expression) = lit_expr.expression()
+        && let Some(lit) = expression.as_any_js_literal_expression()
+        && let Some(bool_lit) = lit.as_js_boolean_literal_expression()
+    {
+        return bool_lit.value_token().ok().map_or(false, |t| t.text_trimmed() == "true");
+    }
+    false
 }
📜 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 47d940e and 743e32b.

⛔ Files ignored due to path filters (9)
  • 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/useConsistentBooleanProps/invalidExplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx.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 (12)
  • .changeset/use-consistent-boolean-props.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json (1 hunks)
  • crates/biome_rule_options/src/lib.rs (1 hunks)
  • crates/biome_rule_options/src/use_consistent_boolean_props.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.

Applied to files:

  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)
crates/biome_analyze/src/rule.rs (2)
  • sources (617-620)
  • inspired (254-259)
⏰ 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). (14)
  • GitHub Check: Check JS Files
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: autofix
🔇 Additional comments (11)
crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx (1)

1-41: Test coverage looks solid.

The test cases comprehensively cover explicit boolean prop scenarios including edge cases with falsy values, expressions, and nested structures. Well done.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json (1)

1-15: Configuration looks correct.

The JSON structure properly configures the rule for explicit mode testing.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json (1)

1-15: Configuration looks correct.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json (1)

1-15: Configuration looks correct.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json (1)

1-15: Configuration looks correct.

.changeset/use-consistent-boolean-props.md (1)

1-30: Documentation is clear and helpful.

The changeset provides a concise explanation with good examples illustrating both modes.

crates/biome_rule_options/src/lib.rs (1)

1-1: Module declaration verified as auto-generated.

Line 273 shows pub mod use_consistent_boolean_props; in alphabetically-ordered sequence with other rule options modules. This matches the pattern produced by the register_analyzer_rule_options() function in xtask/codegen/src/generate_analyzer_rule_options.rs, which automatically registers new modules in lib.rs. The corresponding rule options file exists at the expected location. No manual editing required.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx (1)

1-3: Test cases cover the essentials.

The three test cases appropriately exercise explicit {true} usage (which should be flagged in implicit mode) and include comments in different positions to validate trivia handling.

crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx (1)

1-25: Comprehensive test coverage for valid implicit mode cases.

The test cases appropriately cover bare attributes (line 3) and various non-{true} values (falsy values, strings, numbers, expressions) that should not trigger diagnostics in implicit mode.

crates/biome_rule_options/src/use_consistent_boolean_props.rs (1)

1-22: Well-structured options module.

The options structure follows Biome conventions with appropriate derives for serialisation, schema generation, and the Implicit default mode aligns with the rule documentation.

crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)

142-148: No issues found—trivia preservation is working correctly.

The test snapshots confirm that trailing comments and whitespace are being preserved. For example, test case 2 shows accept /** some comment */ being correctly transformed to accept={true} /** some comment */. The trivia handling in lines 142–148 is sound.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 16, 2025

CodSpeed Performance Report

Merging #8120 will not alter performance

Comparing vladimir-ivanov:feat/use_consistent_boolean_props-2 (13e833c) with main (bb7a15c)1

Summary

✅ 58 untouched
⏩ 95 skipped2

Footnotes

  1. No successful run was found on main (e9f068e) during the generation of this report, so bb7a15c 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.

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 (2)
crates/biome_rule_options/src/use_consistent_boolean_props.rs (2)

4-9: Consider adding documentation.

The struct is correctly implemented with appropriate derives and serde attributes. deny_unknown_fields is a nice touch for catching configuration errors. However, consider adding doc comments to explain the purpose and usage of this public API.

Example:

+/// Configuration options for the `useConsistentBooleanProps` rule.
+///
+/// Controls whether boolean props in JSX should use implicit (`<Foo bar />`)
+/// or explicit (`<Foo bar={true} />`) syntax.
 #[derive(Default, Clone, Debug, Deserialize, Deserializable, Merge, Eq, PartialEq, Serialize)]
 #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 #[serde(rename_all = "camelCase", deny_unknown_fields, default)]
 pub struct UseConsistentBooleanPropsOptions {
+    /// The boolean prop mode to enforce.
     pub mode: BooleanPropMode,
 }

11-18: Good choice of default; consider adding docs.

Implicit as the default aligns well with the linked issue's preference. The derives and serde configuration are spot on. Documentation comments would help users understand the behaviour of each mode.

Example:

+/// Determines how boolean props in JSX should be formatted.
 #[derive(Default, Clone, Debug, Deserialize, Deserializable, Merge, Eq, PartialEq, Serialize)]
 #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
 #[serde(rename_all = "camelCase")]
 pub enum BooleanPropMode {
+    /// Enforce implicit boolean props: `<Foo bar />` (default).
     #[default]
     Implicit,
+    /// Enforce explicit boolean props: `<Foo bar={true} />`.
     Explicit,
 }
📜 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 743e32b and 03a9d43.

⛔ Files ignored due to path filters (3)
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs 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 (1)
  • crates/biome_rule_options/src/use_consistent_boolean_props.rs (1 hunks)
⏰ 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: End-to-end tests
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Check JS Files
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
🔇 Additional comments (1)
crates/biome_rule_options/src/use_consistent_boolean_props.rs (1)

1-2: LGTM!

The imports are correct and all are used in the derives below.

@vladimir-ivanov vladimir-ivanov force-pushed the feat/use_consistent_boolean_props-2 branch from 03a9d43 to 43dc1f9 Compare November 16, 2025 17:25
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

📜 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 03a9d43 and 43dc1f9.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)
crates/biome_analyze/src/rule.rs (2)
  • sources (617-620)
  • inspired (254-259)
⏰ 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). (14)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: End-to-end tests
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Check JS Files
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: autofix

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_rule_options/src/use_consistent_boolean_props.rs (1)

7-18: Consider adding documentation for the public API.

Adding doc comments would help users understand the purpose of each mode:

+/// Configuration options for the useConsistentBooleanProps rule.
 pub struct UseConsistentBooleanPropsOptions {
+    /// The style to enforce for boolean props.
     pub mode: BooleanPropMode,
 }

+/// The style to use for boolean props in JSX.
 pub enum BooleanPropMode {
+    /// Enforce implicit boolean props (e.g., `<input disabled />`).
     #[default]
     Implicit,
+    /// Enforce explicit boolean props (e.g., `<input disabled={true} />`).
     Explicit,
 }
📜 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 43dc1f9 and 68af37e.

⛔ Files ignored due to path filters (3)
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs 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 (1)
  • crates/biome_rule_options/src/use_consistent_boolean_props.rs (1 hunks)
⏰ 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). (10)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test Node.js API
  • GitHub Check: Check JS Files
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_js_parser)
🔇 Additional comments (2)
crates/biome_rule_options/src/use_consistent_boolean_props.rs (2)

1-18: Clean implementation!

The options module is well-structured and follows Biome's patterns. The derives are comprehensive, the default behaviour (Implicit mode) aligns with the PR objectives, and the schema feature gating is consistent.


14-18: Ensure the old noImplicitBoolean rule is properly deprecated before release.

The verification confirms both rules currently coexist—noImplicitBoolean remains active in the style group without deprecation markers, whilst useConsistentBooleanProps is added to nursery. This creates overlapping functionality and user confusion.

Before merging, either:

  • Add deprecation notices to NoImplicitBoolean with migration guidance pointing to useConsistentBooleanProps
  • Remove NoImplicitBoolean entirely if this is a replacement

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

We should deprecate the old rule (maybe in the next minor?) and provide a migrator for it in biome_migrate. That should probably go in a new PR against next, or we could move this PR onto next and include it here.

@vladimir-ivanov vladimir-ivanov force-pushed the feat/use_consistent_boolean_props-2 branch from 68af37e to 68b8444 Compare November 20, 2025 21:06
@vladimir-ivanov
Copy link
Contributor Author

We should deprecate the old rule (maybe in the next minor?) and provide a migrator for it in biome_migrate. That should probably go in a new PR against next, or we could move this PR onto next and include it here.

let me know if any action is required for this pr? @dyc3

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

🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)

112-121: Consider enhancing diagnostic clarity per the rule pillars.

The current message states what should be done but could better explain the context. With action() implemented, you need at least two messages: one describing the issue and one suggesting the fix. The current single message somewhat covers both, but consider making it clearer—for example, stating that the current form doesn't match the configured mode.

Based on learnings

📜 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 68af37e and 68b8444.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.jsx.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
📚 Learning: 2025-10-25T07:02:26.457Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7856
File: .changeset/yellow-crews-guess.md:1-5
Timestamp: 2025-10-25T07:02:26.457Z
Learning: The Biome documentation website uses kebab-case URL slugs for rule pages (e.g., `/linter/rules/no-continue/`), not camelCase.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)
crates/biome_analyze/src/rule.rs (2)
  • sources (617-620)
  • inspired (254-259)
🔇 Additional comments (2)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (2)

92-106: LGTM!

The detection logic correctly identifies violations in both modes and properly delegates to the is_true_literal helper.


196-207: Well-structured helper function.

This correctly checks for {true} literals by examining the trimmed expression content. Make sure to use it consistently throughout (see comment on lines 163-172).

@dyc3
Copy link
Contributor

dyc3 commented Nov 20, 2025

Do you want to do the deprecation in this PR or a new one on next?

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

🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)

199-210: Consider a more type-safe check.

The string comparison works, but checking the AST node type first would be more robust and avoid any ambiguity.

You could refactor to:

fn is_true_literal(jsx_attribute_initializer_clause: &JsxAttributeInitializerClause) -> bool {
    if let Ok(expr) = jsx_attribute_initializer_clause.value()
        && let Some(lit_expr) = expr.as_jsx_expression_attribute_value()
        && let Ok(expression) = lit_expr.expression()
        && let Some(literal) = expression.as_any_js_literal_expression()
        && let Some(bool_literal) = literal.as_js_boolean_literal_expression()
    {
        return bool_literal.value_token().is_ok_and(|t| t.text_trimmed() == "true");
    }
    false
}

This ensures you're checking a boolean literal node before examining its text.

📜 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 dc8cfcd and 097919d.

⛔ Files ignored due to path filters (2)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
📚 Learning: 2025-10-25T07:02:26.457Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7856
File: .changeset/yellow-crews-guess.md:1-5
Timestamp: 2025-10-25T07:02:26.457Z
Learning: The Biome documentation website uses kebab-case URL slugs for rule pages (e.g., `/linter/rules/no-continue/`), not camelCase.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)
crates/biome_analyze/src/rule.rs (1)
  • inspired (254-259)
🔇 Additional comments (5)
crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx (1)

1-4: LGTM! Good test coverage.

The test cases appropriately cover explicit boolean props with various whitespace and comment placements that should be flagged in implicit mode.

crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (4)

17-84: LGTM! Clear documentation and appropriate metadata.

The rule declaration provides clear examples for both modes, and the metadata is correctly configured for a nursery rule.


92-107: LGTM! Logic correctly identifies violations.

The run method properly uses the is_true_literal helper and correctly flags violations for both modes.


109-129: LGTM! Diagnostic messages are clear and actionable.

The messages appropriately describe the issue and what the user should do.


138-160: LGTM! Explicit mode fix correctly adds ={true}.

The implementation properly preserves the existing attribute node whilst adding the initialiser, avoiding trivia issues.

@vladimir-ivanov vladimir-ivanov force-pushed the feat/use_consistent_boolean_props-2 branch from 3362a95 to d830f02 Compare November 20, 2025 22:34
@vladimir-ivanov vladimir-ivanov requested a review from dyc3 November 20, 2025 22:34
@vladimir-ivanov
Copy link
Contributor Author

please review again

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 (3)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (2)

152-161: Preserve attribute trivia when dropping the initialiser

In the implicit branch you rebuild the attribute from just the name:

let next_attr = make::jsx_attribute(jsx_attribute.name().ok()?).build();

This risks losing any trivia/comments that were attached to the original attribute outside the {true} expression. To mirror the explicit branch and better preserve formatting and comments, you can clear the initialiser in place instead:

-                if let Some(init) = jsx_attribute.initializer()
-                    && is_true_literal(&init)
-                {
-                    // Remove initializer
-                    let next_attr = make::jsx_attribute(jsx_attribute.name().ok()?).build();
-                    mutation_has_changes = true;
-                    mutation.replace_node(jsx_attribute.clone(), next_attr);
-                }
+                if let Some(init) = jsx_attribute.initializer()
+                    && is_true_literal(&init)
+                {
+                    // Remove initializer while preserving attribute trivia
+                    let next_attr = jsx_attribute.clone().with_initializer(None);
+                    mutation_has_changes = true;
+                    mutation.replace_node(jsx_attribute.clone(), next_attr);
+                }

That keeps the existing node and just drops the {true} part, which should be safer for trivia.


170-173: Tiny nit: make the fix hint match the actual code (={true})

The explicit‑mode action message currently says:

"Add `= {true}` to the attribute."

but the fixer produces ={true} without a space. For consistency with the rule docs and the produced code, consider:

-                        "Add `= {true}` to the attribute."
+                        "Add `={true}` to the attribute."
crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx (1)

1-25: Add an explicit false case and clarify the heading comment

This spec is great for non‑true values, but it is missing the canonical disabled={false} example that the issue description calls out as valid for implicit mode. The heading comment also says “Explicit true/false” while only exercising the implicit form.

Something along these lines would tighten it up:

-// Explicit true/false
-<input disabled />;
+// Implicit true and explicit false
+<input disabled />;
+<input disabled={false} />;

That both documents the intent and gives you direct coverage that {false} remains untouched in implicit mode.

📜 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 3362a95 and d830f02.

⛔ Files ignored due to path filters (9)
  • 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/useConsistentBooleanProps/invalidExplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx.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 (12)
  • .changeset/use-consistent-boolean-props.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.jsx (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json (1 hunks)
  • crates/biome_rule_options/src/lib.rs (1 hunks)
  • crates/biome_rule_options/src/use_consistent_boolean_props.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.options.json
🚧 Files skipped from review as they are similar to previous changes (8)
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validImplicit.options.json
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.options.json
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidImplicit.jsx
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.jsx
  • .changeset/use-consistent-boolean-props.md
  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/validExplicit.jsx
  • crates/biome_rule_options/src/use_consistent_boolean_props.rs
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json
📚 Learning: 2025-09-25T12:32:59.003Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7593
File: crates/biome_service/src/workspace/server.rs:1306-1306
Timestamp: 2025-09-25T12:32:59.003Z
Learning: In the biomejs/biome project, do not flag compilation errors during code review as they are handled by the existing test infrastructure and CI. Focus on other code quality aspects instead.

Applied to files:

  • crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json
  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
📚 Learning: 2025-10-25T07:02:26.457Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7856
File: .changeset/yellow-crews-guess.md:1-5
Timestamp: 2025-10-25T07:02:26.457Z
Learning: The Biome documentation website uses kebab-case URL slugs for rule pages (e.g., `/linter/rules/no-continue/`), not camelCase.

Applied to files:

  • crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs
🧬 Code graph analysis (1)
crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)
crates/biome_analyze/src/rule.rs (3)
  • sources (617-620)
  • inspired (254-259)
  • 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: Check JS Files
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: Test Node.js API
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
🔇 Additional comments (2)
crates/biome_js_analyze/tests/specs/nursery/useConsistentBooleanProps/invalidExplicit.options.json (1)

1-15: Config wiring for explicit mode looks good

Schema path and linter.rules.nursery.useConsistentBooleanProps options match the intended "explicit" mode and align with the other spec option files.

crates/biome_js_analyze/src/lint/nursery/use_consistent_boolean_props.rs (1)

76-204: Overall rule shape and is_true_literal helper look solid

Nice separation of concerns: run only signals on the exact {true} / missing‑initialiser cases, diagnostic tailors the message by mode, and action mirrors that with safe, mode‑specific fixes using the shared is_true_literal helper. This aligns well with the linked ESLint rule behaviour and the Biome rule pillars.

@dyc3
Copy link
Contributor

dyc3 commented Nov 21, 2025

Review for what? You haven't answered my question.

@vladimir-ivanov vladimir-ivanov force-pushed the feat/use_consistent_boolean_props-2 branch from 3c77d40 to 2892987 Compare November 21, 2025 07:27
@dyc3
Copy link
Contributor

dyc3 commented Nov 21, 2025

Tell you what, @vladimir-ivanov let's just go ahead and do the one PR.

  • Point this PR to next
  • Deprecate noImplicitBoolean
  • Create a migrator in biome_migrate to migrate users of noImplicitBoolean over to useConsistentBooleanProps with the correct options set.
  • Update the changeset to mention the deprecation and the rule replacement.

@ematipico
Copy link
Member

The RuleDiagnostic type has a deprecate function (or similar) that allows you to add a rationale, the infrastructure does the rest

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

Labels

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.

📎 Implement useImplicitBoolean

4 participants