Skip to content

Commit

Permalink
feat: add custom groups fallback sort option
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Feb 22, 2025
1 parent a0ca995 commit f42f24f
Show file tree
Hide file tree
Showing 61 changed files with 1,547 additions and 491 deletions.
1 change: 1 addition & 0 deletions docs/content/guide/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ In settings you can set the following options:

- `type` — The type of sorting. Possible values are `'alphabetical'`, `'natural'`, `'line-length'` and `custom`.
- `order` — The order of sorting. Possible values are `'asc'` and `'desc'`.
- `fallbackSort` — The fallback sorting type and order to use when two elements are equal.
- `alphabet` — The custom alphabet to use when `type` is `custom`.
- `ignoreCase` — Ignore case when sorting.
- `ignorePattern` — Ignore sorting for elements that match the pattern.
Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-array-includes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -371,6 +377,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
selector?: string
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
}
Expand All @@ -385,6 +392,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
anyOf: Array<{
selector?: string
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
Expand All @@ -401,6 +409,7 @@ An array element will match a `CustomGroupAnyOfDefinition` group if it matches a
- `elementNamePattern`: If entered, will check that the name of the element matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group

#### Match importance

Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -647,6 +653,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
newlinesInside?: 'always' | 'never'
selector?: string
modifiers?: string[]
Expand All @@ -664,6 +671,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
newlinesInside?: 'always' | 'never'
anyOf: Array<{
selector?: string
Expand All @@ -687,6 +695,7 @@ A class member will match a `CustomGroupAnyOfDefinition` group if it matches all
- `decoratorNamePattern`: If entered, will check that at least one `decorator` matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group
- `newlinesInside`: Enforces a specific newline behavior between elements of the group.

#### Match importance
Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-decorators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-enums.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -285,6 +291,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
}

Expand All @@ -298,6 +305,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
anyOf: Array<{
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
}>
Expand All @@ -313,6 +321,7 @@ An enum member will match a `CustomGroupAnyOfDefinition` group if it matches all
- `elementValuePattern`: If entered, will check that the value of the element matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group

#### Match importance

Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-heritage-clauses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -554,6 +560,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
sortBy?: 'name' | 'value'
newlinesInside?: 'always' | 'never'
selector?: string
Expand All @@ -572,6 +579,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
sortBy?: 'name' | 'value'
newlinesInside?: 'always' | 'never'
anyOf: Array<{
Expand All @@ -594,6 +602,7 @@ An interface member will match a `CustomGroupAnyOfDefinition` group if it matche
- `elementValuePattern`: Only for properties. If entered, will check that the value of the property matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group
- `sortBy`: Overrides the `sortBy` option for that custom group
- `newlinesInside`: Enforces a specific newline behavior between elements of the group.
Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-intersection-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-jsx-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-maps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -315,6 +321,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
}

Expand All @@ -328,6 +335,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
anyOf: Array<{
elementNamePattern?: string | string[] | { pattern: string; flags?: string } | { pattern: string; flags?: string }[]
}>
Expand All @@ -342,6 +350,7 @@ A map element will match a `CustomGroupAnyOfDefinition` group if it matches all
- `elementNamePattern`: If entered, will check that the name of the element matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group

#### Match importance

Expand Down
11 changes: 10 additions & 1 deletion docs/content/rules/sort-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down Expand Up @@ -426,6 +432,7 @@ interface CustomGroupDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
newlinesInside?: 'always' | 'never'
selector?: string
modifiers?: string[]
Expand All @@ -442,6 +449,7 @@ interface CustomGroupAnyOfDefinition {
groupName: string
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted'
order?: 'asc' | 'desc'
fallbackSort?: { type: string; order?: 'asc' | 'desc' }
newlinesInside?: 'always' | 'never'
anyOf: Array<{
selector?: string
Expand All @@ -463,6 +471,7 @@ A module member will match a `CustomGroupAnyOfDefinition` group if it matches al
- `decoratorNamePattern`: If entered, will check that at least one `decorator` matches the pattern entered.
- `type`: Overrides the sort type for that custom group. `unsorted` will not sort the group.
- `order`: Overrides the sort order for that custom group
- `fallbackSort`: Overrides the fallbackSort option for that custom group
- `newlinesInside`: Enforces a specific newline behavior between elements of the group.

#### Match importance
Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-named-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
8 changes: 7 additions & 1 deletion docs/content/rules/sort-named-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ Determines whether the sorted items should be in ascending or descending order.
### fallbackSort

<sub>
type: `{ type: string; order?: 'asc' | 'desc' }`
type:
```
{
type: 'alphabetical' | 'natural' | 'line-length' | 'custom' | 'unsorted'
order?: 'asc' | 'desc'
}
```
</sub>
<sub>default: `{ type: 'unsorted' }`</sub>

Expand Down
Loading

0 comments on commit f42f24f

Please sign in to comment.