Skip to content

feat(analyze/json): implement organizePackageJson#8659

Open
arthurfiorette wants to merge 30 commits intobiomejs:nextfrom
arthurfiorette:next
Open

feat(analyze/json): implement organizePackageJson#8659
arthurfiorette wants to merge 30 commits intobiomejs:nextfrom
arthurfiorette:next

Conversation

@arthurfiorette
Copy link

@arthurfiorette arthurfiorette commented Jan 3, 2026

As the CONTRIBUTING.md says, I used Claude Code to generate an implementation plan. It helped me write part of the implementation code, some of which was hallucinated and the rest I had to fix myself many times. Finally, it ported for me all test examples from the original https://github.com/keithamus/sort-package-json test suite.

I opened this PR after #941 (comment).

First of all, I haven’t written Rust since 2023, so my code is probably not optimal or may not use recent features. Feel free to bash me.

Summary

An assist action, organizePackageJson, is being introduced (with a safe fix) to reorder a user’s package.json based on the infamous https://www.npmjs.com/package/sort-package-json package.

This PR heavily relies on the upstream JS implementation, in some places it is exactly the same code. The implementation was fairly easy, as it was mostly a translation from JS to Rust.

Before reviewing, I recommend reading sort-package-json/defaultRules.md and possibly sort-package-json/index.js to understand how the sorting is done.

All the sorting logic implemented here has a corresponding implementation in JS provided by sort-package-json. This means that Biome should be able to produce matching output to the aforementioned package. No new features were added, this PR only mimics the package’s behavior.


While implementing this, I noticed that crates/biome_json_syntax/src/generated.rs was not referencing the generated nodes_mut file, unlike other generated.rs files in other crates, and I needed JsonArrayValue::with_elements. After adding it myself, I had to remove some duplicated references in crates/biome_json_syntax/src/member_ext.rs and crates/biome_json_syntax/src/object_ext.rs, but I am not sure if that is the correct approach, a dedicated review there is needed.

Test Plan

Besides some inline tests and two basic tests, the entire test suite from https://github.com/keithamus/sort-package-json was rewritten here to ensure it is working correctly. I assume we can expect 1:1 behavior.

In the future, we could create a set of test files and run them against both Biome and sort-package-json to ensure they produce the same output.

Docs

Documentation is included inline via rustdoc, with before/after examples and references to the authoritative sort-package-json defaultRules.

@changeset-bot
Copy link

changeset-bot bot commented Jan 3, 2026

🦋 Changeset detected

Latest commit: 0c0dad9

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

@arthurfiorette arthurfiorette changed the base branch from main to next January 3, 2026 04:29
@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter A-Parser Area: parser L-JSON Language: JSON and super languages A-Diagnostic Area: diagnostocis labels Jan 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 3, 2026

Walkthrough

Adds a new assist action organizePackageJson and wires it into ActionName and the Source assist group. Implements a JSON source rule that detects and reorganises package.json members using a metadata-driven field ordering and a centralized sorter dispatcher with many transformer modules (constants, helpers, dependencies, dependencies_meta, scripts, eslint_config, prettier_config, exports). Adds tests and compatibility vectors derived from sort-package-json, a public parameterless OrganizePackageJsonOptions type, minor JSON-syntax API removals (member/object builder helpers), and a package.json guard in use_sorted_keys.

Possibly related PRs

Suggested reviewers

  • Conaclos
  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'feat(analyze/json): implement organizePackageJson' clearly and specifically summarises the main change—adding a new organisePackageJson assist action to the JSON analyser.
Description check ✅ Passed The PR description thoroughly relates to the changeset, providing context about the feature, implementation approach, test coverage, and concerns about syntax changes.

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

✨ Finishing touches
  • 📝 Generate docstrings

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: 4

🧹 Nitpick comments (9)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)

6-12: Signature inconsistency with sibling transform functions.

This transform takes an unused _root: &JsonObjectValue parameter, whereas sort_pnpm_config::transform and others take only value: &AnyJsonValue. If _root isn't needed here, consider aligning the signature for consistency. If it's reserved for future use, a brief comment would clarify intent.

Also, the catalog key is a pnpm workspace feature rather than npm — the doc link might benefit from referencing pnpm docs as well.

crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)

4-44: Consider returning None when no reordering is needed.

Unlike sibling transforms (e.g., sort_object_by_key_order returns None for single-member objects), this always rebuilds and returns Some. For consistency and to avoid unnecessary AST mutations, you might short-circuit when the input is already in the desired order.

That said, this is a minor optimisation — the current logic is correct.

crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (1)

83-129: Minor: Consider early return for single-member objects.

sort_eslint_rules always returns Some, even for objects with 0 or 1 members where no sorting is meaningful. Other sorters like sort_object_by_key_order return None in such cases to signal "no change needed". Not critical, but aligning the behaviour would be tidier.

