Skip to content

Commit

Permalink
feat!: remove minimatch in favor of regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 19, 2024
1 parent 2af0cd3 commit e240971
Show file tree
Hide file tree
Showing 67 changed files with 294 additions and 797 deletions.
3 changes: 1 addition & 2 deletions docs/content/guide/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ In settings you can set the following options:
- `ignoreCase` — Ignore case when sorting.
- `ignorePattern` — Ignore sorting for elements that match the pattern.
- `specialCharacters` — Control whether special characters should be kept, trimmed or removed before sorting. Values can be `'keep'`, `'trim'` or `'remove'`.
- `partitionByComment` — Partition the sorted elements by comments. Values can be `true`, `false` or glob pattern string.
- `partitionByComment` — Partition the sorted elements by comments. Values can be `true`, `false` or regexp pattern.
- `partitionByNewLine` — Partition the sorted elements by new lines. Values can be `true` or `false`.
- `matcher` — Determine the matcher used for patterns in options such as `partitionByComment`. Values can be `minimatch` or `regex`.

Example:

Expand Down
15 changes: 2 additions & 13 deletions docs/content/rules/sort-array-includes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ Allows you to use comments to separate the members of arrays into logical groups

- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
- `string` — A glob pattern to specify which comments should act as delimiters.
- `string[]` — A list of glob patterns to specify which comments should act as delimiters.
- `string` — A regexp pattern to specify which comments should act as delimiters.
- `string[]` — A list of regexp patterns to specify which comments should act as delimiters.

### partitionByNewLine

Expand Down Expand Up @@ -209,15 +209,6 @@ if ([

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

### matcher

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

Determines the matcher used for patterns in the `partitionByComment` option.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

## Usage

<CodeTabs
Expand All @@ -242,7 +233,6 @@ Determines the matcher used for patterns in the `partitionByComment` option.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
matcher: 'minimatch',
},
],
},
Expand All @@ -269,7 +259,6 @@ Determines the matcher used for patterns in the `partitionByComment` option.
specialCharacters: 'keep',
groupKind: 'literals-first',
partitionByNewLine: false,
matcher: 'minimatch',
},
],
},
Expand Down
16 changes: 2 additions & 14 deletions docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Allows you to use comments to separate the class members into logical groups. Th

- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
- string — A glob pattern to specify which comments should act as delimiters.
- string — A regexp pattern to specify which comments should act as delimiters.

### groups

Expand Down Expand Up @@ -506,9 +506,7 @@ Current API:
</sub>
<sub>default: `[]`</sub>

You can define your own groups and use custom glob patterns or regex for matching very specific class members.

Use the `matcher` option to specify the pattern matching method.
You can define your own groups and use regex for matching very specific class members.

A custom group definition may follow one of the two following interfaces:

Expand Down Expand Up @@ -616,14 +614,6 @@ Example:
}
```

### matcher

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

Determines the matcher used for patterns in the `partitionByComment` and `customGroups` options.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

## Usage

Expand All @@ -648,7 +638,6 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom
ignoreCase: true,
specialCharacters: 'keep',
partitionByComment: false,
matcher: 'minimatch',
groups: [
'index-signature',
['static-property', 'static-accessor-property'],
Expand Down Expand Up @@ -699,7 +688,6 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom
ignoreCase: true,
specialCharacters: 'keep',
partitionByComment: false,
matcher: 'minimatch',
groups: [
'index-signature',
['static-property', 'static-accessor-property'],
Expand Down
19 changes: 3 additions & 16 deletions docs/content/rules/sort-decorators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ Allows you to use comments to separate class decorators into logical groups.

- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
- `string` — A glob pattern to specify which comments should act as delimiters.
- `string[]` — An array of glob patterns to specify which comments should act as delimiters.
- `string` — A regexp pattern to specify which comments should act as delimiters.
- `string[]` — An array of regexp patterns to specify which comments should act as delimiters.

### groups

Expand Down Expand Up @@ -227,9 +227,7 @@ All members of the groups in the array will be sorted together as if they were p
</sub>
<sub>default: `{}`</sub>

You can define your own groups and use custom glob patterns or regex to match specific decorators.

Use the `matcher` option to specify the pattern matching method.
You can define your own groups and use regex to match specific decorators.

Each key of `customGroups` represents a group name which you can then use in the `groups` option. The value for each key can either be of type:
- `string` — A decorator's name matching the value will be marked as part of the group referenced by the key.
Expand Down Expand Up @@ -267,15 +265,6 @@ class MyClass {
}
```

