Skip to content

feat(analyze/json): implement organizePackageJson (Broken)#8657

Closed
arthurfiorette wants to merge 16 commits intobiomejs:mainfrom
arthurfiorette:main
Closed

feat(analyze/json): implement organizePackageJson (Broken)#8657
arthurfiorette wants to merge 16 commits intobiomejs:mainfrom
arthurfiorette:main

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: 023dce8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JSON Language: JSON and super languages A-Diagnostic Area: diagnostocis labels Jan 3, 2026
@github-actions github-actions bot added A-Project Area: project A-Parser Area: parser labels Jan 3, 2026
@arthurfiorette arthurfiorette marked this pull request as ready for review January 3, 2026 04:18
@arthurfiorette arthurfiorette changed the base branch from main to next January 3, 2026 04:19
@arthurfiorette arthurfiorette changed the base branch from next to main January 3, 2026 04:19
@arthurfiorette arthurfiorette changed the base branch from main to next January 3, 2026 04:19
@arthurfiorette arthurfiorette changed the base branch from next to main January 3, 2026 04:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 3, 2026

Walkthrough

This PR introduces a new organizePackageJson assist action that automatically organizes package.json files according to sort-package-json conventions. It adds the core rule implementation with comprehensive sorting logic for various package.json sections (dependencies, scripts, exports, ESLint/Prettier configs, workspaces, etc.), supporting different package managers (npm, yarn, pnpm) and field transformers. The change also updates the configuration layer to register the new action and includes extensive test fixtures covering multiple field-ordering scenarios.

Possibly related PRs

  • PR #7799: Modifies the UseSortedKeys rule in the same JSON analyser module; this PR adds package.json-specific logic to that rule as well, so they interact with the same codebase.

Suggested labels

A-Tooling

Suggested reviewers

  • ematipico
  • dyc3
  • arendjr

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: implementing a new assist action named organizePackageJson for JSON analysis.
Description check ✅ Passed The description is well-structured and directly related to the changeset, providing context about the feature, implementation approach, and testing strategy.
✨ 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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/biome_json_analyze/src/assist/source.rs (1)

1-8: The file has a duplicate comment line that shouldn't be there.

The codegen should produce a single preamble comment, but this file has two identical comment lines at the start (lines 1 and 3). Either this file was manually edited, or codegen wasn't executed properly. Run cargo run --package xtask --bin codegen -- assist and ensure the output matches the expected generated format before committing.

🧹 Nitpick comments (7)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)

30-37: Consider iterator chain for conciseness (optional).

The manual loop could be simplified, though the current version is perfectly readable.

🔎 Optional refactor
-    let mut script_names = Vec::new();
-    for m in &members {
-        if let Ok(member) = m
-            && let Ok(name) = member.name().and_then(|n| n.inner_string_text())
-        {
-            script_names.push(name.text().to_string());
-        }
-    }
+    let script_names: Vec<String> = members
+        .iter()
+        .filter_map(|m| m.ok())
+        .filter_map(|member| member.name().ok()?.inner_string_text().ok())
+        .map(|name| name.text().to_string())
+        .collect();
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_pnpm_config.rs (1)

21-25: Consider adding rustdoc.

The implementation is clear, but adding inline rustdoc with a brief example would be helpful, especially since the coding guidelines mention using rustdoc for assists.

🔎 Suggested rustdoc addition
+/// Transforms a PNPM base configuration object by sorting its keys according to
+/// the canonical field order defined in sort-package-json.
+///
+/// # Example
+/// ```rust,ignore
+/// // Input: { "overrides": {...}, "peerDependencyRules": {...} }
+/// // Output: { "peerDependencyRules": {...}, "overrides": {...} }
+/// ```
 pub fn transform(value: &AnyJsonValue) -> Option<AnyJsonValue> {
     let object = value.as_json_object_value()?;
     let sorted = sort_object_by_key_order(object, PNPM_BASE_CONFIG_PROPERTIES)?;
     Some(AnyJsonValue::from(sorted))
 }

