Skip to content

feat(assist): use sorted type fields 9137#9275

Open
ff1451 wants to merge 4 commits intobiomejs:nextfrom
ff1451:feat/use-sorted-type-fields-9137
Open

feat(assist): use sorted type fields 9137#9275
ff1451 wants to merge 4 commits intobiomejs:nextfrom
ff1451:feat/use-sorted-type-fields-9137

Conversation

@ff1451
Copy link
Contributor

@ff1451 ff1451 commented Feb 28, 2026

I used Claude Code to assist with generating test cases and documentation.

Summary

Implements the useSortedTypeFields assist action for GraphQL as part of #9137.

This action alphabetically sorts fields of:

  • ObjectTypeDefinition
  • InterfaceTypeDefinition
  • InputObjectTypeDefinition
  • and their corresponding extensions

The ordering matches JavaScript’s localeCompare() behavior for GraphQL identifiers ([_A-Za-z0-9]):

  • Primary order: _ < digits < letters (case-insensitive)
  • Tiebreaker: lowercase before uppercase (e.g. aField before AField)

This PR also introduces the assist category infrastructure for biome_graphql_analyze, which previously only supported lint rules.


Why this is implemented as an assist

Sorting fields is a non-semantic, style-only transformation with a clear and safe auto-fix. It does not indicate a bug or problematic pattern — it only improves structural consistency and readability.

For that reason, I implemented it as an assist action rather than a lint rule. If this classification is incorrect (for example, if it should follow thenursery rule policy or be modeled as a lint rule instead), please let me know. I’m happy to adjust the implementation accordingly.


Branch Target

This PR currently targets next, since adding a new assist action is a user-facing feature (minor change).

If new assist actions are expected to target main instead (e.g. if they follow the same release policy as nursery rules), I’m happy to retarget the branch.


Test Plan

Snapshot tests cover:

  • Unsorted ObjectTypeDefinition
  • Unsorted InterfaceTypeDefinition
  • Unsorted InputObjectTypeDefinition
  • Unsorted ObjectTypeExtension
  • Unsorted InterfaceTypeExtension
  • Unsorted InputObjectTypeExtension
  • Mixed-case ordering (apple before Zoo)
  • Case tiebreaker (aField before AField)
  • localeCompare character class ordering (a_ before a1)

Documentation

Inline rustdoc documentation is provided in use_sorted_type_fields.rs,
including expect_diff examples demonstrating the before/after transformation.


@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

🦋 Changeset detected

Latest commit: f91741a

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

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

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

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

@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter A-Tooling Area: internal tools A-Diagnostic Area: diagnostocis labels Feb 28, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

Walkthrough

This pull request introduces a new GraphQL assist action called useSortedTypeFields that automatically sorts fields within GraphQL type, interface, and input object definitions in alphabetical order. The implementation includes registration of the new action variant, configuration infrastructure, the sorting rule with locale-aware comparison logic, and comprehensive test specifications covering both valid and invalid GraphQL scenarios.

Possibly related PRs

Suggested labels

A-Project, A-Tooling, A-Linter, A-Parser

Suggested reviewers

  • Netail
  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the implementation of useSortedTypeFields assist action, the sorting logic, test coverage, and design rationale.
Title check ✅ Passed The title accurately reflects the main change: introducing a new useSortedTypeFields assist action for GraphQL type fields.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/biome_graphql_analyze/src/assist/source/use_sorted_type_fields.rs (1)

79-131: Consider extracting common pattern.

The six match arms follow identical structure. A helper method could reduce duplication, though current readability is fine.

♻️ Optional: Extract helper for common pattern
fn check_fields<T, F>(fields: Option<T>, check_sorted: F) -> Option<UseSortedTypeFieldsState>
where
    F: FnOnce(&T) -> bool,
    T: Into<UseSortedTypeFieldsState>,
{
    let fields = fields?;
    if check_sorted(&fields) {
        None
    } else {
        Some(fields.into())
    }
}