### matcher

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

Determines the matcher used for patterns in the `partitionByComment` and `customGroups` options.

- `'minimatch'`Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'`Use regular expressions for pattern matching.

## Usage

<CodeTabs
Expand All @@ -298,7 +287,6 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
groups: [],
customGroups: {},
sortOnClasses: true,
Expand Down Expand Up @@ -330,7 +318,6 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
groups: [],
customGroups: {},
sortOnClasses: true,
Expand Down
14 changes: 2 additions & 12 deletions docs/content/rules/sort-enums.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ Allows you to use comments to separate the members of enums into logical groups.

- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
- `string` — A glob pattern to specify which comments should act as delimiters.
- `string[]` — A list of glob patterns to specify which comments should act as delimiters.
- `string` — A regexp pattern to specify which comments should act as delimiters.
- `string[]` — A list of regexp patterns to specify which comments should act as delimiters.

### partitionByNewLine

Expand All @@ -176,15 +176,6 @@ enum Enum {

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

### matcher

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

Determines the matcher used for patterns in the `partitionByComment` option.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

## Usage

<CodeTabs
Expand Down Expand Up @@ -239,7 +230,6 @@ Determines the matcher used for patterns in the `partitionByComment` option.
partitionByNewLine: false,
sortByValue: false,
forceNumericSort: false,
matcher: 'minimatch',
},
],
},
Expand Down
15 changes: 2 additions & 13 deletions docs/content/rules/sort-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ Allows you to use comments to separate the exports into logical groups. This can

- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
- `string` — A glob pattern to specify which comments should act as delimiters.
- `string[]` — A list of glob patterns to specify which comments should act as delimiters.
- `string` — A regexp pattern to specify which comments should act as delimiters.
- `string[]` — A list of regexp patterns to specify which comments should act as delimiters.

### partitionByNewLine

Expand Down Expand Up @@ -156,15 +156,6 @@ Allows you to group exports by their kind, determining whether value exports sho
- `values-first` — Group all value exports before type exports.
- `types-first` — Group all type exports before value exports.

### matcher

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

Determines the matcher used for patterns in the `partitionByComment` option.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

## Usage

<CodeTabs
Expand All @@ -190,7 +181,6 @@ Determines the matcher used for patterns in the `partitionByComment` option.
partitionByComment: false,
partitionByNewLine: false,
groupKind: 'mixed',
matcher: 'minimatch',
},
],
},
Expand Down Expand Up @@ -218,7 +208,6 @@ Determines the matcher used for patterns in the `partitionByComment` option.
partitionByComment: false,
partitionByNewLine: false,
groupKind: 'mixed',
matcher: 'minimatch',
},
],
},
Expand Down
17 changes: 2 additions & 15 deletions docs/content/rules/sort-heritage-clauses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ All members of the groups in the array will be sorted together as if they were p
</sub>
<sub>default: `{}`</sub>

You can define your own groups and use custom glob patterns or regex to match specific heritage clauses.

Use the `matcher` option to specify the pattern matching method.
You can define your own groups and use regex to match specific heritage clauses.