🔎 Suggested early return
 fn sort_eslint_rules(object: &JsonObjectValue) -> Option<JsonObjectValue> {
     let members = object.json_member_list();
     let mut member_vec: Vec<JsonMember> = Vec::new();
 
     for m in (&members).into_iter().flatten() {
         member_vec.push(m.clone());
     }
+
+    if member_vec.len() < 2 {
+        return None;
+    }
 
     member_vec.sort_by(|a, b| {
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (1)

72-81: Early return on error may skip valid members.

find_member_value returns None on any member parse error, terminating the search. If a malformed member precedes the target key, the function will fail to find it. Consider using continue instead of the ? operator.

🔎 Suggested fix
 fn find_member_value(members: &JsonMemberList, key: &str) -> Option<AnyJsonValue> {
     for member in members {
-        let member = member.ok()?;
-        let name = member.name().ok()?.inner_string_text().ok()?;
-        if name.text() == key {
-            return member.value().ok();
+        let Ok(member) = member else { continue };
+        let Ok(name) = member.name().and_then(|n| n.inner_string_text()) else { continue };
+        if name.text() == key {
+            return member.value().ok();
         }
     }
     None
 }
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)

162-223: Recursive sorting may cause stack overflow on deeply nested script hierarchies.

sort_script_names calls itself recursively for nested colon-separated groups. While unlikely in practice, extremely deep hierarchies (e.g., a:b:c:d:e:f:g:...) could exhaust the stack. This is a minor edge case given typical package.json structures.

crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (1)

433-436: engineStrict should probably use FieldTransformer::None.

The engineStrict field is a boolean in package.json, not an object. Using SortObject would fail silently (returning the original value). While harmless, None would be more semantically accurate.

🔎 Suggested fix
     FieldMetadata {
         key: "engineStrict",
-        transformer: FieldTransformer::SortObject,
+        transformer: FieldTransformer::None,
     },
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)

563-563: UniqArray and UniqAndSortArray transformers are no-ops.

These transformers return the value unchanged. If array deduplication/sorting is intended, this needs implementation. If intentionally deferred, consider adding a TODO comment.

Would you like me to help implement array uniqueness and sorting logic for these transformers?


212-249: Inverted logic in check_object_keys_sorted.

The function returns true when keys are not sorted (i.e., transformation is needed), which is correct for needs_transformation. However, the function name check_object_keys_sorted suggests it returns true when sorted. Consider renaming to are_object_keys_unsorted or needs_key_sorting for clarity.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (1)

162-196: GIT_HOOKS_ORDER is duplicated.

This constant is defined identically in mod.rs (lines 289-318). Consider extracting to a shared location to avoid drift.

🔎 Suggested approach

Move GIT_HOOKS_ORDER to a shared constants module or keep it only in sorters.rs and reference it from mod.rs:

// In sorters.rs, make it pub(super)
pub(super) const GIT_HOOKS_ORDER: &[&str] = &[...];

// In mod.rs, use super::sorters::GIT_HOOKS_ORDER
📜 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 1dc8dc2 and ded348d.

⛔ Files ignored due to path filters (25)
  • Cargo.lock is excluded by !**/*.lock and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/basic/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_npm/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_yarn/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dev_engines/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_field_order/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_rules_builtin_first/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_default_last/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_nested_deep/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_types_first/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_contributors/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/husky_hooks/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/pnpm_config/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_grouped/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_lifecycle/package.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/workspaces_object/package.json.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 (44)
  • .changeset/cool-rice-change.md
  • .gitignore
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/basic/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_npm/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_yarn/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dev_engines/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_field_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_rules_builtin_first/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_default_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_nested_deep/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_types_first/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_contributors/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/husky_hooks/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/pnpm_config/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_grouped/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_lifecycle/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/workspaces_object/package.json
  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/organize_package_json.rs
🧰 Additional context used
📓 Path-based instructions (2)
**/Cargo.toml

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/Cargo.toml: Use workspace dependencies with workspace = true for internal crates in Cargo.toml
Use path dependencies for dev-dependencies in crates to avoid requiring published versions

Files:

  • crates/biome_json_analyze/Cargo.toml
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_syntax/src/object_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
🧠 Learnings (61)
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/Cargo.toml : Use workspace dependencies with `workspace = true` for internal crates in Cargo.toml

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs
📚 Learning: 2025-11-24T18:06:12.048Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace*.rs : Implement the Workspace trait in the Biome Service to manage internal state of projects, including open documents, project layout instances, and module graph instances

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_syntax/src/object_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/Cargo.toml : Use path dependencies for dev-dependencies in crates to avoid requiring published versions

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Create two new crates `biome_{language}_syntax` and `biome_{language}_factory` using `cargo new --lib` for new language parsers

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_syntax/src/generated.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/language_kind.rs : Add a new language prefix to the `LANGUAGE_PREFIXES` constant in `language_kind.rs` file

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2025-11-24T18:06:12.048Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Implement watcher tests for workspace methods in watcher.tests.rs and end-to-end tests in LSP tests

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Build debug binaries using `cargo build --bin biome` for development and triaging

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2025-11-24T18:06:12.048Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Debug the WorkspaceWatcher by starting the daemon with cargo run --bin=biome -- start and running commands such as cargo run --bin=biome -- lint --use-server <path>

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Box<[Box<str>]>` instead of `Vec<String>` for collections of strings in rule options to save memory

Applied to files:

  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/organize_package_json.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/*.jsonc : Use `.jsonc` format for test files containing multiple code snippets, where each snippet is a string in an array

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/husky_hooks/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_rules_builtin_first/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_yarn/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_field_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_lifecycle/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_contributors/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_grouped/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/pnpm_config/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/workspaces_object/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_nested_deep/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_default_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dev_engines/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_types_first/package.json
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/specs/**/options.json : Create an `options.json` file (formatted as `biome.json`) in test specification folders to apply non-default formatting options to all test files in that folder

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_rules_builtin_first/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_field_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_lifecycle/package.json
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/scripts_grouped/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/pnpm_config/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_nested_deep/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_default_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
📚 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_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_field_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_nested_deep/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dev_engines/package.json
  • .changeset/cool-rice-change.md
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/private_fields/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/* : Test snapshot output files must be placed in `tests/specs/` folder with subfolders matching the rule group and rule name

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Create specification test files in `tests/specs/<language>/` directories with one or more test files; use `cargo insta accept` or `cargo insta review` to accept/reject snapshots

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/README.md
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Rule severity should be set to `error` for hard errors, dangerous code, and accessibility issues; `warn` for possibly erroneous code; and `info` for stylistic suggestions

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/eslint_rules_builtin_first/package.json
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_syntax/src/object_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Implement `biome_deserialize::Merge` for rule option types to define how shared and user configurations are merged

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use helper functions like `map`, `filter`, and `and_then` to avoid excessive nested `if let` statements

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement custom `Queryable` and `Visitor` types for rules that require deep inspection of child nodes to avoid inefficient traversals

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/* : Create test files with `invalid` and `valid` prefixes to represent code that should and should not trigger the rule

Applied to files:

  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/fields_badges/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/prettier_overrides_last/package.json
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : No module may copy or clone data from another module in the module graph, not even behind an `Arc`

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import the `FormatNode` trait and implement it for your Node when creating formatters in biome_js_formatter

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_node_union!` macro to query multiple node types together to avoid redundant traversal passes

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Use `TypeReference` instead of `Arc` for types that reference other types to avoid stale cache issues when modules are replaced

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When formatting AST nodes, use mandatory tokens from the AST instead of hardcoding token strings (e.g., use `node.l_paren_token().format()` instead of `token("(")`)

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Do not attempt to 'fix' the code; if a token/node is known to be mandatory but is missing, return `None` instead

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/src/lib.rs : Expose a public `format_node` function that accepts formatting options and a root syntax node, returning a `FormatResult<Formatted<Context>>` with appropriate documentation

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_syntax/src/member_ext.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `ConditionalParsedSyntax` for syntax that is only valid in specific contexts (e.g., strict mode, file types, language versions) and call `or_invalid_to_bogus()` to convert to a bogus node if not supported

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/local_inference.rs : Implement local inference in dedicated modules to derive type definitions from expressions without context of surrounding scopes

Applied to files:

  • crates/biome_json_syntax/src/generated.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For tokens that are not mandatory, use helper functions instead of hardcoding

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Avoid string allocations by using `&str` or `TokenText` instead of `to_string()`

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `ParseSeparatedList` and `ParseNodeList` for parsing lists with error recovery to avoid infinite loops

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/*.ungram : Unions of nodes must start with `Any*`, e.g., `AnyHtmlAttribute`

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `p.eat(token)` for optional tokens, `p.expect(token)` for required tokens, `parse_rule(p).ok(p)` for optional nodes, and `parse_rule(p).or_add_diagnostic(p, error)` for required nodes

Applied to files:

  • crates/biome_json_syntax/src/member_ext.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Rule names should use the `use` prefix when the rule's sole intention is to mandate a single concept

Applied to files:

  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-11-21T01:10:53.059Z
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.059Z
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/organize_package_json.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : A parser struct must implement the `Parser` trait and save the token source, parser context, and optional parser options

Applied to files:

  • crates/biome_rule_options/src/organize_package_json.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types

Applied to files:

  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use the `try operator (?)` to transform `Result` types into `Option` when the `run` function returns `Option`

Applied to files:

  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `.ok()?` to transform `Result` types into `Option` or `let else` pattern to handle errors when the function returns `Vec`

Applied to files:

  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `rule_category!()` macro to refer to the diagnostic category instead of dynamically parsing its string name

Applied to files:

  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Code actions must pass `ctx.action_category(ctx.category(), ctx.group())` as the category parameter

Applied to files:

  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Parse rule functions must be prefixed with `parse_` and use the name defined in the grammar file, e.g., `parse_for_statement` or `parse_expression`

Applied to files:

  • crates/biome_configuration/src/analyzer/assist/actions.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/*.ungram : Nodes that represent a list must end with the postfix `List`, e.g., `HtmlAttributeList`, and lists are mandatory (not optional) but empty by default

Applied to files:

  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Implement error recovery in list parsing using `or_recover()` to wrap unparseable tokens in a `BOGUS_*` node and consume tokens until a recovery token is found

Applied to files:

  • crates/biome_json_syntax/src/object_ext.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : The first paragraph of rule documentation must be written in a single line to ensure proper rendering in the rules overview table

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧬 Code graph analysis (8)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (3)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (1)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (1)
  • transform (4-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (6-12)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (2)
  • sort_object_by_comparator (47-80)
  • sort_alphabetically_deep (10-13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (1)
  • transform (24-46)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
  • transform (23-51)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)
  • transform (21-25)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (6-12)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (1)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)
  • transform (21-25)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (1)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_comparator (47-80)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_configuration/src/analyzer/assist/actions.rs (2)
crates/biome_service/src/workspace_types.rs (1)
  • Self (748-748)
crates/biome_configuration/src/analyzer/mod.rs (1)
  • RuleFilter (722-722)

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 (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (2)

54-76: Add documentation for the helper function.

Consider adding a doc comment explaining the conditional exports ordering logic (types-related → others → default) to make the intent explicit for future maintainers.

🔎 Suggested documentation
+/// Sorts condition keys according to Node.js conditional exports conventions:
+/// 1. Types-related keys ("types" or "types@...")
+/// 2. Other condition keys (in insertion order)
+/// 3. "default" key
 fn sort_conditions(conditions: Vec<(String, JsonMember)>) -> Vec<(String, JsonMember)> {

102-110: Consider extracting duplicate key extraction logic.

The key extraction logic (lines 102–110, 122–130, 143–151) is repeated in all three tests. Extracting it into a helper like extract_keys(obj: &JsonObjectValue) -> Vec<String> would reduce duplication.

🔎 Suggested helper function
+    fn extract_keys(obj: &JsonObjectValue) -> Vec<String> {
+        let mut keys = Vec::new();
+        for m in &obj.json_member_list() {
+            if let Ok(member) = m
+                && let Ok(name) = member.name()
+                && let Ok(text) = name.inner_string_text()
+            {
+                keys.push(text.text().to_string());
+            }
+        }
+        keys
+    }
+
     #[test]
     fn test_condition_ordering() {
         let obj = parse_object(
             r#"{"default": "./default.js", "unknown": "./unknown.js", "types": "./types.d.ts"}"#,
         );
         let result = transform(&AnyJsonValue::from(obj.clone())).unwrap();
         let result_obj = result.as_json_object_value().unwrap();
-
-        let mut keys = Vec::new();
-        for m in &result_obj.json_member_list() {
-            if let Ok(member) = m
-                && let Ok(name) = member.name()
-                && let Ok(text) = name.inner_string_text()
-            {
-                keys.push(text.text().to_string());
-            }
-        }
-
+        let keys = extract_keys(result_obj);
         assert_eq!(keys, vec!["types", "unknown", "default"]);
     }

Apply similar changes to the other two tests.

📜 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 ded348d and 02c37ff.

📒 Files selected for processing (1)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
🧠 Learnings (5)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use helper functions like `map`, `filter`, and `and_then` to avoid excessive nested `if let` statements

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
🧬 Code graph analysis (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
  • transform (23-51)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)
  • transform (21-25)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (6-12)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (4)

1-3: LGTM!

Imports are appropriate for JSON transformation in Biome.


24-25: Nice fix!

Paths are now correctly sorted alphabetically as flagged in the previous review.


94-154: Excellent test coverage!

The three tests effectively validate paths-before-conditions, alphabetical path sorting, and condition ordering.


59-68: The current implementation is correct—insertion order is preserved within groups.

The test fixtures confirm this is the expected behaviour: all three exports test cases (exports_types_first, exports_default_last, exports_nested_deep) have no expected output changes, meaning the current code already produces the correct result. This matches sort-package-json's handling of export condition keys.

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

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (1)

4-52: Add rustdoc documentation for the public function.

Per the past review comment, this public function still needs rustdoc documentation explaining its behaviour.

🔎 Suggested rustdoc structure
+/// Transforms a JSON object representing package.json exports by reordering keys.
+///
+/// Export paths (keys starting with '.') are sorted alphabetically and placed first,
+/// followed by condition keys sorted according to Node.js conditional exports conventions
+/// (types-related keys, then others, then default).
+///
+/// Recursively transforms nested export objects.
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {
🧹 Nitpick comments (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)

4-48: Add rustdoc documentation for the public function.

For consistency with other transform functions in this module (e.g., sort_workspaces.rs), please add rustdoc explaining what this function does - specifically that it sorts Prettier config keys alphabetically whilst keeping overrides at the end.

🔎 Suggested rustdoc
+/// Sorts Prettier configuration object keys alphabetically, keeping `overrides` last.
+///
+/// This follows Prettier's convention where override rules are typically placed
+/// at the end of the configuration.
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (2)

24-46: Add rustdoc documentation for the public function.

Missing rustdoc on the public transform function. The ESLint schema link at line 6 is helpful context but should be part of proper documentation.

🔎 Suggested rustdoc
+/// Sorts ESLint configuration object according to the ESLint config schema.
+///
+/// Applies the following transformations:
+/// - Top-level keys sorted by [`ESLINT_BASE_CONFIG_PROPERTIES`] order
+/// - `env`, `globals`, `parserOptions`, `settings` sorted alphabetically
+/// - `rules` sorted by slash count (core rules first), then alphabetically
+///
+/// See <https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js>
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {

59-59: Consider simplifying the iterator.

(&members).into_iter().flatten() can be simplified to members.iter().flatten() for readability.

-    for m in (&members).into_iter().flatten() {
+    for m in members.iter().flatten() {
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (1)

292-311: Unreachable match arm.

Line 307's _ => {} arm is unreachable since all FieldTransformer variants are already handled in the preceding arms. This won't cause issues but could be removed for clarity.

         FieldTransformer::SortPnpmConfig => {
             sorted.sort();
         }
-        _ => {}
     }
📜 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 02c37ff and dac8ea4.

📒 Files selected for processing (8)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧠 Learnings (20)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : Import the `FormatNode` trait and implement it for your Node when creating formatters in biome_js_formatter

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use helper functions like `map`, `filter`, and `and_then` to avoid excessive nested `if let` statements

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Implement `biome_deserialize::Merge` for rule option types to define how shared and user configurations are merged

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : The first paragraph of rule documentation must be written in a single line to ensure proper rendering in the rules overview table

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `rule_category!()` macro to refer to the diagnostic category instead of dynamically parsing its string name

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧬 Code graph analysis (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_comparator (47-80)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (1)
  • transform (24-46)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)
  • transform (4-48)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (9-13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
  • transform (23-51)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (1)
  • transform (4-52)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)
  • transform (4-48)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (9-13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (1)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)
  • transform (21-25)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (9)
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (2)
  • get_field_index (496-500)
  • get_field_transformer (502-507)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (1)
  • transform (24-46)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (1)
  • transform (4-52)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_prettier_config.rs (1)
  • transform (4-48)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)
  • transform (9-13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)
  • transform (21-25)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
  • transform (23-51)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (13)
  • sort_alphabetically_deep (10-13)
  • transform_nested_property (274-310)
  • sort_git_hooks (195-197)
  • sort_object_by_key_order (82-122)
  • sort_alphabetically (6-8)
  • sort_people_object (125-127)
  • sort_url_object (129-131)
  • sort_bugs_object (133-135)
  • sort_directories (137-139)
  • sort_volta (141-143)
  • sort_binary (145-156)
  • uniq_array (313-341)
  • uniq_and_sort_array (344-396)
🔇 Additional comments (13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs (1)

1-13: LGTM!

Clean, minimal implementation that follows the established pattern from other sorters. The rustdoc comment provides useful context and the npm documentation link is helpful.

crates/biome_json_analyze/src/assist/source/organize_package_json/sort_eslint_config.rs (1)

83-133: LGTM on the ESLint rules sorting logic.

The slash-count-first approach sensibly groups core ESLint rules before plugin rules (e.g., no-unused-vars before react/jsx-uses-vars). Good test coverage would be beneficial here if not already present in the broader test suite.

crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (2)

6-30: Good implementation with clear documentation.

The inline comments explaining npm's locale-aware sorting vs yarn/pnpm's simple comparison are helpful. The detection logic appropriately mirrors the sort-package-json behaviour.

One note: the rustdoc could be promoted to proper /// documentation on the function signature for discoverability.


85-135: Excellent test coverage.

Tests cover npm detection via packageManager, yarn/pnpm via packageManager, pnpm via pnpm field, npm via engines, and the default case. This gives good confidence in the detection logic.

crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (3)

1-27: Well-structured enum covering all transformation types.

The FieldTransformer enum cleanly categorises all the transformation strategies. Good use of #[derive(Debug, Clone, Copy, PartialEq, Eq)] for ergonomic usage.


35-494: Comprehensive field metadata.

The field list is thorough, covering npm, yarn, pnpm, VSCode extensions, and various tooling configs. The inline comments (e.g., /* vscode */, /* yarn */) are helpful for understanding the origin of less common fields.

Consider adding a module-level rustdoc explaining that this follows sort-package-json's defaultRules.md for discoverability.


509-533: Good invariant tests.

Testing the relative ordering of key fields ensures the metadata stays consistent. The test for unknown fields returning None is a sensible edge case check.

crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (2)

54-76: LGTM on the condition sorting logic.

The types → rest → default ordering follows Node.js conditional exports conventions where types should be matched first and default acts as a fallback.


78-153: Good test coverage.

Tests for condition ordering, paths-before-conditions, and alphabetical path sorting provide confidence in the implementation.

crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (4)

26-70: Excellent rustdoc with examples.

The rule documentation clearly explains the field organisation strategy and provides helpful before/after examples. The link to sort-package-json's defaultRules.md is a good reference.


169-210: Sensible performance trade-offs.

The decision to skip deep checks for complex nested transformers (lines 193-208) is pragmatic. The comment explains the rationale well - these transformations are correct when run, so avoiding expensive validation is reasonable.


370-542: Comprehensive transformer dispatch.

The apply_field_transformer function correctly routes each transformer type to its implementation. The consistent pattern of sorter::transform(&value).unwrap_or_else(|| value.clone()) handles failures gracefully by preserving the original value.

The repetition across the object-based transformers (lines 470-532) is a bit verbose but acceptable given the different sorter functions involved.


571-620: Good unit tests for field ordering.

Tests validate the core ordering logic: known fields by canonical order, unknown fields alphabetically, and private fields (_-prefixed) last.

@arthurfiorette
Copy link
Author

After thinking a bit, no one should be using prettier and biome at the same time, at first, pairing with the original js package, I added the special sorting case for the prettier key, should I keep it or remove it?

We need to also decide if mirroring the sort-package-json is something that biome wants or if we are able to change the sorting algo to better fit our reality. Although i think it would be cool to keep it being 1:1.

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: 3

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)