This would require implementing Into<UseSortedTypeFieldsState> for the field types, which may be more boilerplate than it's worth.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_graphql_analyze/src/assist/source/use_sorted_type_fields.rs`
around lines 79 - 131, The six match arms in run (handling
UseSortedTypeFieldsQuery::{GraphqlObjectTypeDefinition,
GraphqlObjectTypeExtension, GraphqlInterfaceTypeDefinition,
GraphqlInterfaceTypeExtension, GraphqlInputObjectTypeDefinition,
GraphqlInputObjectTypeExtension}) duplicate the same pattern; extract a helper
like check_fields that takes the optional fields, a predicate
(is_field_definition_list_sorted or is_input_field_list_sorted) and a closure or
an Into/From conversion to produce the appropriate UseSortedTypeFieldsState
(UseSortedTypeFieldsState::TypeFields or ::InputFields) so each arm reduces to
calling check_fields(fields_option, predicate, state_mapper). Ensure helper
handles the Option early-return (fields?) and returns Some(state) or None
matching current behavior; reference functions is_field_definition_list_sorted,
is_input_field_list_sorted and enum UseSortedTypeFieldsState for integration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_graphql_analyze/src/assist/source/use_sorted_type_fields.rs`:
- Around line 79-131: The six match arms in run (handling
UseSortedTypeFieldsQuery::{GraphqlObjectTypeDefinition,
GraphqlObjectTypeExtension, GraphqlInterfaceTypeDefinition,
GraphqlInterfaceTypeExtension, GraphqlInputObjectTypeDefinition,
GraphqlInputObjectTypeExtension}) duplicate the same pattern; extract a helper
like check_fields that takes the optional fields, a predicate
(is_field_definition_list_sorted or is_input_field_list_sorted) and a closure or
an Into/From conversion to produce the appropriate UseSortedTypeFieldsState
(UseSortedTypeFieldsState::TypeFields or ::InputFields) so each arm reduces to
calling check_fields(fields_option, predicate, state_mapper). Ensure helper
handles the Option early-return (fields?) and returns Some(state) or None
matching current behavior; reference functions is_field_definition_list_sorted,
is_input_field_list_sorted and enum UseSortedTypeFieldsState for integration.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd3da1 and b9a73d9.

⛔ Files ignored due to path filters (3)
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_graphql_analyze/tests/specs/source/useSortedTypeFields/invalid.graphql.snap is excluded by !**/*.snap and included by **
  • crates/biome_graphql_analyze/tests/specs/source/useSortedTypeFields/valid.graphql.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (13)
  • .changeset/afraid-humans-worry.md
  • crates/biome_configuration/src/analyzer/assist/actions.rs
  • crates/biome_graphql_analyze/build.rs
  • crates/biome_graphql_analyze/src/assist.rs
  • crates/biome_graphql_analyze/src/assist/source.rs
  • crates/biome_graphql_analyze/src/assist/source/use_sorted_type_fields.rs
  • crates/biome_graphql_analyze/src/lib.rs
  • crates/biome_graphql_analyze/src/registry.rs
  • crates/biome_graphql_analyze/tests/specs/source/useSortedTypeFields/invalid.graphql
  • crates/biome_graphql_analyze/tests/specs/source/useSortedTypeFields/valid.graphql
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/use_sorted_type_fields.rs
  • xtask/codegen/src/generate_analyzer.rs

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 28, 2026

Merging this PR will not alter performance

✅ 1 untouched benchmark
⏩ 154 skipped benchmarks1


Comparing ff1451:feat/use-sorted-type-fields-9137 (f91741a) with next (9ec8500)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on next (8cd3da1) during the generation of this report, so 9ec8500 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ff1451 ff1451 changed the title feat(lint): use sorted type fields 9137 feat(assist): use sorted type fields 9137 Feb 28, 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-Project Area: project A-Tooling Area: internal tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant