Skip to content

useSortedAttributes

~/.config/zed/settings.json
{
"code_actions_on_format": {
"source.action.useSortedAttributes.biome": true,
}
}

Enforce attribute sorting in JSX elements.

This rule checks if the JSX props are sorted in a consistent way. Props are sorted alphabetically using a natural sort order. This rule will not consider spread props as sortable. Instead, whenever it encounters a spread prop, it will sort all the previous non spread props up until the nearest spread prop, if one exist. This prevents breaking the override of certain props using spread props.

<Hello lastName="Smith" firstName="John" />;
code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Source action diff:

1 - <Hello·lastName=Smith·firstName=John·/>;
1+ <Hello·firstName=John·lastName=Smith·/>;
2 2

<Hello lastName="Smith" firstName="John" {...this.props} tel="0000" address="111 Main Street" {...another.props} lastName="Smith" />;
code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Source action diff:

1 - <Hello·lastName=Smith·firstName=John·{...this.props}·tel=0000·address=111·Main·Street··{...another.props}·lastName=Smith·/>;
1+ <Hello·firstName=John·lastName=Smith·{...this.props}·tel=0000·address=111·Main·Street··{...another.props}·lastName=Smith·/>;
2 2

code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Source action diff:

1 - <Hello·lastName=Smith·firstName=John·{...this.props}·tel=0000·address=111·Main·Street··{...another.props}·lastName=Smith·/>;
1+ <Hello·lastName=Smith·firstName=John·{...this.props}·address=111·Main·Street·tel=0000··{...another.props}·lastName=Smith·/>;
2 2

biome.json
{
"assist": {
"actions": {
"source": {
"useSortedAttributes": "on"
}
}
}
}