4-4: Add rustdoc documentation for the public function.

This was flagged in a previous review. Please add documentation explaining the exports transformation behaviour — particularly the distinction between paths (kept in original order) and conditions (sorted with types first, default last).

🧹 Nitpick comments (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)

4-47: Add rustdoc documentation for the public function.

The coding guidelines require inline rustdoc documentation for assists. Please document what this function does, its parameters, and return value. A brief note about the "overrides" handling would be helpful.

🔎 Suggested rustdoc structure
+/// Transforms a Prettier configuration object by sorting keys alphabetically,
+/// with `overrides` kept at the end.
+///
+/// # Arguments
+///
+/// * `value` - A JSON value representing a Prettier config object
+///
+/// # Returns
+///
+/// * `Some(AnyJsonValue)` - The reordered JSON object
+/// * `None` - If the value is not a JSON object or has fewer than 2 non-overrides keys
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {

Based on coding guidelines.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)

23-56: Add rustdoc documentation for the public function.

This is a sophisticated implementation handling lifecycle scripts and sequential script detection. A rustdoc comment explaining the sorting behaviour and the rationale for skipping when npm-run-all is detected would be valuable.

🔎 Suggested rustdoc structure
+/// Sorts package.json scripts in a deterministic order.
+///
+/// Scripts are grouped and sorted with lifecycle scripts (`pre*`, `post*`) placed
+/// around their base scripts. Skips sorting when sequential scripts using
+/// `npm-run-all` with wildcards are detected to avoid breaking glob patterns.
+///
+/// Based on sort-package-json behaviour.
 pub fn transform(
     value: &AnyJsonValue,
     package_json_root: &JsonObjectValue,
 ) -> Option<AnyJsonValue> {

Based on coding guidelines.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)

