diff --git a/docs/content/rules/sort-array-includes.mdx b/docs/content/rules/sort-array-includes.mdx
index 44b59433f..40b1b26ca 100644
--- a/docs/content/rules/sort-array-includes.mdx
+++ b/docs/content/rules/sort-array-includes.mdx
@@ -447,7 +447,7 @@ This feature is only applicable when [`partitionByNewLine`](#partitionbynewline)
default: `[]`
-Defines custom groups to match specific object type members.
+Defines custom groups to match specific array elements.
A custom group definition may follow one of the two following interfaces:
@@ -523,11 +523,12 @@ Custom groups have a higher priority than any predefined group.
fallbackSort: { type: 'unsorted' },
ignoreCase: true,
specialCharacters: 'keep',
+ partitionByComment: false,
partitionByNewLine: false,
newlinesBetween: 'ignore',
newlinesInside: 'ignore',
useConfigurationIf: {},
- groups: ["literal"],
+ groups: ['literal'],
customGroups: [],
},
],
@@ -554,11 +555,12 @@ Custom groups have a higher priority than any predefined group.
fallbackSort: { type: 'unsorted' },
ignoreCase: true,
specialCharacters: 'keep',
+ partitionByComment: false,
partitionByNewLine: false,
newlinesBetween: 'ignore',
newlinesInside: 'ignore',
useConfigurationIf: {},
- groups: ["literal"],
+ groups: ['literal'],
customGroups: [],
},
],
diff --git a/docs/content/rules/sort-classes.mdx b/docs/content/rules/sort-classes.mdx
index e090652cb..03ca9e4b1 100644
--- a/docs/content/rules/sort-classes.mdx
+++ b/docs/content/rules/sort-classes.mdx
@@ -375,7 +375,7 @@ Without `ignoreCallbackDependenciesPatterns: ['^computed$']`, `role` and `userna
default: `{}`
-Specifies filters to match a particular options configuration for a given object.
+Specifies filters to match a particular options configuration for a given class.
The first matching options configuration will be used. If no configuration matches, the default options configuration will be used.
@@ -553,7 +553,7 @@ The `private` modifier will currently match any of the following:
Elements that are not `protected` nor `private` will be matched with the `public` modifier, even if the keyword is not present.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
the members will remain in their original order.
##### Behavior when multiple groups match an element
diff --git a/docs/content/rules/sort-decorators.mdx b/docs/content/rules/sort-decorators.mdx
index e6367deb9..594f7b264 100644
--- a/docs/content/rules/sort-decorators.mdx
+++ b/docs/content/rules/sort-decorators.mdx
@@ -319,7 +319,7 @@ Specifies a list of decorator groups for sorting.
Predefined groups:
-- `'unknown'` — Decorators that don’t fit into any group specified in the `groups` option.
+- `'unknown'` — Decorators that don't fit into any group specified in the `groups` option.
If the `unknown` group is not specified in the `groups` option, it will automatically be added to the end of the list.
diff --git a/docs/content/rules/sort-enums.mdx b/docs/content/rules/sort-enums.mdx
index 2418f9571..ce83f65af 100644
--- a/docs/content/rules/sort-enums.mdx
+++ b/docs/content/rules/sort-enums.mdx
@@ -364,7 +364,7 @@ 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.
-##### Group with overridden settings
+#### Group with overridden settings
You may directly override options for a specific group by using an object with the `group` property and other option overrides.
diff --git a/docs/content/rules/sort-exports.mdx b/docs/content/rules/sort-exports.mdx
index 5120c7bd4..6cf258a9f 100644
--- a/docs/content/rules/sort-exports.mdx
+++ b/docs/content/rules/sort-exports.mdx
@@ -131,7 +131,7 @@ Example: enforce alphabetical sort between two elements with the same length.
You can also sort by subgroup order (nested groups in the [`groups`](#groups) option) using `subgroup-order`.
-Example: When two exports tie on the primary sort key, sort type exports before value exports inside a subgroup.
+Example: when two exports tie on the primary sort key, sort type exports before value exports inside a subgroup.
```ts
{
groups: [['type-export', 'value-export']],
@@ -302,7 +302,7 @@ Example: `type-export`.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
##### Group with overridden settings
@@ -483,7 +483,6 @@ Custom groups have a higher priority than any predefined group.
lang="tsx"
/>
-
## Version
This rule was introduced in [v1.2.0](https://github.com/azat-io/eslint-plugin-perfectionist/releases/tag/v1.2.0).
diff --git a/docs/content/rules/sort-heritage-clauses.mdx b/docs/content/rules/sort-heritage-clauses.mdx
index 1978a7b71..ce57d8b06 100644
--- a/docs/content/rules/sort-heritage-clauses.mdx
+++ b/docs/content/rules/sort-heritage-clauses.mdx
@@ -232,7 +232,7 @@ Example configuration: don't sort heritage clauses of classes (only interfaces).
default: `false`
-Enables the use of comments to separate class decorators into logical groups.
+Enables the use of comments to separate heritage clauses into logical groups.
- `true` — All comments will be treated as delimiters, creating partitions.
- `false` — Comments will not be used as delimiters.
@@ -308,7 +308,7 @@ Specifies a list of heritage clause groups for sorting.
Predefined groups:
-- `'unknown'` — Heritage Clauses that don’t fit into any group specified in the `groups` option.
+- `'unknown'` — Heritage Clauses that don't fit into any group specified in the `groups` option.
If the `unknown` group is not specified in the `groups` option, it will automatically be added to the end of the list.
diff --git a/docs/content/rules/sort-imports.mdx b/docs/content/rules/sort-imports.mdx
index 52c8ee9ed..cd4486390 100644
--- a/docs/content/rules/sort-imports.mdx
+++ b/docs/content/rules/sort-imports.mdx
@@ -444,7 +444,7 @@ The list of modifiers is sorted from most to least important:
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
the members will remain in their original order.
##### Behavior when multiple groups match an element
@@ -713,7 +713,7 @@ you must write a custom group definition that does the same as what the predefin
default: `'node'`
-Specifies which environment’s built-in modules should be recognized. If you are using [Bun](https://bun.sh), change the value to `'bun'`.
+Specifies which environment's built-in modules should be recognized. If you are using [Bun](https://bun.sh), change the value to `'bun'`.
### useExperimentalDependencyDetection
diff --git a/docs/content/rules/sort-interfaces.mdx b/docs/content/rules/sort-interfaces.mdx
index 5b337501b..13830188a 100644
--- a/docs/content/rules/sort-interfaces.mdx
+++ b/docs/content/rules/sort-interfaces.mdx
@@ -546,7 +546,7 @@ Elements that are not `optional` will be matched with the `required` modifier, e
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
##### Behavior when multiple groups match an element
diff --git a/docs/content/rules/sort-intersection-types.mdx b/docs/content/rules/sort-intersection-types.mdx
index 5eea04a7d..8bd4ae854 100644
--- a/docs/content/rules/sort-intersection-types.mdx
+++ b/docs/content/rules/sort-intersection-types.mdx
@@ -11,7 +11,6 @@ keywords:
- typescript linting
- intersection types sorting
- typescript types
- - typescript linting
- typescript-eslint
---
@@ -315,6 +314,8 @@ To avoid unexpected behavior, do not use `:exit` or `:enter` pseudo-selectors.
default: `[]`
+Specifies a list of intersection type groups for sorting. Groups help organize types into categories, making your type definitions more readable and maintainable.
+
Each member will be assigned a single group specified in the `groups` option (or the `unknown` group if no match is found).
The order of items in the `groups` option determines how groups are ordered.
@@ -327,23 +328,23 @@ Predefined groups are characterized by a single selector.
##### Selectors
-- `'conditional`' — Conditional types.
-- `'function`' — Function types.
-- `'import`' — Imported types.
-- `'intersection`' — Intersection types.
-- `'keyword`' — Keyword types.
-- `'literal`' — Literal types.
-- `'named`' — Named types.
-- `'object`' — Object types.
-- `'operator`' — Operator types.
-- `'tuple`' — Tuple types.
-- `'union`' — Union types.
-- `'nullish`' — Nullish types (`null` or `undefined`).
-- `'unknown`' — Types that don’t fit into any group specified in the `groups` option.
+- `'conditional'` — Conditional types.
+- `'function'` — Function types.
+- `'import'` — Imported types.
+- `'intersection'` — Intersection types.
+- `'keyword'` — Keyword types.
+- `'literal'` — Literal types.
+- `'named'` — Named types.
+- `'object'` — Object types.
+- `'operator'` — Operator types.
+- `'tuple'` — Tuple types.
+- `'union'` — Union types.
+- `'nullish'` — Nullish types (`null` or `undefined`).
+- `'unknown'` — Types that don't fit into any group specified in the `groups` option.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
#### Example 1
@@ -473,7 +474,7 @@ This feature is only applicable when [`partitionByNewLine`](#partitionbynewline)
default: `[]`
-Defines custom groups to match specific object type members.
+Defines custom groups to match specific intersection type members.
A custom group definition may follow one of the two following interfaces:
@@ -489,7 +490,7 @@ interface CustomGroupDefinition {
}
```
-An type member will match a `CustomGroupDefinition` group if it matches all the filters of the custom group's definition.
+A type member will match a `CustomGroupDefinition` group if it matches all the filters of the custom group's definition.
or:
@@ -507,7 +508,7 @@ interface CustomGroupAnyOfDefinition {
}
```
-An type member will match a `CustomGroupAnyOfDefinition` group if it matches all the filters of at least one of the `anyOf` items.
+A type member will match a `CustomGroupAnyOfDefinition` group if it matches all the filters of at least one of the `anyOf` items.
#### Attributes
diff --git a/docs/content/rules/sort-jsx-props.mdx b/docs/content/rules/sort-jsx-props.mdx
index 47c9e2797..7951f3a95 100644
--- a/docs/content/rules/sort-jsx-props.mdx
+++ b/docs/content/rules/sort-jsx-props.mdx
@@ -402,7 +402,7 @@ All members of the groups in the array will be sorted together as if they were p
Predefined groups are characterized by a single selector and potentially multiple modifiers. You may enter modifiers in any order, but the selector must always come at the end.
-##### Selectors
+#### Selectors
The only selector possible for this rule is `'prop'`.
@@ -485,7 +485,7 @@ Current API:
default: `[]`
-Defines custom groups to match specific JSX prop.
+Defines custom groups to match specific JSX props.
A custom group definition may follow one of the two following interfaces:
diff --git a/docs/content/rules/sort-modules.mdx b/docs/content/rules/sort-modules.mdx
index 79f4731af..8bbde97cf 100644
--- a/docs/content/rules/sort-modules.mdx
+++ b/docs/content/rules/sort-modules.mdx
@@ -288,7 +288,7 @@ Enables the use of comments to separate the module members into logical groups.
default: `false`
-When `true`, the rule will not sort the members of a class if there is an empty line between them. This helps maintain the defined order of logically separated groups of members.
+When `true`, the rule will not sort the members of a module if there is an empty line between them. This helps maintain the defined order of logically separated groups of members.
```ts
// Group 1
@@ -440,7 +440,7 @@ Predefined groups are characterized by a single selector and potentially multipl
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
the members will remain in their original order.
##### Behavior when multiple groups match an element
diff --git a/docs/content/rules/sort-named-exports.mdx b/docs/content/rules/sort-named-exports.mdx
index 284ee8599..a5e7c5988 100644
--- a/docs/content/rules/sort-named-exports.mdx
+++ b/docs/content/rules/sort-named-exports.mdx
@@ -381,7 +381,7 @@ Example: `type-export`.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
##### Group with overridden settings
diff --git a/docs/content/rules/sort-named-imports.mdx b/docs/content/rules/sort-named-imports.mdx
index cae75cb91..a40dfc332 100644
--- a/docs/content/rules/sort-named-imports.mdx
+++ b/docs/content/rules/sort-named-imports.mdx
@@ -380,7 +380,7 @@ Example: `type-import`.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
##### Group with overridden settings
diff --git a/docs/content/rules/sort-object-types.mdx b/docs/content/rules/sort-object-types.mdx
index 1bdebe0b7..d765f0ea6 100644
--- a/docs/content/rules/sort-object-types.mdx
+++ b/docs/content/rules/sort-object-types.mdx
@@ -514,7 +514,7 @@ Elements that are not `optional` will be matched with the `required` modifier, e
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
##### Behavior when multiple groups match an element
diff --git a/docs/content/rules/sort-objects.mdx b/docs/content/rules/sort-objects.mdx
index 62b55ca40..eef17014b 100644
--- a/docs/content/rules/sort-objects.mdx
+++ b/docs/content/rules/sort-objects.mdx
@@ -272,7 +272,7 @@ Enables the use of comments to separate the keys of objects into logical groups.
default: `false`
-When `true`, the rule will not sort the object’s keys if there is an empty line between them. This helps maintain the defined order of logically separated groups of keys.
+When `true`, the rule will not sort the object's keys if there is an empty line between them. This helps maintain the defined order of logically separated groups of keys.
```ts
const user = {
@@ -626,7 +626,7 @@ let user = {
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
#### Important notes
diff --git a/docs/content/rules/sort-sets.mdx b/docs/content/rules/sort-sets.mdx
index 1768bc164..57f10aae4 100644
--- a/docs/content/rules/sort-sets.mdx
+++ b/docs/content/rules/sort-sets.mdx
@@ -85,8 +85,6 @@ By keeping sets sorted, developers can quickly scan and verify the values, makin
return 'Unknown'
}
`}
- client:load
- lang="tsx"
initial={dedent`
const getProductCategories = (product) => {
let electronics = new Set([
@@ -118,6 +116,8 @@ By keeping sets sorted, developers can quickly scan and verify the values, makin
return 'Unknown'
}
`}
+ client:load
+ lang="tsx"
/>
## Options
@@ -528,6 +528,7 @@ Custom groups have a higher priority than any predefined group.
fallbackSort: { type: 'unsorted' },
ignoreCase: true,
specialCharacters: 'keep',
+ partitionByComment: false,
partitionByNewLine: false,
newlinesBetween: 'ignore',
newlinesInside: 'ignore',
@@ -559,6 +560,7 @@ Custom groups have a higher priority than any predefined group.
fallbackSort: { type: 'unsorted' },
ignoreCase: true,
specialCharacters: 'keep',
+ partitionByComment: false,
partitionByNewLine: false,
newlinesBetween: 'ignore',
newlinesInside: 'ignore',
diff --git a/docs/content/rules/sort-union-types.mdx b/docs/content/rules/sort-union-types.mdx
index d8eea97f6..8791fd9ec 100644
--- a/docs/content/rules/sort-union-types.mdx
+++ b/docs/content/rules/sort-union-types.mdx
@@ -11,12 +11,10 @@ keywords:
- typescript linting
- union types sorting
- typescript types
- - typescript linting
- typescript-eslint
- typescript union types
- typescript union type sorting
- typescript union type members
- - typescript union type sorting
- typescript union type members sorting
---
@@ -361,11 +359,11 @@ Predefined groups are characterized by a single selector.
- `'tuple'` — Tuple types.
- `'union'` — Union types.
- `'nullish'` — Nullish types (`null` or `undefined`).
-- `'unknown'` — Types that don’t fit into any group entered by the user.
+- `'unknown'` — Types that don't fit into any group entered by the user.
##### The `unknown` group
-Members that don’t fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
+Members that don't fit into any group specified in the `groups` option will be placed in the `unknown` group. If the `unknown` group is not specified in the `groups` option,
it will automatically be added to the end of the list.
#### Example 1
@@ -495,7 +493,7 @@ This feature is only applicable when [`partitionByNewLine`](#partitionbynewline)
default: `[]`
-Defines custom groups to match specific object type members.
+Defines custom groups to match specific union type members.
A custom group definition may follow one of the two following interfaces:
@@ -511,7 +509,7 @@ interface CustomGroupDefinition {
}
```
-An type member will match a `CustomGroupDefinition` group if it matches all the filters of the custom group's definition.
+A type member will match a `CustomGroupDefinition` group if it matches all the filters of the custom group's definition.
or:
@@ -529,7 +527,7 @@ interface CustomGroupAnyOfDefinition {
}
```
-An type member will match a `CustomGroupAnyOfDefinition` group if it matches all the filters of at least one of the `anyOf` items.
+A type member will match a `CustomGroupAnyOfDefinition` group if it matches all the filters of at least one of the `anyOf` items.
#### Attributes
diff --git a/test/utils/context-matching/filter-options-by-all-names-match.test.ts b/test/utils/context-matching/passes-all-names-match-pattern-filter.test.ts
similarity index 100%
rename from test/utils/context-matching/filter-options-by-all-names-match.test.ts
rename to test/utils/context-matching/passes-all-names-match-pattern-filter.test.ts
diff --git a/test/utils/context-matching/passes-ast-selector-filter.test.ts b/test/utils/context-matching/passes-ast-selector-filter.test.ts
new file mode 100644
index 000000000..be6771bd5
--- /dev/null
+++ b/test/utils/context-matching/passes-ast-selector-filter.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from 'vitest'
+
+import { passesAstSelectorFilter } from '../../../utils/context-matching/passes-ast-selector-filter'
+
+describe('passes-ast-selector-filter', () => {
+ it.each([undefined, ''])(
+ 'returns true if `matchesAstSelector` is %s',
+ matchesAstSelector => {
+ let matchedAstSelectors = new Set(['TSTypeAnnotation'])
+
+ expect(
+ passesAstSelectorFilter({ matchedAstSelectors, matchesAstSelector }),
+ ).toBeTruthy()
+ },
+ )
+
+ it('returns true if `matchedAstSelectors` contains `matchesAstSelector`', () => {
+ let matchedAstSelectors = new Set(['TSTypeAnnotation', 'ClassBody'])
+
+ expect(
+ passesAstSelectorFilter({
+ matchesAstSelector: 'TSTypeAnnotation',
+ matchedAstSelectors,
+ }),
+ ).toBeTruthy()
+ })
+
+ it('returns false if `matchedAstSelectors` does not contain `matchesAstSelector`', () => {
+ let matchedAstSelectors = new Set(['TSTypeAnnotation'])
+
+ expect(
+ passesAstSelectorFilter({
+ matchesAstSelector: 'ClassBody',
+ matchedAstSelectors,
+ }),
+ ).toBeFalsy()
+ })
+})
diff --git a/test/utils/scoped-regex/partition-patterns-by-scope.test.ts b/test/utils/scoped-regex/partition-patterns-by-scope.test.ts
new file mode 100644
index 000000000..7acc2c057
--- /dev/null
+++ b/test/utils/scoped-regex/partition-patterns-by-scope.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from 'vitest'
+
+import { partitionPatternsByScope } from '../../../utils/scoped-regex/partition-patterns-by-scope'
+
+describe('partition-patterns-by-scope', () => {
+ it('puts a string pattern into shallowScopePatterns', () => {
+ expect(partitionPatternsByScope('foo')).toEqual({
+ shallowScopePatterns: ['foo'],
+ deepScopePatterns: [],
+ })
+ })
+
+ it('puts an object pattern without scope into shallowScopePatterns', () => {
+ let pattern = { pattern: 'foo', flags: 'i' }
+
+ expect(partitionPatternsByScope(pattern)).toEqual({
+ shallowScopePatterns: [pattern],
+ deepScopePatterns: [],
+ })
+ })
+
+ it('puts an object pattern with shallow scope into shallowScopePatterns', () => {
+ let pattern = { scope: 'shallow' as const, pattern: 'foo' }
+
+ expect(partitionPatternsByScope(pattern)).toEqual({
+ shallowScopePatterns: [pattern],
+ deepScopePatterns: [],
+ })
+ })
+
+ it('puts an object pattern with deep scope into deepScopePatterns', () => {
+ let pattern = { scope: 'deep' as const, pattern: 'foo' }
+
+ expect(partitionPatternsByScope(pattern)).toEqual({
+ deepScopePatterns: [pattern],
+ shallowScopePatterns: [],
+ })
+ })
+
+ it('partitions an array of mixed patterns by scope', () => {
+ let shallowString = 'foo'
+ let shallowObject = { pattern: 'bar', flags: 'i' }
+ let deepObject = { scope: 'deep' as const, pattern: 'baz' }
+
+ expect(
+ partitionPatternsByScope([shallowString, shallowObject, deepObject]),
+ ).toEqual({
+ shallowScopePatterns: [shallowString, shallowObject],
+ deepScopePatterns: [deepObject],
+ })
+ })
+})