Based on coding guidelines recommending rustdoc for assists and their options.

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

64-73: Early return on any parse failure may skip valid members.

Using ? on member.ok() at Line 66 causes the function to return None if any member fails to parse, even if subsequent members contain the target key. Consider using continue to skip unparseable members instead.

🔎 Proposed 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()?;
+        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_dependencies_meta.rs (1)

47-77: Consider returning None when no transformation occurs.

Currently, when has_changes is false (Line 66-68), the function returns Some(object.clone()). This is consistent with the overall transform returning the original if nothing changed. However, returning None would signal "no action needed" and align with the pattern in sorters.rs where sort_object_by_comparator returns None for single-element objects.

This is minor — the current behaviour works, just a consistency note.

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

83-129: Consider reusing sort_object_by_comparator for ESLint rules sorting.

The sort_eslint_rules function reimplements much of what sort_object_by_comparator already provides. You could simplify:

🔎 Proposed refactor
+use super::sorters::sort_object_by_comparator;
+
 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());
-    }
-
-    member_vec.sort_by(|a, b| {
-        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());
-
-        match (a_name, b_name) {
-            (Some(a), Some(b)) => {
-                let a_slash_count = a.matches('/').count();
-                let b_slash_count = b.matches('/').count();
-
-                match a_slash_count.cmp(&b_slash_count) {
-                    std::cmp::Ordering::Equal => a.cmp(&b),
-                    other => other,
-                }
-            }
-            _ => std::cmp::Ordering::Equal,
-        }
-    });
-
-    let mut elements = Vec::new();
-    let mut separators = Vec::new();
-
-    for (i, member) in member_vec.iter().enumerate() {
-        elements.push(member.clone());
-        if i < member_vec.len() - 1 {
-            separators.push(make::token(T![,]));
-        }
-    }
-
-    let new_members = make::json_member_list(elements, separators);
-    Some(object.clone().with_json_member_list(new_members))
+    sort_object_by_comparator(object, |a, b| {
+        let a_slashes = a.matches('/').count();
+        let b_slashes = b.matches('/').count();
+        a_slashes.cmp(&b_slashes).then_with(|| a.cmp(b))
+    })
 }
crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs (2)

536-536: UniqArray and UniqAndSortArray transformers are not implemented.

These transformers simply return value.clone(), meaning fields like keywords, files, bundledDependencies, etc., won't be deduplicated or sorted. If this is intentional for the WIP, consider adding a // TODO comment.

Would you like me to help implement these array transformers?


307-310: Unreachable catch-all pattern.

The _ => {} at Line 309 is unreachable since all FieldTransformer variants are explicitly matched above. While harmless, it could mask future enum additions.

🔎 Suggested fix

Remove the catch-all or use #[deny(unreachable_patterns)]:

         FieldTransformer::SortPnpmConfig => {
             sorted.sort();
         }
-        _ => {}
+        FieldTransformer::None
+        | FieldTransformer::UniqArray
+        | FieldTransformer::UniqAndSortArray => {}
     }
📜 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 87dac09 and 023dce8.

⛔ 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)
**/*.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/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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_pnpm_config.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_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs
  • crates/biome_json_syntax/src/generated.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_scripts.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source.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/mod.rs
  • crates/biome_json_syntax/src/object_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs
**/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
🧠 Learnings (59)
📓 Common learnings
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
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
📚 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/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/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/dev_engines/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/pnpm_config/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/exports_default_last/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/dependencies_npm/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/eslint_field_order/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/prettier_overrides_last/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/dependencies_meta/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/husky_hooks/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/README.md
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/already_sorted/package.json
  • crates/biome_rule_options/src/organize_package_json.rs
  • 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/dev_engines/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/pnpm_config/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/scripts_grouped/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/prettier_overrides_last/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/dependencies_meta/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/exports_types_first/package.json