47-48: Remove redundant reassignment.

Line 48 reassigns sorted_conditions to itself — this does nothing.

🔎 Proposed fix
-    // Note: paths maintain original order, only conditions sorted
-    let sorted_conditions = sorted_conditions;
-
     let mut all_members = Vec::new();
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)

68-117: Consider extracting member collection to a helper.

The pattern of collecting members into a Vec and rebuilding with separators is duplicated across multiple sorters. This could potentially be consolidated, but it's not blocking.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)

46-80: Consider adding an "already sorted" check for performance.

The function always rebuilds the object even if members are already in the correct order. For large objects, this creates unnecessary allocations. However, this is a minor optimisation and the current approach is correct.

🔎 Optional optimisation
// After sorting, check if order changed
let original_names: Vec<_> = members.iter()
    .filter_map(|m| m.ok()?.name().ok()?.inner_string_text().ok())
    .map(|t| t.text().to_string())
    .collect();
let sorted_names: Vec<_> = member_vec.iter()
    .filter_map(|m| m.name().ok()?.inner_string_text().ok())
    .map(|t| t.text().to_string())
    .collect();
if original_names == sorted_names {
    return None;
}
📜 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 dac8ea4 and eb09c77.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock and included by **
📒 Files selected for processing (14)
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs
  • crates/biome_json_analyze/tests/compat_sortpkg/README.md
  • crates/biome_json_analyze/tests/compat_sortpkg/data.json
  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/biome_json_analyze/tests/compat_sortpkg/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_json_analyze/Cargo.toml
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs
  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
