Skip to content

Commit

Permalink
feat: add matcher option
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Sep 30, 2024
1 parent a11841a commit 9434334
Show file tree
Hide file tree
Showing 62 changed files with 1,260 additions and 157 deletions.
9 changes: 9 additions & 0 deletions docs/content/rules/sort-array-includes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ if ([
}
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-astro-attributes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ Example:
}
```

### 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

In order to start using this rule, you need to install additional dependency:
Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,15 @@ Example:
}
```

### 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.

## Usage

<CodeTabs
Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-enums.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ enum Enum {
}
```

### 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
8 changes: 8 additions & 0 deletions docs/content/rules/sort-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ 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

Expand Down
13 changes: 12 additions & 1 deletion docs/content/rules/sort-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Controls whether sorting should be case-sensitive or not.

### internalPattern

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

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

Expand Down Expand Up @@ -292,6 +292,15 @@ Example:
}
```

### 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 @@ -319,6 +328,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar
type: 'alphabetical',
order: 'asc',
ignoreCase: true,
matcher: 'minimatch',
internalPattern: ['~/**'],
newlinesBetween: 'always',
maxLineLength: undefined,
Expand Down Expand Up @@ -357,6 +367,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar
type: 'alphabetical',
order: 'asc',
ignoreCase: true,
matcher: 'minimatch',
internalPattern: ['~/**'],
newlinesBetween: 'always',
maxLineLength: undefined,
Expand Down
8 changes: 8 additions & 0 deletions docs/content/rules/sort-interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ Example:
}
```

### matcher

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

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

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

## Usage

Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-intersection-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ type Example =
& undefined;
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-jsx-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ Example:
}
```

### 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 Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-maps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ new Map([
])
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-named-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ export {
} from './devices'
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-object-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ Example:
}
```

### 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.

## Usage

<CodeTabs
Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ You can define your own groups for object keys using custom glob patterns for ma
}
```

### 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.

## Usage

<CodeTabs
Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-sets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ let items = new Set([
])
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-svelte-attributes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ Example:
}
```

### 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

In order to start using this rule, you need to install additional dependency:
Expand Down
9 changes: 9 additions & 0 deletions docs/content/rules/sort-union-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ groups: [
],
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-variable-declarations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ const
ford = "Ford"
```

### 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
9 changes: 9 additions & 0 deletions docs/content/rules/sort-vue-attributes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ Example:
}
```

### 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

In order to start using this rule, you need to install additional dependency:
Expand Down
13 changes: 10 additions & 3 deletions rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Options = [
groupKind: 'literals-first' | 'spreads-first' | 'mixed'
type: 'alphabetical' | 'line-length' | 'natural'
partitionByComment: string[] | boolean | string
matcher: 'minimatch' | 'regex'
partitionByNewLine: boolean
order: 'desc' | 'asc'
ignoreCase: boolean
Expand All @@ -47,6 +48,11 @@ export let jsonSchema: JSONSchema4 = {
type: 'string',
enum: ['asc', 'desc'],
},
matcher: {
description: 'Specifies the string matcher.',
type: 'string',
enum: ['minimatch', 'regex'],
},
ignoreCase: {
description: 'Controls whether sorting should be case-sensitive or not.',
type: 'boolean',
Expand Down Expand Up @@ -102,6 +108,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
type: 'alphabetical',
order: 'asc',
ignoreCase: true,
matcher: 'minimatch',
groupKind: 'literals-first',
partitionByComment: false,
partitionByNewLine: false,
Expand Down Expand Up @@ -137,6 +144,7 @@ export let sortArray = <MessageIds extends string>(
groupKind: 'literals-first',
type: 'alphabetical',
ignoreCase: true,
matcher: 'minimatch',
order: 'asc',
partitionByComment: false,
partitionByNewLine: false,
Expand Down Expand Up @@ -171,6 +179,7 @@ export let sortArray = <MessageIds extends string>(
hasPartitionComment(
partitionComment,
getCommentsBefore(element, sourceCode),
options.matcher,
)) ||
(options.partitionByNewLine &&
lastSortingNode &&
Expand Down Expand Up @@ -221,9 +230,7 @@ export let sortArray = <MessageIds extends string>(
.flat()
: sortNodes(nodes, options)

return makeFixes(fixer, nodes, sortedNodes, sourceCode, {
partitionComment,
})
return makeFixes(fixer, nodes, sortedNodes, sourceCode, options)
},
})
}
Expand Down
Loading

0 comments on commit 9434334

Please sign in to comment.