📚 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/README.md
  • 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/private_fields/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/prettier_overrides_last/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/dependencies_meta/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/sort_package_json/eslint_field_order/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: 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_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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_pnpm_config.rs
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
  • crates/biome_configuration/src/analyzer/assist/actions.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_dependencies_meta.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_scripts.rs
  • crates/biome_json_syntax/src/member_ext.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source.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/mod.rs
  • crates/biome_json_syntax/src/object_ext.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/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_rule_options/src/lib.rs
  • crates/biome_json_analyze/src/assist/source/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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/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 `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/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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_pnpm_config.rs
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/assist/source/organize_package_json/sort_exports.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
  • crates/biome_json_analyze/src/assist/source.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/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/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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_exports.rs
  • crates/biome_json_analyze/src/assist/source.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/mod.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/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_rule_options/src/organize_package_json.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_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 `Box<[Box<str>]>` instead of `Vec<String>` for collections of strings in rule options to save memory

Applied to files:

  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • 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 : 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/use_sorted_keys.rs
  • crates/biome_rule_options/src/organize_package_json.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/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/**/*_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_configuration/src/analyzer/assist/actions.rs
  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_analyze/src/assist/source.rs
  • crates/biome_json_analyze/src/assist/source/organize_package_json/mod.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_rule_options/src/lib.rs
  • crates/biome_rule_options/src/organize_package_json.rs
  • 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 : 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_rule_options/src/lib.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/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 : 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/use_sorted_keys.rs
  • crates/biome_json_analyze/src/assist/source.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/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/**/*_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/use_sorted_keys.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_exports.rs
  • crates/biome_json_analyze/src/assist/source.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 : 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/use_sorted_keys.rs
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • 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 : 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 : Check if a variable is global using the semantic model before reporting diagnostics for rules that ban global functions or variables

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 : 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/use_sorted_keys.rs
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_configuration/src/analyzer/assist/actions.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 **/*.rs : Use inline rustdoc documentation for rules, assists, and their options

Applied to files:

  • 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: 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: 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_prettier_config.rs
  • 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 `.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/organize_package_json/sort_prettier_config.rs
  • 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 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/organize_package_json/sort_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: In changesets, reference rules and assists with links to the website documentation

Applied to files:

  • .changeset/cool-rice-change.md
📚 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: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: 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/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/package.json
📚 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: 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: 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_analyze/Cargo.toml
  • crates/biome_json_syntax/src/generated.rs
  • crates/biome_json_analyze/src/assist/source.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: 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: 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/dev_engines/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/scripts_lifecycle/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/eslint_field_order/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/all_fields_order/package.json
  • crates/biome_json_analyze/tests/specs/source/organizePackageJson/sort_package_json/dependencies_meta/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/**/* : 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/dev_engines/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/eslint_field_order/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/**/*_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: 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 `Markup!` macro for diagnostic messages and code action descriptions to ensure proper formatting

Applied to files:

  • crates/biome_configuration/src/analyzer/assist/actions.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/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 : 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 : 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_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 : 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
📚 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: 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_syntax/src/generated.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: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 : 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.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/src/context.rs : Define `<Language>FormatContext` struct in a `context.rs` file containing `comments` and `source_map` fields, implementing `FormatContext` and `CstFormatContext` traits

Applied to files:

  • crates/biome_json_analyze/src/assist/source.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
🧬 Code graph analysis (8)
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_pnpm_config.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_json_analyze/src/assist/source/organize_package_json/sort_exports.rs (4)
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_analyze/src/assist/source/organize_package_json/sort_scripts.rs (1)
  • transform (23-51)
crates/biome_json_parser/src/lib.rs (1)
  • parse_json (26-29)
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_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_eslint_config.rs (1)
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/mod.rs (10)
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/use_sorted_keys.rs (3)
  • run (93-121)
  • diagnostic (123-131)
  • action (141-175)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies_meta.rs (1)
  • transform (35-45)
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_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_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_scripts.rs (1)
  • transform (23-51)
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs (1)
  • transform (7-22)