🧠 Learnings (31)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs
  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Implement `biome_deserialize::Merge` for rule option types to define how shared and user configurations are merged

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use helper functions like `map`, `filter`, and `and_then` to avoid excessive nested `if let` statements

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/language.rs : Implement `TestFormatLanguage` trait in `tests/language.rs` for the formatter's test language

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/spec_tests.rs : Use the `tests_macros::gen_tests!` macro in `spec_tests.rs` to generate test functions for each specification file matching the pattern `tests/specs/<language>/**/*.<ext>`

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Create test infrastructure with `tests/specs` folder structure and `spec_test.rs`, `spec_tests.rs`, and `language.rs` files in test directories

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-11-24T18:06:12.048Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_service/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:12.048Z
Learning: Applies to crates/biome_service/src/workspace/watcher.tests.rs : Implement watcher tests for workspace methods in watcher.tests.rs and end-to-end tests in LSP tests

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/*.jsonc : Use `.jsonc` format for test files containing multiple code snippets, where each snippet is a string in an array

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
  • crates/biome_json_analyze/tests/compat_sortpkg/data.json
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/* : Create test files with `invalid` and `valid` prefixes to represent code that should and should not trigger the rule

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `.ok()?` to transform `Result` types into `Option` or `let else` pattern to handle errors when the function returns `Vec`

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg_tests.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/tests/compat_sortpkg/data.json
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement custom `Queryable` and `Visitor` types for rules that require deep inspection of child nodes to avoid inefficient traversals

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-08-20T16:24:59.781Z
Learnt from: arendjr
Repo: biomejs/biome PR: 7266
File: crates/biome_js_type_info/src/type.rs:94-102
Timestamp: 2025-08-20T16:24:59.781Z
Learning: In crates/biome_js_type_info/src/type.rs, the flattened_union_variants() method returns TypeReference instances that already have the correct module IDs applied to them. These references should be used directly with resolver.resolve_reference() without applying additional module ID transformations, as variant references may originate from nested unions in different modules.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Box<[Box<str>]>` instead of `Vec<String>` for collections of strings in rule options to save memory

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/specs/**/options.json : Create an `options.json` file (formatted as `biome.json`) in test specification folders to apply non-default formatting options to all test files in that folder

Applied to files:

  • crates/biome_json_analyze/tests/compat_sortpkg/data.json
📚 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_json_analyze/tests/compat_sortpkg/data.json
🧬 Code graph analysis (10)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
  • transform (37-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
  • transform (8-31)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)
  • transform (4-73)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)
  • transform (23-56)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/tests/compat_sortpkg_tests.rs (3)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_json_syntax/src/file_source.rs (1)
  • json (185-191)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (1)
  • action (102-121)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
  • transform (37-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
  • transform (8-31)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)
  • transform (4-48)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)
  • transform (23-56)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_comparator (47-80)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_object_by_comparator (47-80)
  • sort_alphabetically_deep (10-13)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_key_order (82-122)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (2)
  • get_field_index (496-500)
  • get_field_transformer (502-507)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs (1)
  • try_transform_field (22-137)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs (7)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (6)
  • sort_alphabetically (6-8)
  • sort_object_by_key_order (82-122)
  • sort_alphabetically_deep (10-13)
  • transform_array_with (150-189)
  • uniq_array (230-258)
  • uniq_and_sort_array (261-313)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
  • transform (37-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
  • transform (8-31)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)
  • transform (4-73)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)
  • transform (4-48)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)
  • transform (23-56)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (23)
crates/biome_json_analyze/tests/compat_sortpkg_tests.rs (1)

1-109: Solid compatibility test suite.

The test structure is well-organised with good error messages for debugging failures. The idempotency handling (using output as input when input is None) is a nice touch for testing already-sorted cases.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)

1-105: Good implementation with thorough edge case testing.

The package name extraction logic correctly handles scoped packages and version suffixes. The unit tests cover the important edge cases nicely.

crates/biome_json_analyze/tests/compat_sortpkg/data.json (1)

691-704: Minor typo in test data.

Line 692: "_": "this should still the first element" — missing "be"
Line 699: "_": "this should still the seconde element" — "seconde" should be "second"

These are test fixture strings but they do appear in output comparisons.

🔎 Suggested fix
-            "_": "this should still the first element",
+            "_": "this should still be the first element",
...
-            "_": "this should still the seconde element",
+            "_": "this should still be the second element",
⛔ Skipped due to learnings
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/tests/specs/**/*.jsonc : Use `.jsonc` format for test files containing multiple code snippets, where each snippet is a string in an array
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (2)

6-30: Good implementation of package-manager-aware sorting.

The logic correctly branches between npm's locale-aware comparison and yarn/pnpm's simple string comparison. The approximation using to_lowercase_cow() is reasonable for English locale.

One minor observation: the rustdoc comment on lines 6-10 is helpful, though it could be worth noting that this is an approximation since Rust doesn't have built-in ICU locale support.


72-83: Helper looks good.

Simple and correct linear search. For typical package.json sizes, this is perfectly adequate.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs (2)

1-14: Module organisation is clean.

Good use of submodules to separate concerns. The wildcard imports from constants::* and helpers::* are acceptable here since this is the central dispatcher that uses most items from those modules.


22-137: Well-structured dispatcher function.

The match arms follow a consistent pattern, and the delegation to specialised submodules for complex transformations (dependencies, scripts, exports, etc.) keeps this file manageable. The Option<AnyJsonValue> return type elegantly indicates whether transformation was needed.

crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (6)

18-62: Excellent rustdoc with examples.

The documentation follows biome conventions with before/after examples in doctest format. The link to upstream defaultRules.md is helpful for users wanting to understand the field ordering.

As per coding guidelines, inline rustdoc documentation is the correct approach for rules.


102-121: Verify: replace_node_discard_trivia will remove comments and formatting.

Using replace_node_discard_trivia on line 111 will discard any trivia (comments, whitespace) attached to the member list. This may be intentional for a full reorganisation, but users with inline comments in their package.json might lose them.

If preserving comments is desired, consider using replace_node instead and handling trivia preservation in the member transformation logic.


124-161: LGTM!

The is_organized function correctly checks both field ordering and per-field transformation requirements. The early return on empty fields and order mismatch is efficient.


175-216: Implementation is solid.

The use of HashMap for O(1) member lookup combined with the pre-computed sorted order is a good approach. Separator handling correctly produces n-1 commas for n elements.


235-260: Clean partitioning logic.

The three-way split (known fields by index, unknown alphabetically, private alphabetically at end) matches the documented sort-package-json behaviour. Well done.


262-311: Good test coverage for sorting logic.

The tests cover the main scenarios: known field ordering, private fields at end (alphabetically), and unknown fields in between (alphabetically). Consider adding a test for an empty input if edge cases are a concern.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/constants.rs (1)

1-99: Well-documented constants with source references.

The doc comments linking to npm documentation and noting sources (e.g., git-hooks-list package) are helpful for maintainability. The field orders appear comprehensive and match upstream conventions.

Minor note: WORKSPACES_FIELD_ORDER includes "catalog" which is a pnpm-specific field. This is fine since it won't affect npm/yarn workspaces, but might be worth a comment for clarity.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (9)

6-13: Clean API for alphabetical sorting.

sort_alphabetically delegates to the generic sort_object_by_comparator, and sort_alphabetically_deep adds recursive sorting. Good separation of concerns.


15-44: Recursive deep sorting logic is correct.

The function correctly handles the case where the top-level object was sorted (via sort_alphabetically_deep) but nested objects don't need changes – it returns Some(object.clone()) to preserve the already-sorted structure.


82-122: Key-order sorting is correct.

The logic correctly prioritises known keys by their position in key_order, with unknown keys sorted alphabetically afterwards. The O(n) position lookups are acceptable given the small size of field order arrays.


124-146: LGTM!

Clean reconstruction of the object from sorted members with correct separator handling.


150-189: Array transformation helper is well-implemented.

The function correctly handles mixed arrays (preserving non-object elements) and short-circuits when no transformations occur.


191-227: Nested property transformation is correct.

The logic correctly identifies the target property, applies the transformation, and rebuilds the object. The continue on line 211 ensures the transformed member isn't double-added.


229-258: Deduplication logic is sound.

Using HashSet::insert to detect duplicates while preserving first occurrence is the correct approach. Non-string elements are preserved, which handles edge cases gracefully.


260-313: Good dedup+sort implementation with change detection.

The function efficiently combines deduplication and sorting, with an early return if no changes are needed (line 302-304).

