Skip to content

Commit

Permalink
feat: add newlines-between to some rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Jan 18, 2025
1 parent c705547 commit 231af42
Show file tree
Hide file tree
Showing 18 changed files with 1,352 additions and 95 deletions.
37 changes: 37 additions & 0 deletions docs/content/rules/sort-array-includes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ if ([

Each group of elements (separated by empty lines) is treated independently, and the order within each group is preserved.

### newlinesBetween

<sub>default: `'ignore'`</sub>

Specifies how new lines should be handled between groups.

- `ignore` — Do not report errors related to new lines.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### useConfigurationIf

<sub>
Expand Down Expand Up @@ -301,6 +317,25 @@ Predefined groups are characterized by a selector.
- `literal`: Array elements that are not spread values.
- `spread`: Array elements that are spread values.

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

### customGroups

<sub>
Expand Down Expand Up @@ -379,6 +414,7 @@ Custom groups have a higher priority than any predefined group.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
newlinesBetween: 'ignore',
useConfigurationIf: {},
groups: [],
customGroups: [],
Expand Down Expand Up @@ -408,6 +444,7 @@ Custom groups have a higher priority than any predefined group.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
newlinesBetween: 'ignore',
useConfigurationIf: {},
groups: [],
customGroups: [],
Expand Down
23 changes: 23 additions & 0 deletions docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ Specifies how new lines should be handled between class member groups.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed in object types.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### ignoreCallbackDependenciesPatterns
Expand Down Expand Up @@ -556,6 +560,25 @@ abstract class Example extends BaseExample {
}
```

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

### customGroups

<Important title="Migrating from the old API">
Expand Down
23 changes: 23 additions & 0 deletions docs/content/rules/sort-interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ Specifies how new lines should be handled between interface groups.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed between interface members.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### [DEPRECATED] groupKind
Expand Down Expand Up @@ -433,6 +437,25 @@ interface Interface {
method(): string
```
#### Newlines between groups
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
See the [`newlinesBetween`](#newlinesbetween) option.
This feature is only applicable when `partitionByNewLine` is false.
```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```
### customGroups
<Important title="Migrating from the old API">
Expand Down
23 changes: 23 additions & 0 deletions docs/content/rules/sort-intersection-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ Specifies how new lines should be handled between intersection type groups.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed in intersection types.
You can also enforce the newline behavior between two specific groups through the `groups` options.
See the [`groups`](#newlines-between-groups) option.
This option is only applicable when `partitionByNewLine` is `false`.
### groups
Expand Down Expand Up @@ -296,6 +300,25 @@ type Example =
}
```

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

## Usage

<CodeTabs
Expand Down
29 changes: 29 additions & 0 deletions docs/content/rules/sort-jsx-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ Allows you to specify names or patterns for JSX elements that should be ignored

You can specify their names or a regexp pattern to ignore, for example: `'^Table.+'` to ignore all object types whose names begin with the word Table.

### partitionByNewLine

<sub>default: `false`</sub>

When `true`, the rule will not sort members if there is an empty line between them. This can be useful for keeping logically separated groups of members in their defined order.

### groups

<sub>
Expand All @@ -225,6 +231,25 @@ Within a given group, members will be sorted according to the `type`, `order`, `
Individual groups can be combined together by placing them in an array. The order of groups in that array does not matter.
All members of the groups in the array will be sorted together as if they were part of a single group.

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

### customGroups

<sub>
Expand Down Expand Up @@ -280,6 +305,8 @@ Custom group matching takes precedence over predefined group matching.
ignoreCase: true,
specialCharacters: 'keep',
ignorePattern: [],
partitionByNewLine: false,
newlinesBetween: 'ignore',
groups: [],
customGroups: {},
},
Expand Down Expand Up @@ -307,6 +334,8 @@ Custom group matching takes precedence over predefined group matching.
ignoreCase: true,
specialCharacters: 'keep',
ignorePattern: [],
partitionByNewLine: false,
newlinesBetween: 'ignore',
groups: [],
customGroups: {},
},
Expand Down
22 changes: 22 additions & 0 deletions docs/content/rules/sort-modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ Specifies how new lines should be handled between module member groups.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed in object types.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### groups
Expand Down Expand Up @@ -496,6 +500,24 @@ Example:
}
```

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

## Usage

Expand Down
23 changes: 23 additions & 0 deletions docs/content/rules/sort-object-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Specifies how new lines should be handled between object type groups.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed in object types.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### [DEPRECATED] groupKind
Expand Down Expand Up @@ -529,6 +533,25 @@ type User = {
}
```
#### Newlines between groups
You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.
See the [`newlinesBetween`](#newlinesbetween) option.
This feature is only applicable when `partitionByNewLine` is false.
```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```
## Usage
<CodeTabs
Expand Down
37 changes: 37 additions & 0 deletions docs/content/rules/sort-sets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ let items = new Set([

Each group of elements (separated by empty lines) is treated independently, and the order within each group is preserved.

### newlinesBetween

<sub>default: `'ignore'`</sub>

Specifies how new lines should be handled between groups.

- `ignore` — Do not report errors related to new lines.
- `always` — Enforce one new line between each group, and forbid new lines inside a group.
- `never` — No new lines are allowed.

You can also enforce the newline behavior between two specific groups through the `groups` options.

See the [`groups`](#newlines-between-groups) option.

This option is only applicable when `partitionByNewLine` is `false`.

### groups

<sub>
Expand All @@ -259,6 +275,25 @@ Predefined groups are characterized by a selector.
- `literal`: Array elements that are not spread values.
- `spread`: Array elements that are spread values.

#### Newlines between groups

You may place `newlinesBetween` objects between your groups to enforce the newline behavior between two specific groups.

See the [`newlinesBetween`](#newlinesbetween) option.

This feature is only applicable when `partitionByNewLine` is false.

```ts
{
newlinesBetween: 'always',
groups: [
'a',
{ newlinesBetween: 'never' }, // Overrides the global newlinesBetween option
'b',
]
}
```

### customGroups

<sub>
Expand Down Expand Up @@ -337,6 +372,7 @@ Custom groups have a higher priority than any predefined group.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
newlinesBetween: 'ignore',
useConfigurationIf: {},
groups: [],
customGroups: [],
Expand Down Expand Up @@ -366,6 +402,7 @@ Custom groups have a higher priority than any predefined group.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
newlinesBetween: 'ignore',
useConfigurationIf: {},
groups: [],
customGroups: [],
Expand Down
Loading

0 comments on commit 231af42

Please sign in to comment.