Skip to content

useSortedInterfaceMembers

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useSortedInterfaceMembers.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"useSortedInterfaceMembers": "on"
}
}
}
}

Sort interface members by key.

Interface members are sorted according to their names. The rule distinguishes between two types of members:

Sortable members - Members with explicit, fixed names that can be alphabetically sorted:

  • Property signatures: property: type
  • Method signatures: method(): type
  • Getter signatures: get property(): type
  • Setter signatures: set property(value: type): void

Non-sortable members - Members without fixed names or with dynamic/computed names:

  • Call signatures: (): type (represents the interface as a callable function)
  • Construct signatures: new (): type (represents the interface as a constructor)
  • Index signatures: [key: string]: type (represents dynamic property access)

The rule sorts all sortable members alphabetically and places them first, followed by non-sortable members in their original order. Non-sortable members cannot be meaningfully sorted by name since they represent different interface contracts rather than named properties or methods.

interface MixedMembers {
z: string;
a: number;
(): void; // Call signature
y: boolean;
new (): MixedMembers; // Construct signature
b: string;
[key: string]: any; // Index signature
}
code-block.ts:1:1 assist/source/useSortedInterfaceMembers  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The interface members are not sorted by key.

> 1 │ interface MixedMembers {
^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ z: string;
> 3 │ a: number;
> 4 │ (): void; // Call signature
> 5 │ y: boolean;
> 6 │ new (): MixedMembers; // Construct signature
> 7 │ b: string;
> 8 │ [key: string]: any; // Index signature
> 9 │ }
^
10 │

Safe fix: Sort the interface members by key.

1 1 interface MixedMembers {
2 - ··z:·string;
3 - ··a:·number;
4 - ··():·void;··//·Call·signature
5 - ··y:·boolean;
6 - ··new·():·MixedMembers;··//·Construct·signature
7 - ··b:·string;
2+ ··a:·number;
3+ ··b:·string;
4+ ··y:·boolean;
5+ ··z:·string;
6+ ··():·void;··//·Call·signature
7+ ··new·():·MixedMembers;··//·Construct·signature
8 8 [key: string]: any; // Index signature
9 9 }

interface MixedMembers {
a: number;
b: string;
y: boolean;
z: string;
(): void; // Non-sortable members remain in original order
new (): MixedMembers;
[key: string]: any;
}