One consideration: non-string elements are appended at the end (line 310). Verify this matches sort-package-json behaviour if mixed arrays are a valid use case.


330-431: Comprehensive test coverage.

Tests validate both alphabetical sorting and key-order sorting with real constants. The helper function parse_json_object keeps tests concise.

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: 4

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)

4-70: Add rustdoc documentation for the public function.

The coding guidelines require inline rustdoc documentation for assists and their functions. This was flagged in a previous review but appears unaddressed.

🔎 Suggested rustdoc
+/// Transforms a JSON object representing package.json exports by reordering keys.
+///
+/// Export paths (keys starting with `.`) are placed first in their original order,
+/// followed by condition keys sorted according to Node.js conditional exports conventions
+/// (types-related keys first, then others, then default last).
+///
+/// Recursively applies the same transformation to nested export objects.
+///
+/// # Arguments
+///
+/// * `value` - A JSON value that should be a JSON object representing exports
+///
+/// # Returns
+///
+/// * `Some(AnyJsonValue)` - The reordered JSON object if changes were made
+/// * `None` - If the value is already in correct order or transformation fails
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {
🧹 Nitpick comments (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)

6-30: Add rustdoc for the public function.

The function has a good comment block but it's not in rustdoc format. Per coding guidelines, convert to proper /// documentation.

🔎 Suggested change
-/// Sort dependencies alphabetically, detecting package manager to use the appropriate comparison.
-/// npm uses locale-aware comparison, yarn and pnpm use simple string comparison.
-///
-/// npm sorting uses English locale-aware comparison (similar to JavaScript's localeCompare).
-/// This is approximated using case-insensitive comparison.
+/// Sorts dependencies alphabetically, detecting package manager to use the appropriate comparison.
+///
+/// npm uses locale-aware comparison (approximated here as case-insensitive),
+/// while yarn and pnpm use simple string comparison.
+///
+/// # Arguments
+///
+/// * `value` - The dependencies object to sort
+/// * `package_json_root` - The root package.json object for detecting package manager
+///
+/// # Returns
+///
+/// * `Some(AnyJsonValue)` - Sorted dependencies if order changed
+/// * `None` - If already sorted or not applicable
 pub fn transform(
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)

259-288: Consider documenting that non-string elements are preserved in place.

Line 278-280 keeps non-string elements in their original positions, which might not be obvious to callers expecting full deduplication.

🔎 Suggested rustdoc addition
 /// Remove duplicate string values from an array
+///
+/// String elements are deduplicated while preserving first occurrence order.
+/// Non-string elements are preserved in their original positions.
 pub fn uniq_array(array: &AnyJsonValue) -> Option<AnyJsonValue> {
📜 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 eb09c77 and 6919877.

📒 Files selected for processing (5)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
🧠 Learnings (14)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Implement `biome_deserialize::Merge` for rule option types to define how shared and user configurations are merged

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use helper functions like `map`, `filter`, and `and_then` to avoid excessive nested `if let` statements

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement custom `Queryable` and `Visitor` types for rules that require deep inspection of child nodes to avoid inefficient traversals

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/flattening.rs : Implement type flattening to simplify `TypeofExpression` variants once all component types are resolved

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs
🧬 Code graph analysis (4)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
  • transform (8-55)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)
  • transform (4-70)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
  • transform (37-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)
  • transform (23-56)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_comparator (47-80)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_key_order (82-154)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (5)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (1)
  • transform (11-30)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)
  • transform (4-69)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies_meta.rs (1)
  • transform (37-49)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/scripts.rs (1)
  • transform (23-56)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (9)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (2)

72-94: LGTM!

The sort_conditions logic correctly implements the expected ordering: types/types@ first, default last, everything else in between maintaining relative order.


96-153: LGTM!

Good test coverage for condition ordering and paths-before-conditions behaviour. The tests are clear and well-structured.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)

71-130: LGTM!

Solid test coverage for the three key scenarios: overrides moved to last, alphabetical sorting without overrides, and no-op when already sorted.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)

148-262: LGTM!

Comprehensive test coverage for base config ordering, rules sorting (builtin-first), no-op detection, and nested env sorting.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/dependencies.rs (2)

32-70: LGTM!

The package manager detection logic is sound. The default of false (line 69) ensures yarn/pnpm-like sorting when no explicit npm indicators are found, which aligns with the conservative approach mentioned in the comment about skipping filesystem checks.


85-129: LGTM!

Good coverage of the detection scenarios: npm via packageManager, yarn/pnpm via packageManager, pnpm via field, and npm via engines.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (3)

46-80: LGTM!

Solid generic comparator-based sorter with proper early return for trivial cases.


82-154: LGTM!

Good implementation with explicit change detection. Keys not in key_order are sorted alphabetically at the end, which is sensible default behaviour.


360-595: LGTM!

Comprehensive test coverage for all helper functions including edge cases like partial key matches and deep sorting.

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 (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)

313-324: Consider extracting field name collection logic.

The field name extraction pattern appears in both is_organized (lines 313-324) and organize_members (lines 367-380). Whilst this duplication is acceptable, extracting it into a helper function would reduce repetition and make the code slightly more maintainable.

🔎 Example helper function
fn extract_field_names(members: &JsonMemberList) -> Vec<String> {
    members
        .iter()
        .filter_map(|member| {
            member
                .ok()?
                .name()
                .ok()?
                .inner_string_text()
                .ok()
                .map(|text| text.text().to_string())
        })
        .collect()
}

Also applies to: 367-380


438-438: Minor optimisation opportunity in field sorting.

Line 438 calls get_field_index again in the sort key closure after already filtering known_fields by is_some() on line 431. The unwrap_or(usize::MAX) is necessary but could be avoided by caching indices during the partitioning phase. Current implementation is correct, just slightly inefficient.

📜 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 6919877 and 177bc2a.

📒 Files selected for processing (1)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧠 Learnings (10)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : The first paragraph of rule documentation must be written in a single line to ensure proper rendering in the rules overview table

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
🧬 Code graph analysis (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (2)
  • get_field_index (496-500)
  • get_field_transformer (502-507)
🔇 Additional comments (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)

252-310: LGTM! Well-structured rule implementation.

The rule correctly implements the required workflow: file path check, organisation validation, diagnostic emission, and safe mutation. Proper use of early returns and the mutation API.


450-499: Good test coverage for the sorting logic.

The three tests effectively verify the three-tier sorting behaviour (known, unknown, private fields) with clear assertions.

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

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)

7-8: Add rustdoc for the public function.

The URL comment on line 7 references the ESLint schema but doesn't document the function itself. Per coding guidelines, public functions should have inline rustdoc documentation.

🔎 Suggested rustdoc
-/// https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js
+/// Transforms a JSON object representing ESLint configuration by reordering fields.
+///
+/// Sorts base config properties according to the ESLint schema order, then sorts
+/// nested fields: `env`, `globals`, `parserOptions`, and `settings` alphabetically,
+/// and `rules` by slash-depth (builtins first) then alphabetically.
+///
+/// See: <https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js>
+///
+/// # Returns
+///
+/// * `Some(AnyJsonValue)` - The transformed config if any changes were made
+/// * `None` - If already in correct order
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {
🧹 Nitpick comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)

50-84: Missing change detection before rebuild.

Unlike sort_object_by_key_order (lines 130-155), this function doesn't check if the sorted order actually differs from the original before calling rebuild_object_from_members. This could cause unnecessary object reconstruction when keys are already sorted.