Each key of `customGroups` represents a group name which you can then use in the `groups` option. The value for each key can either be of type:
- `string` — A heritage clause's name matching the value will be marked as part of the group referenced by the key.
Expand Down Expand Up @@ -159,20 +157,11 @@ interface Interface extends WithId, Logged, StartupService {
'unknown'
],
+ customGroups: { // [!code ++]
+ withIdInterface: 'WithId' // [!code ++]
+ withIdInterface: '^WithId' // [!code ++]
+ } // [!code ++]
}
```

### matcher

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

Determines the matcher used for patterns in the `customGroups` option.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

## Usage

<CodeTabs
Expand All @@ -195,7 +184,6 @@ Determines the matcher used for patterns in the `customGroups` option.
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
groups: [],
customGroups: {}
},
Expand All @@ -222,7 +210,6 @@ Determines the matcher used for patterns in the `customGroups` option.
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
groups: [],
customGroups: {}
},
Expand Down
47 changes: 16 additions & 31 deletions docs/content/rules/sort-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ Controls whether special characters should be trimmed, removed or kept before so

### internalPattern

<sub>default: `['~/**']` for `minimatch` matcher, `['^~/.*']` for `regex` matcher</sub>
<sub>default: `['^~/.*']`</sub>

Allows you to specify a pattern for identifying internal imports. This is useful for distinguishing your own modules from external dependencies.

You can use glob patterns to define these internal imports.
You can use regexp patterns to define these internal imports.

### sortSideEffects

Expand Down Expand Up @@ -293,9 +293,7 @@ import type { BaseOptions } from './index.d.ts'
</sub>
<sub>default: `{ value: {}, type: {} }`</sub>

You can define your own groups and use custom glob patterns or regex to match specific imports.

Use the `matcher` option to specify the pattern matching method.
You can define your own groups and use regexp pattern to match specific imports.

Each key of the `value` or `type` fields represents a group name which you can then use in the `groups` option. The value for each key can either be of type:
- `string` — An import matching the value will be marked as part of the group referenced by the key.
Expand All @@ -308,38 +306,29 @@ Custom group matching takes precedence over predefined group matching.

```js
groups: [
+ 'react', // [!code ++]
+ 'react', // [!code ++]
'type',
['builtin', 'external'],
+ 'lodash', // [!code ++]
+ 'lodash', // [!code ++]
'internal-type',
'internal',
['parent-type', 'sibling-type', 'index-type'],
['parent', 'sibling', 'index'],
'object',
'unknown',
],
+ customGroups: { // [!code ++]
+ value: { // [!code ++]
+ react: ['react', 'react-*'], // [!code ++]
+ lodash: 'lodash', // [!code ++]
+ }, // [!code ++]
+ type: { // [!code ++]
+ react: ['react', 'react-*'], // [!code ++]
+ } // [!code ++]
+ }, // [!code ++]
+ customGroups: { // [!code ++]
+ value: { // [!code ++]
+ react: ['^react$', '^react-.+'], // [!code ++]
+ lodash: 'lodash', // [!code ++]
+ }, // [!code ++]
+ type: { // [!code ++]
+ react: ['^react$', '^react-.+'], // [!code ++]
+ } // [!code ++]
+ }, // [!code ++]
}
```

### matcher

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

Determines the matcher used for patterns in the `internalPattern` and `customGroups` options.

- `'minimatch'` — Use the [minimatch](https://github.com/isaacs/minimatch) library for pattern matching.
- `'regex'` — Use regular expressions for pattern matching.

### environment

<sub>default: `'node'`</sub>
Expand Down Expand Up @@ -368,11 +357,9 @@ Specifies which environment’s built-in modules should be recognized. If you ar
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
internalPattern: ['~/**'],
internalPattern: ['^~/.+'],
newlinesBetween: 'always',
maxLineLength: undefined,
matcher: 'minimatch',
groups: [
'type',
['builtin', 'external'],
Expand Down Expand Up @@ -409,11 +396,9 @@ Specifies which environment’s built-in modules should be recognized. If you ar
order: 'asc',
ignoreCase: true,
specialCharacters: 'keep',
matcher: 'minimatch',
internalPattern: ['~/**'],
internalPattern: ['^~/.+'],
newlinesBetween: 'always',
maxLineLength: undefined,
matcher: 'minimatch',
groups: [
'type',
['builtin', 'external'],
Expand Down
Loading

0 comments on commit e240971

Please sign in to comment.