eslint-plugin-perfectionist 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json.js +1 -1
- package/dist/rules/sort-classes/is-known-class-element.d.ts +13 -0
- package/dist/rules/sort-classes/is-known-class-element.js +17 -0
- package/dist/rules/sort-classes.js +4 -0
- package/dist/rules/sort-objects/passes-declaration-comment-matches-filter.js +10 -2
- package/dist/rules/sort-union-types/compute-node-name.d.ts +21 -0
- package/dist/rules/sort-union-types/compute-node-name.js +12 -0
- package/dist/rules/sort-union-types.js +5 -1
- package/dist/utils/compute-group.d.ts +2 -4
- package/dist/utils/report-all-errors.d.ts +0 -3
- package/package.json +3 -3
package/dist/package.json.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a class element is supported by the sort-classes rule.
|
|
4
|
+
*
|
|
5
|
+
* Unknown elements should be ignored to avoid crashes with non-standard parsers
|
|
6
|
+
* while letting known elements keep their ordering behavior.
|
|
7
|
+
*
|
|
8
|
+
* @param member - The class element to check.
|
|
9
|
+
* @returns True when the element is a known, supported class member.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isKnownClassElement(
|
|
12
|
+
member: TSESTree.ClassElement,
|
|
13
|
+
): boolean
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
function isKnownClassElement(member) {
|
|
3
|
+
switch (member.type) {
|
|
4
|
+
case AST_NODE_TYPES.TSAbstractPropertyDefinition:
|
|
5
|
+
case AST_NODE_TYPES.TSAbstractMethodDefinition:
|
|
6
|
+
case AST_NODE_TYPES.TSAbstractAccessorProperty:
|
|
7
|
+
case AST_NODE_TYPES.PropertyDefinition:
|
|
8
|
+
case AST_NODE_TYPES.MethodDefinition:
|
|
9
|
+
case AST_NODE_TYPES.AccessorProperty:
|
|
10
|
+
case AST_NODE_TYPES.TSIndexSignature:
|
|
11
|
+
case AST_NODE_TYPES.StaticBlock:
|
|
12
|
+
return true
|
|
13
|
+
default:
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { isKnownClassElement }
|
|
@@ -39,6 +39,7 @@ import { validateGroupsConfiguration } from '../utils/validate-groups-configurat
|
|
|
39
39
|
import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js'
|
|
40
40
|
import { sortNodesByDependencies } from '../utils/sort-nodes-by-dependencies.js'
|
|
41
41
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
42
|
+
import { isKnownClassElement } from './sort-classes/is-known-class-element.js'
|
|
42
43
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
43
44
|
import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
44
45
|
import { UnreachableCaseError } from '../utils/unreachable-case-error.js'
|
|
@@ -127,6 +128,9 @@ const sortClasses = createEslintRule({
|
|
|
127
128
|
let className = classBody.parent.id?.name
|
|
128
129
|
let sortingNodeGroupsWithoutOverloadSignature = classBody.body.reduce(
|
|
129
130
|
(accumulator, member) => {
|
|
131
|
+
if (!isKnownClassElement(member)) {
|
|
132
|
+
return accumulator
|
|
133
|
+
}
|
|
130
134
|
let dependencies = []
|
|
131
135
|
let isDecorated = false
|
|
132
136
|
let decorators = []
|
|
@@ -17,8 +17,16 @@ function passesDeclarationCommentMatchesFilter({
|
|
|
17
17
|
function computeRelevantNodeForComment(objectParent) {
|
|
18
18
|
let objectParentType = objectParent.type
|
|
19
19
|
switch (objectParentType) {
|
|
20
|
-
case AST_NODE_TYPES.VariableDeclarator:
|
|
21
|
-
|
|
20
|
+
case AST_NODE_TYPES.VariableDeclarator: {
|
|
21
|
+
let variableDeclaration = objectParent.parent
|
|
22
|
+
if (
|
|
23
|
+
variableDeclaration.parent?.type ===
|
|
24
|
+
AST_NODE_TYPES.ExportNamedDeclaration
|
|
25
|
+
) {
|
|
26
|
+
return variableDeclaration.parent
|
|
27
|
+
}
|
|
28
|
+
return variableDeclaration
|
|
29
|
+
}
|
|
22
30
|
case AST_NODE_TYPES.CallExpression:
|
|
23
31
|
case AST_NODE_TYPES.Property:
|
|
24
32
|
return objectParent
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/types'
|
|
2
|
+
import { TSESLint } from '@typescript-eslint/utils'
|
|
3
|
+
/**
|
|
4
|
+
* Computes the name of a union/intersection member.
|
|
5
|
+
*
|
|
6
|
+
* Multi-line parenthesized unions/intersections can include leading `|` or `&`
|
|
7
|
+
* in raw source text, while formatter output often omits them. To keep sorting
|
|
8
|
+
* stable across both forms, the leading separator prefix is normalized.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Parameters object.
|
|
11
|
+
* @param params.sourceCode - ESLint source code object for text extraction.
|
|
12
|
+
* @param params.type - Type node represented by the member text.
|
|
13
|
+
* @returns Normalized member text used for sorting and matching.
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeNodeName({
|
|
16
|
+
sourceCode,
|
|
17
|
+
type,
|
|
18
|
+
}: {
|
|
19
|
+
sourceCode: TSESLint.SourceCode
|
|
20
|
+
type: TSESTree.TypeNode
|
|
21
|
+
}): string
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
|
|
2
|
+
function computeNodeName({ sourceCode, type }) {
|
|
3
|
+
let name = sourceCode.getText(type)
|
|
4
|
+
if (
|
|
5
|
+
type.type !== AST_NODE_TYPES.TSUnionType &&
|
|
6
|
+
type.type !== AST_NODE_TYPES.TSIntersectionType
|
|
7
|
+
) {
|
|
8
|
+
return name
|
|
9
|
+
}
|
|
10
|
+
return name.replace(/^\s*[&|]\s*/u, '')
|
|
11
|
+
}
|
|
12
|
+
export { computeNodeName }
|
|
@@ -24,6 +24,7 @@ import { generatePredefinedGroups } from '../utils/generate-predefined-groups.js
|
|
|
24
24
|
import { getEslintDisabledLines } from '../utils/get-eslint-disabled-lines.js'
|
|
25
25
|
import { isNodeEslintDisabled } from '../utils/is-node-eslint-disabled.js'
|
|
26
26
|
import { doesCustomGroupMatch } from '../utils/does-custom-group-match.js'
|
|
27
|
+
import { computeNodeName } from './sort-union-types/compute-node-name.js'
|
|
27
28
|
import { sortNodesByGroups } from '../utils/sort-nodes-by-groups.js'
|
|
28
29
|
import { createEslintRule } from '../utils/create-eslint-rule.js'
|
|
29
30
|
import { reportAllErrors } from '../utils/report-all-errors.js'
|
|
@@ -185,7 +186,10 @@ function sortUnionOrIntersectionTypes({
|
|
|
185
186
|
selectors.push('union')
|
|
186
187
|
break
|
|
187
188
|
}
|
|
188
|
-
let name =
|
|
189
|
+
let name = computeNodeName({
|
|
190
|
+
sourceCode,
|
|
191
|
+
type,
|
|
192
|
+
})
|
|
189
193
|
let predefinedGroups = generatePredefinedGroups({
|
|
190
194
|
cache: cachedGroupsByModifiersAndSelectors,
|
|
191
195
|
modifiers: [],
|
|
@@ -16,10 +16,8 @@ interface ComputeGroupParameters<CustomGroupMatchOptions> {
|
|
|
16
16
|
'customGroups' | 'groups'
|
|
17
17
|
>
|
|
18
18
|
/**
|
|
19
|
-
* Function to test if an element matches a custom group.
|
|
20
|
-
*
|
|
21
|
-
* @param customGroup - Custom group configuration to test against.
|
|
22
|
-
* @returns True if the element matches the custom group.
|
|
19
|
+
* Function to test if an element matches a custom group. Takes a custom
|
|
20
|
+
* group configuration and returns true if the element matches.
|
|
23
21
|
*/
|
|
24
22
|
customGroupMatcher: CustomGroupMatcher<CustomGroupMatchOptions>
|
|
25
23
|
/**
|
|
@@ -121,9 +121,6 @@ interface ReportAllErrorsParameters<
|
|
|
121
121
|
* return computedNewlinesBetween
|
|
122
122
|
* }
|
|
123
123
|
* ```
|
|
124
|
-
*
|
|
125
|
-
* @param params - Context for determining newlines.
|
|
126
|
-
* @returns Number of required newlines or 'ignore'.
|
|
127
124
|
*/
|
|
128
125
|
newlinesBetweenValueGetter?: NewlinesBetweenValueGetter<T>
|
|
129
126
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"./dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@typescript-eslint/utils": "^8.
|
|
32
|
+
"@typescript-eslint/utils": "^8.56.0",
|
|
33
33
|
"natural-orderby": "^5.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"eslint": "
|
|
36
|
+
"eslint": "^8.45.0 || ^9.0.0 || ^10.0.0"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": "^20.0.0 || >=22.0.0"
|