🔎 Suggested fix
 pub fn sort_object_by_comparator<F>(
     object: &JsonObjectValue,
     comparator: F,
 ) -> Option<JsonObjectValue>
 where
     F: Fn(&String, &String) -> Ordering,
 {
     let members = object.json_member_list();
     let mut member_vec: Vec<JsonMember> = members.iter().filter_map(|m| m.ok()).collect();

     if member_vec.len() < 2 {
         return None;
     }

+    // Capture original order for comparison
+    let original_keys: Vec<String> = member_vec
+        .iter()
+        .filter_map(|m| {
+            m.name()
+                .ok()?
+                .inner_string_text()
+                .ok()
+                .map(|t| t.text().to_string())
+        })
+        .collect();
+
     member_vec.sort_by(|a, b| {
         // ... existing sorting logic ...
     });

+    // Check if order changed
+    let sorted_keys: Vec<String> = member_vec
+        .iter()
+        .filter_map(|m| {
+            m.name()
+                .ok()?
+                .inner_string_text()
+                .ok()
+                .map(|t| t.text().to_string())
+        })
+        .collect();
+
+    if original_keys == sorted_keys {
+        return None;
+    }
+
     rebuild_object_from_members(object, member_vec)
 }
📜 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 177bc2a and 9299d1f.

📒 Files selected for processing (4)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
🧠 Learnings (13)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Invalid code snippets in rule documentation must emit exactly one diagnostic

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
🧬 Code graph analysis (3)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (2)
  • get_field_index (496-500)
  • get_field_transformer (502-507)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs (1)
  • try_transform_field (22-137)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
  • sort_alphabetically (6-8)
  • sort_object_by_key_order (86-158)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (17)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (4)

11-55: LGTM!

The early return issue from prior review has been properly addressed. Change tracking is now correctly propagated through all nested field transformations, and the function only returns Some when actual changes occur.


57-94: LGTM!

The helper correctly transforms a specific field within an object and tracks whether any change occurred. The tuple return pattern cleanly separates the result from the change flag.


96-162: LGTM!

The past review concern about always returning Some has been addressed. The function now correctly captures the original order, compares after sorting, and returns None when no reordering is needed.


178-304: LGTM!

Good test coverage including transformation cases and no-op scenarios. The tests validate base config ordering, rules sorting (builtins first), and nested field sorting.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (7)

10-17: LGTM!

The past review concern has been addressed. The function now correctly handles the case where the parent object has fewer than 2 keys by falling back to the original object before deep-sorting nested objects. The deep_sorted_opt.or(sorted_opt) pattern ensures we return a result if either level changed.


19-48: LGTM!

The recursive deep-sorting logic correctly processes nested objects and tracks changes.


86-158: LGTM!

Correctly implements key-order sorting with proper change detection. Unknown keys are sorted alphabetically at the end, which aligns with the expected behaviour.


184-223: LGTM!

The array transformation helper correctly processes object elements and only returns a new array when changes occur.


225-261: LGTM!

Correctly transforms a nested property and tracks changes.


263-347: LGTM!

Both uniq_array and uniq_and_sort_array correctly handle deduplication with proper change detection. Non-string elements are preserved as-is.


535-593: LGTM!

Good edge-case coverage. These tests specifically validate that nested objects are sorted even when the parent has only one key or is already sorted—addressing the concerns from prior review.

crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (6)

18-256: LGTM!

Excellent rustdoc documentation following the coding guidelines. The comprehensive table format clearly documents each field's sorting rules. The examples demonstrate both invalid and valid states effectively.


258-316: LGTM!

The rule implementation correctly checks for package.json files, determines if organisation is needed, and applies the fix via mutation. The diagnostic is appropriately scoped to the object range.


318-355: LGTM!

Two-phase check correctly identifies both out-of-order fields and fields requiring transformation.


369-410: LGTM!

The organisation logic correctly builds a sorted member list with field transformations applied. Using a HashMap for member lookup is efficient.


429-454: LGTM!

Field ordering correctly partitions into known (by index), unknown (alphabetical), and private (alphabetical, last). This matches the documented sort-package-json behaviour.


456-505: LGTM!

Unit tests adequately cover the field ordering logic including known, unknown, and private field scenarios.

@arthurfiorette
Copy link
Author

PR is ready for review

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: 5

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (1)

7-55: Add rustdoc for public transform function.

The public transform function still lacks rustdoc documentation. Per coding guidelines, inline rustdoc is required for public functions.

🔎 Suggested rustdoc
-/// https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js
+/// Transforms an ESLint configuration object by reordering fields.
+///
+/// Sorts base config properties according to ESLint schema order, then processes
+/// nested fields: `env`, `globals`, `parserOptions`, and `settings` (alphabetically),
+/// and `rules` (built-in rules first, then by slash depth and alphabetically).
+///
+/// See: <https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js>
+///
+/// # Returns
+///
+/// * `Some` - If any reordering occurred
+/// * `None` - If already correctly ordered
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {

Based on coding guidelines.

🧹 Nitpick comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)

179-218: Consider adding rustdoc for pub(super) function.

While transform_array_with has module-restricted visibility, rustdoc would improve internal documentation clarity.

🔎 Suggested rustdoc
+/// Transforms object elements within a JSON array using the provided function.
+///
+/// Only processes array elements that are JSON objects. Non-object elements are preserved unchanged.
+///
+/// # Returns
+///
+/// * `Some` - If any transformations were applied
+/// * `None` - If no changes occurred or value is not an array
 pub(super) fn transform_array_with<F>(array: &AnyJsonValue, transform_fn: F) -> Option<AnyJsonValue>
📜 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 9299d1f and 896ac49.