crates/biome_json_analyze/src/assist/source/organize_package_json/sorters.rs (6)
  • transform_people_array (222-224)
  • transform_badges_array (226-230)
  • sort_alphabetically_deep (10-13)
  • transform_nested_property (273-309)
  • sort_alphabetically (6-8)
  • sort_people_object (125-127)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Validate PR title

Comment on lines +457 to +460
FieldMetadata {
key: "preferGlobal",
transformer: FieldTransformer::SortObject,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

preferGlobal is typically a boolean, not an object.

The preferGlobal field in package.json is a deprecated boolean flag. Assigning SortObject as its transformer will have no effect (since booleans aren't objects), but it's semantically misleading.

🔎 Suggested fix
     FieldMetadata {
         key: "preferGlobal",
-        transformer: FieldTransformer::SortObject,
+        transformer: FieldTransformer::None,
     },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FieldMetadata {
key: "preferGlobal",
transformer: FieldTransformer::SortObject,
},
FieldMetadata {
key: "preferGlobal",
transformer: FieldTransformer::None,
},
🤖 Prompt for AI Agents
In
crates/biome_json_analyze/src/assist/source/organize_package_json/field_order.rs
around lines 457 to 460, the entry for "preferGlobal" incorrectly uses
FieldTransformer::SortObject even though preferGlobal is a deprecated boolean;
replace the transformer with a no-op transformer (e.g., FieldTransformer::None
or a passthrough variant used elsewhere in this file) or remove the transformer
entry so it’s not treated as an object transformer, ensuring the field is
handled as a boolean.

Comment on lines +206 to +221
FieldTransformer::SortDependencies
| FieldTransformer::SortDependenciesMeta
| FieldTransformer::SortScripts
| FieldTransformer::SortExports
| FieldTransformer::SortEslintConfig
| FieldTransformer::SortPrettierConfig
| FieldTransformer::SortPeopleArray
| FieldTransformer::SortBadgesArray
| FieldTransformer::SortObjectDeep
| FieldTransformer::SortHusky
| FieldTransformer::SortDevEngines
| FieldTransformer::SortWorkspaces
| FieldTransformer::SortPnpmConfig => false,

FieldTransformer::UniqArray | FieldTransformer::UniqAndSortArray => false,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Complex transformers always return false in needs_transformation.

For transformers like SortDependencies, SortScripts, SortExports, etc., needs_transformation returns false. This means is_organized won't detect when these fields are unordered, potentially causing the rule not to trigger when it should.

If the intent is to avoid expensive checks, consider adding a comment explaining this trade-off. Otherwise, implement proper checks for at least the most common transformers.

🤖 Prompt for AI Agents
In crates/biome_json_analyze/src/assist/source/organize_package_json/mod.rs
around lines 206–221 the complex FieldTransformer variants all return false from
needs_transformation which prevents is_organized from detecting
unordered/duplicate fields; either implement proper predicate checks for these
variants (e.g., detect unsorted dependency keys, unsorted script keys, unsorted
export keys, unsorted eslint/prettier config entries, unsorted people/badges
arrays, deep-object order, husky keys, devEngines/workspaces/pnpm config
ordering, and detect duplicates for UniqArray/UniqAndSortArray) and wire those
checks into needs_transformation, or if this is an intentional performance
trade-off add a clear comment explaining why these expensive checks are skipped
and add TODOs and/or targeted tests; also update/add unit tests to cover the
common transformers you implement to ensure is_organized triggers correctly.

Comment on lines +15 to +19
let sorted = if should_sort_dependencies_like_npm(package_json_root) {
sort_object_by_comparator(object, |a, b| a.cmp(b))?
} else {
sort_alphabetically(object)?
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Both branches produce identical sorting.

Looking at the relevant snippet from sorters.rs, sort_alphabetically uses |a, b| a.cmp(b) — the same comparator as Line 16. The npm vs non-npm distinction has no effect.

The docstring at Line 5-6 mentions npm uses "locale-aware comparison", but String::cmp is lexicographic byte comparison, not locale-aware. If sort-package-json truly differs here, consider using str::to_lowercase().cmp(...) or a locale-aware comparator for npm.

🔎 Suggested clarification or fix

If both should genuinely be the same, remove the conditional and simplify:

-    let sorted = if should_sort_dependencies_like_npm(package_json_root) {
-        sort_object_by_comparator(object, |a, b| a.cmp(b))?
-    } else {
-        sort_alphabetically(object)?
-    };
+    let sorted = sort_alphabetically(object)?;

Otherwise, implement the intended locale-aware comparison for npm.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let sorted = if should_sort_dependencies_like_npm(package_json_root) {
sort_object_by_comparator(object, |a, b| a.cmp(b))?
} else {
sort_alphabetically(object)?
};
let sorted = sort_alphabetically(object)?;
🤖 Prompt for AI Agents
In
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_dependencies.rs
around lines 15–19, both branches call the same comparator (String::cmp) so the
npm-vs-non-npm conditional has no effect; either collapse the branches into a
single call and remove the conditional, or implement the intended
locale-aware/comparator difference by replacing the comparator in the npm branch
with a locale/case-insensitive comparison (for example compare a.to_lowercase()
and b.to_lowercase(), or use a proper collation crate like ICU4X/unic or
similar) so the npm path actually performs a different, locale-aware sort.

Comment on lines +162 to +186
fn sort_script_names(names: Vec<String>, prefix: &str) -> Vec<String> {
let mut group_map: HashMap<String, Vec<String>> = HashMap::new();

for key in &names {
let rest = if prefix.is_empty() {
key.as_str()
} else {
&key[prefix.len() + 1..]
};

if let Some(idx) = rest.find(':') {
let base_len = if prefix.is_empty() {
0
} else {
prefix.len() + 1
};
let base = &key[..base_len + idx];
group_map
.entry(base.to_string())
.or_default()
.push(key.clone());
} else {
group_map.entry(key.clone()).or_default().push(key.clone());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Potential panic on string slicing.

Line 169 performs &key[prefix.len() + 1..] assuming key starts with prefix:. If key equals prefix exactly or doesn't contain the expected :, this could panic or produce unexpected results.

The guard at line 172 checks for : in rest, but rest is already derived from the potentially unsafe slice.

🔎 Suggested safer approach
     for key in &names {
         let rest = if prefix.is_empty() {
             key.as_str()
         } else {
-            &key[prefix.len() + 1..]
+            key.get(prefix.len() + 1..).unwrap_or("")
         };

Or validate that key starts with {prefix}: before slicing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn sort_script_names(names: Vec<String>, prefix: &str) -> Vec<String> {
let mut group_map: HashMap<String, Vec<String>> = HashMap::new();
for key in &names {
let rest = if prefix.is_empty() {
key.as_str()
} else {
&key[prefix.len() + 1..]
};
if let Some(idx) = rest.find(':') {
let base_len = if prefix.is_empty() {
0
} else {
prefix.len() + 1
};
let base = &key[..base_len + idx];
group_map
.entry(base.to_string())
.or_default()
.push(key.clone());
} else {
group_map.entry(key.clone()).or_default().push(key.clone());
}
}
fn sort_script_names(names: Vec<String>, prefix: &str) -> Vec<String> {
let mut group_map: HashMap<String, Vec<String>> = HashMap::new();
for key in &names {
let rest = if prefix.is_empty() {
key.as_str()
} else {
key.get(prefix.len() + 1..).unwrap_or("")
};
if let Some(idx) = rest.find(':') {
let base_len = if prefix.is_empty() {
0
} else {
prefix.len() + 1
};
let base = &key[..base_len + idx];
group_map
.entry(base.to_string())
.or_default()
.push(key.clone());
} else {
group_map.entry(key.clone()).or_default().push(key.clone());
}
}
🤖 Prompt for AI Agents
In
crates/biome_json_analyze/src/assist/source/organize_package_json/sort_scripts.rs
around lines 162-186, the code slices key with &key[prefix.len() + 1..] assuming
key contains “prefix:”, which can panic or be incorrect when key == prefix or
doesn’t include the colon; change to safely derive rest by checking and using
strip_prefix or starts_with before slicing: if prefix.is_empty() just use
key.as_str(), otherwise check if key.starts_with(&format!("{}:", prefix)) and
then use key.strip_prefix(&format!("{}:", prefix)).unwrap_or("") (or fall back
to a safe alternative) and only search for ':' in that safe rest; similarly
compute base by using the known split point rather than indexing with
prefix.len() + 1 to avoid out-of-bounds panics.

Comment on lines +5 to +12
/// https://docs.npmjs.com/cli/v7/using-npm/workspaces?v=true#running-commands-in-the-context-of-workspaces
pub fn transform(value: &AnyJsonValue, _root: &JsonObjectValue) -> Option<AnyJsonValue> {
let object = value.as_json_object_value()?;

let sorted_base = sort_object_by_key_order(object, &["packages", "catalog"])?;

Some(AnyJsonValue::from(sorted_base))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's read the file to see the full context
cat -n crates/biome_json_analyze/src/assist/source/organize_package_json/sort_workspaces.rs

Repository: biomejs/biome

Length of output: 619


🏁 Script executed:

# Let's check if there are other similar functions in the same directory for pattern comparison
fd -t f "\.rs$" crates/biome_json_analyze/src/assist/source/organize_package_json/ | head -10

Repository: biomejs/biome

Length of output: 902


🏁 Script executed:

# Search for other public functions in similar assists to see rustdoc patterns
rg -A 3 "^pub fn " crates/biome_json_analyze/src/assist/source/organize_package_json/ | head -50

Repository: biomejs/biome

Length of output: 5208


🌐 Web query:

npm CLI current version 2026 workspaces documentation

💡 Result:

As of Jan 3, 2026 the latest stable npm CLI release is v11.7.0 (released Dec 9, 2025). (gitclear.com)

Official npm CLI workspaces documentation: "Workspaces" on the npm docs site. (docs.npmjs.com)

Citations:


Add rustdoc documentation for the public function.

The transform function lacks inline rustdoc. Per the coding guidelines, assistsrequire inline documentation for their public functions. The suggested documentation below covers purpose, parameters, and return values:

📝 Suggested rustdoc addition
 /// https://docs.npmjs.com/cli/v7/using-npm/workspaces?v=true#running-commands-in-the-context-of-workspaces
+/// Transforms workspace configuration by sorting keys according to the standard order.
+///
+/// Filters and orders workspace object keys to include only `packages` and `catalog`.
+///
+/// # Arguments
+/// * `value` - The JSON value to transform (must be an object)
+/// * `_root` - The root package.json object (currently unused)
+///
+/// # Returns
+/// The sorted workspace object, or `None` if the input is not an object.
 pub fn transform(value: &AnyJsonValue, _root: &JsonObjectValue) -> Option<AnyJsonValue> {

Update the npm documentation URL reference.

The URL references npm CLI v7 documentation, but the current version is v11 (released December 2025). Update the reference to a current version—v8 or later. Whilst the v7 docs may still be accessible, using current documentation is better for maintainability.

@arthurfiorette
Copy link
Author

Opened #8659 with correct next branch target

@arthurfiorette arthurfiorette changed the title feat(analyze/json): implement organizePackageJson (WIP) feat(analyze/json): implement organizePackageJson (Broken) Jan 3, 2026
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.

1 participant