useSortedInterfaceMembers
Summary
Section titled “Summary”- Diagnostic Category:
assist/source/useSortedInterfaceMembers - Sources:
- Inspired from
perfectionist/sort-interfaces
- Inspired from
How to enable in your editor
Section titled “How to enable in your editor”{ "editor.codeActionsOnSave": { "source.action.useSortedInterfaceMembers.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useSortedInterfaceMembers.biome": true, "source.fixAll.biome": true }}
Use the source action code
source.action.useSortedInterfaceMembers.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "useSortedInterfaceMembers": "on" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.