📒 Files selected for processing (3)
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
🧠 Learnings (16)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : When porting rules from other linters, use `sources` metadata with `RuleSource::Eslint().same()` for identical behavior or `.inspired()` for different behavior

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(deny_unknown_fields)]` to rule option structs to enforce strict configuration validation

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
📚 Learning: 2025-12-22T09:27:13.161Z
Learnt from: ematipico
Repo: biomejs/biome PR: 8537
File: crates/biome_js_analyze/src/lint/nursery/no_leaked_render.rs:167-210
Timestamp: 2025-12-22T09:27:13.161Z
Learning: In crates/biome_analyze/**/*analyze/src/**/*.rs, the `fix_kind` field in `declare_lint_rule!` should only be specified when the rule implements the `action` function. Rules that only emit diagnostics without providing code fixes should not include `fix_kind` in their metadata.

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Use `declare_lint_rule!` macro with a `version` field set to `next` for new rules

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Implement the `action` function and add `fix_kind` metadata to the rule macro if the rule provides code actions

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : New rules must be placed inside the `nursery` group before promotion to other groups

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule option types must derive `Deserializable`, `Serialize`, `Deserialize`, and optionally `JsonSchema` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Deprecated rules must include a `deprecated` field in the `declare_lint_rule!` macro with an explanation of what rule to use instead

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Rule options must be defined in the `biome_rule_options` crate with a file named after the rule

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : The first paragraph of rule documentation must be written in a single line to ensure proper rendering in the rules overview table

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/**/*_analyze/**/src/lint/**/*.rs : Invalid code snippets in rule documentation must emit exactly one diagnostic

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Implement `biome_deserialize::Merge` for rule option types to define how shared and user configurations are merged

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Store type data in linear vectors instead of using recursive data structures with `Arc` for improved data locality and performance

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs
🧬 Code graph analysis (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs (2)
  • get_field_index (496-500)
  • get_field_transformer (502-507)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/mod.rs (1)
  • try_transform_field (22-137)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (2)
crates/biome_js_analyze/src/assist/source/use_sorted_interface_members.rs (1)
  • comparator (125-127)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (6)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/helpers.rs (1)

359-654: Excellent test coverage!

The test suite comprehensively covers sorting variants, including edge cases for nested object sorting that address the previous review concern. Tests verify behaviour when parent objects have single keys or are already sorted, ensuring nested objects are still processed.

crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/eslint_config.rs (2)

96-157: Previous concern resolved.

The function now correctly checks whether the order actually changed (lines 137-143) before rebuilding, returning None when already sorted. This addresses the earlier review feedback.


159-285: Good test coverage.

Tests verify base config ordering, rules sorting (built-in first), and the corrected behaviour when already sorted (returning None).

crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (3)

18-256: Exemplary rustdoc.

The rule documentation is comprehensive, well-structured, and includes doctest examples. The typo from the previous review has been corrected at line 187.


318-459: Helper functions are well-structured.

The helper functions correctly implement the organization logic:

  • is_organized checks both field order and content transformations
  • organize_members applies both reordering and field-specific transformations
  • get_sorted_field_order properly categorizes fields (known, unknown, private with _ prefix)

461-510: Test coverage for helper logic is adequate.

Tests verify the field ordering logic with edge cases (private fields, unknown fields, mixed scenarios).

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 5, 2026

Merging this PR will not alter performance

✅ 19 untouched benchmarks
⏩ 136 skipped benchmarks1


Comparing arthurfiorette:next (0c0dad9) with next (730fb06)

Open in CodSpeed

Footnotes

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

♻️ Duplicate comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)

4-4: Add rustdoc documentation for this public function.

Per coding guidelines, public functions should have inline rustdoc. Document the purpose (sorts Prettier config keys alphabetically, overrides last), parameter, and return semantics.

🧹 Nitpick comments (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (2)

24-26: Minor: could early-exit for the "overrides only" edge case.

When keys_with_members.is_empty() and there's only an overrides key, the function continues to line 44 before returning None. Consider extending the guard:

if keys_with_members.is_empty() || (keys_with_members.len() < 2 && overrides_member.is_none()) {
    return None;
}

This is purely a micro-optimisation—current behaviour is correct.


86-127: Tests look solid; consider adding edge-case coverage.

Current tests cover the happy paths well. You might add tests for:

  • Single non-override key + overrides (e.g., {"overrides": [], "semi": true} → should return sorted).
  • Object with only overrides → should return None.

These would strengthen confidence in the early-return logic.

📜 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 896ac49 and 87eee55.

⛔ Files ignored due to path filters (2)
  • 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_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.rs: Use inline rustdoc documentation for rules, assists, and their options
Use the dbg!() macro for debugging output in Rust tests and code
Use doc tests (doctest) format with code blocks in rustdoc comments; ensure assertions pass in tests

Files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🧠 Learnings (3)
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Apply `#[serde(rename_all = "camelCase")]` to rule option structs to match JSON configuration naming convention

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
📚 Learning: 2026-01-02T14:58:16.536Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2026-01-02T14:58:16.536Z
Learning: Applies to crates/biome_analyze/biome_rule_options/lib/**/*.rs : Use `Option<_>` wrapper for rule option fields to enable proper merging of configurations

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
📚 Learning: 2025-12-21T21:15:03.796Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-21T21:15:03.796Z
Learning: Applies to **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs
🧬 Code graph analysis (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (2)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/exports.rs (1)
  • transform (4-70)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
🔇 Additional comments (1)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters/prettier_config.rs (1)

50-67: LGTM!

The separator handling correctly avoids a trailing comma—either by appending overrides as the final element or by popping the last separator. Clean approach.

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.

Thanks for the PR! I appreciate the thorough compatibility tests.

There's a lot of String allocations for things that could either be a &str, or TokenText. I didn't mark all of them for the sake of brevity.

The name doesn't follow our rule naming guidelines. organizeImports also does not follow the rules, but its an exception.

Comment on lines +112 to +121
let a_name = a
.name()
.ok()
.and_then(|n| n.inner_string_text().ok())
.map(|t| t.text().to_string());
let b_name = b
.name()
.ok()
.and_then(|n| n.inner_string_text().ok())
.map(|t| t.text().to_string());
Copy link
Contributor

Choose a reason for hiding this comment

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

.to_string() allocates a string. You should be able to get a TokenText instead which lets you avoid the heap allocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

move the mod.rs to ../organize_package_json.rs. our codegen infra relies on the module being in the source/ directory.

Comment on lines +397 to +398
let field_names = extract_field_names(members);
let sorted_names = get_sorted_field_order(&field_names);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of allocating a bunch of strings, sorting the strings, and then applying, couldn't you just sort the members in the list directly?

Comment on lines +434 to +447
fn get_sorted_field_order(field_names: &[String]) -> Vec<String> {
let mut known_fields = Vec::new();
let mut unknown_fields = Vec::new();
let mut private_fields = Vec::new();

for name in field_names {
if name.starts_with('_') {
private_fields.push(name.clone());
} else if get_field_index(name).is_some() {
known_fields.push(name.clone());
} else {
unknown_fields.push(name.clone());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might make sense to create a wrapper type that implements a custom PartialOrd impl.

Comment on lines +126 to +131
static RUN_S_REGEXP: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"(?:^|[\s&;<>|(])(?:run-s|npm-run-all2? .*(?:--sequential|--serial|-s))(?:$|[\s&;<>|)])",
)
.unwrap()
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the regex truly necessary? We try to avoid regex because of the perf impact.

Comment on lines +496 to +507
pub fn get_field_index(field_name: &str) -> Option<usize> {
PACKAGE_JSON_FIELDS
.iter()
.position(|metadata| metadata.key == field_name)
}

pub fn get_field_transformer(field_name: &str) -> FieldTransformer {
PACKAGE_JSON_FIELDS
.iter()
.find(|metadata| metadata.key == field_name)
.map_or(FieldTransformer::None, |metadata| metadata.transformer)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These lookups are O(n) every time they're called. You could turn PACKAGE_JSON_FIELDS into a LazyLock<HashMap<'static str, FieldMetadata>> and add the sort index to FieldMetadata. It might even make more sense to just have it be a simple match instead of a hashmap, since it doesn't need to be dynamic.

If that doesn't work out, this could still be improved by having the lookups use a binary search, and sorting PACKAGE_JSON_FIELDS to make that work.

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't typically how we do tests for our rules, but I'm not entirely opposed to it. We already have a mechanism for doing snapshot tests loading cases from json in our test utils crate. We could also set this up like our prettier tests instead, where we have .prettier-snap, and we emit a snapshot of the difference or no snapshot if no difference.

So either:

  • snapshot diff tests
  • make this more generic, and put it in biome_test_utils

@Conaclos
Copy link
Member

Conaclos commented Jan 5, 2026

Thanks for your contribution! very welcomed :)

I am a bit concerned about the possible conflict with useSortedKeys. I wonder if we should incorporate your implementation as an option of useSortedKeys.

Also, a similar feature has recently been incorporated to oxfmt. We could take a look to the order they implemented: it seems to be refined. They have also an extended suite of tests.

@arthurfiorette
Copy link
Author

Hey @dyc3 and @Conaclos, what could I call this rule instead? I went with organizePackageJson to keep similar to organizeImports...

Thanks for the deep review, next weekend I'll be fixing it!

@ematipico
Copy link
Member

ematipico commented Jan 6, 2026

useSortedPackageJson

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-Parser Area: parser A-Project Area: project L-JSON Language: JSON and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants