eslint-plugin-perfectionist 3.1.3 → 3.3.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/index.d.ts +13 -9
- package/dist/rules/sort-array-includes.js +3 -1
- package/dist/rules/sort-array-includes.mjs +3 -1
- package/dist/rules/sort-astro-attributes.js +3 -1
- package/dist/rules/sort-astro-attributes.mjs +3 -1
- package/dist/rules/sort-classes-utils.js +99 -0
- package/dist/rules/sort-classes-utils.mjs +96 -0
- package/dist/rules/sort-classes.js +154 -77
- package/dist/rules/sort-classes.mjs +158 -77
- package/dist/rules/sort-enums.js +93 -6
- package/dist/rules/sort-enums.mjs +89 -6
- package/dist/rules/sort-exports.js +3 -1
- package/dist/rules/sort-exports.mjs +3 -1
- package/dist/rules/sort-imports.js +3 -1
- package/dist/rules/sort-imports.mjs +3 -1
- package/dist/rules/sort-interfaces.js +3 -1
- package/dist/rules/sort-interfaces.mjs +3 -1
- package/dist/rules/sort-intersection-types.js +3 -1
- package/dist/rules/sort-intersection-types.mjs +3 -1
- package/dist/rules/sort-jsx-props.js +3 -1
- package/dist/rules/sort-jsx-props.mjs +3 -1
- package/dist/rules/sort-maps.js +3 -1
- package/dist/rules/sort-maps.mjs +3 -1
- package/dist/rules/sort-named-exports.js +3 -1
- package/dist/rules/sort-named-exports.mjs +3 -1
- package/dist/rules/sort-named-imports.js +3 -1
- package/dist/rules/sort-named-imports.mjs +3 -1
- package/dist/rules/sort-object-types.js +3 -1
- package/dist/rules/sort-object-types.mjs +3 -1
- package/dist/rules/sort-objects.js +3 -1
- package/dist/rules/sort-objects.mjs +3 -1
- package/dist/rules/sort-svelte-attributes.js +3 -1
- package/dist/rules/sort-svelte-attributes.mjs +3 -1
- package/dist/rules/sort-switch-case.js +9 -4
- package/dist/rules/sort-switch-case.mjs +9 -4
- package/dist/rules/sort-union-types.js +3 -1
- package/dist/rules/sort-union-types.mjs +3 -1
- package/dist/rules/sort-variable-declarations.js +3 -1
- package/dist/rules/sort-variable-declarations.mjs +3 -1
- package/dist/rules/sort-vue-attributes.js +2 -1
- package/dist/rules/sort-vue-attributes.mjs +2 -1
- package/dist/utils/compare.js +12 -7
- package/dist/utils/compare.mjs +12 -7
- package/dist/utils/complete.js +2 -1
- package/dist/utils/complete.mjs +2 -1
- package/dist/utils/get-settings.js +30 -0
- package/dist/utils/get-settings.mjs +28 -0
- package/dist/utils/use-groups.js +2 -1
- package/dist/utils/use-groups.mjs +2 -1
- package/package.json +3 -3
package/dist/utils/compare.js
CHANGED
|
@@ -10,11 +10,16 @@ let compare = (a, b, options) => {
|
|
|
10
10
|
}
|
|
11
11
|
let orderCoefficient = options.order === 'asc' ? 1 : -1
|
|
12
12
|
let sortingFunction
|
|
13
|
-
let formatString =
|
|
14
|
-
options.
|
|
13
|
+
let formatString =
|
|
14
|
+
options.type === 'line-length' || !options.ignoreCase
|
|
15
|
+
? string => string
|
|
16
|
+
: string => string.toLowerCase()
|
|
17
|
+
let nodeValueGetter = options.nodeValueGetter ?? (node => node.name)
|
|
15
18
|
if (options.type === 'alphabetical') {
|
|
16
19
|
sortingFunction = (aNode, bNode) =>
|
|
17
|
-
formatString(aNode
|
|
20
|
+
formatString(nodeValueGetter(aNode)).localeCompare(
|
|
21
|
+
formatString(nodeValueGetter(bNode)),
|
|
22
|
+
)
|
|
18
23
|
} else if (options.type === 'natural') {
|
|
19
24
|
let prepareNumeric = string => {
|
|
20
25
|
let formattedNumberPattern = /^[+-]?[\d ,_]+(\.[\d ,_]+)?$/
|
|
@@ -25,8 +30,8 @@ let compare = (a, b, options) => {
|
|
|
25
30
|
}
|
|
26
31
|
sortingFunction = (aNode, bNode) =>
|
|
27
32
|
naturalCompare(
|
|
28
|
-
prepareNumeric(formatString(aNode
|
|
29
|
-
prepareNumeric(formatString(bNode
|
|
33
|
+
prepareNumeric(formatString(nodeValueGetter(aNode))),
|
|
34
|
+
prepareNumeric(formatString(nodeValueGetter(bNode))),
|
|
30
35
|
)
|
|
31
36
|
} else {
|
|
32
37
|
sortingFunction = (aNode, bNode) => {
|
|
@@ -37,10 +42,10 @@ let compare = (a, b, options) => {
|
|
|
37
42
|
let isTooLong = (size, node) =>
|
|
38
43
|
size > maxLineLength && node.hasMultipleImportDeclarations
|
|
39
44
|
if (isTooLong(aSize, aNode)) {
|
|
40
|
-
aSize = aNode.
|
|
45
|
+
aSize = nodeValueGetter(aNode).length + 10
|
|
41
46
|
}
|
|
42
47
|
if (isTooLong(bSize, bNode)) {
|
|
43
|
-
bSize = bNode.
|
|
48
|
+
bSize = nodeValueGetter(bNode).length + 10
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
return aSize - bSize
|
package/dist/utils/compare.mjs
CHANGED
|
@@ -8,11 +8,16 @@ let compare = (a, b, options) => {
|
|
|
8
8
|
}
|
|
9
9
|
let orderCoefficient = options.order === 'asc' ? 1 : -1
|
|
10
10
|
let sortingFunction
|
|
11
|
-
let formatString =
|
|
12
|
-
options.
|
|
11
|
+
let formatString =
|
|
12
|
+
options.type === 'line-length' || !options.ignoreCase
|
|
13
|
+
? string => string
|
|
14
|
+
: string => string.toLowerCase()
|
|
15
|
+
let nodeValueGetter = options.nodeValueGetter ?? (node => node.name)
|
|
13
16
|
if (options.type === 'alphabetical') {
|
|
14
17
|
sortingFunction = (aNode, bNode) =>
|
|
15
|
-
formatString(aNode
|
|
18
|
+
formatString(nodeValueGetter(aNode)).localeCompare(
|
|
19
|
+
formatString(nodeValueGetter(bNode)),
|
|
20
|
+
)
|
|
16
21
|
} else if (options.type === 'natural') {
|
|
17
22
|
let prepareNumeric = string => {
|
|
18
23
|
let formattedNumberPattern = /^[+-]?[\d ,_]+(\.[\d ,_]+)?$/
|
|
@@ -23,8 +28,8 @@ let compare = (a, b, options) => {
|
|
|
23
28
|
}
|
|
24
29
|
sortingFunction = (aNode, bNode) =>
|
|
25
30
|
naturalCompare(
|
|
26
|
-
prepareNumeric(formatString(aNode
|
|
27
|
-
prepareNumeric(formatString(bNode
|
|
31
|
+
prepareNumeric(formatString(nodeValueGetter(aNode))),
|
|
32
|
+
prepareNumeric(formatString(nodeValueGetter(bNode))),
|
|
28
33
|
)
|
|
29
34
|
} else {
|
|
30
35
|
sortingFunction = (aNode, bNode) => {
|
|
@@ -35,10 +40,10 @@ let compare = (a, b, options) => {
|
|
|
35
40
|
let isTooLong = (size, node) =>
|
|
36
41
|
size > maxLineLength && node.hasMultipleImportDeclarations
|
|
37
42
|
if (isTooLong(aSize, aNode)) {
|
|
38
|
-
aSize = aNode.
|
|
43
|
+
aSize = nodeValueGetter(aNode).length + 10
|
|
39
44
|
}
|
|
40
45
|
if (isTooLong(bSize, bNode)) {
|
|
41
|
-
bSize = bNode.
|
|
46
|
+
bSize = nodeValueGetter(bNode).length + 10
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
return aSize - bSize
|
package/dist/utils/complete.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
-
let complete = (options = {},
|
|
3
|
+
let complete = (options = {}, settings = {}, defaults) =>
|
|
4
|
+
Object.assign(defaults, settings, options)
|
|
4
5
|
exports.complete = complete
|
package/dist/utils/complete.mjs
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
3
|
+
let getSettings = (settings = {}) => {
|
|
4
|
+
if (!settings.perfectionist) {
|
|
5
|
+
return {}
|
|
6
|
+
}
|
|
7
|
+
let validateOptions = object => {
|
|
8
|
+
let allowedOptions = [
|
|
9
|
+
'partitionByComment',
|
|
10
|
+
'partitionByNewLine',
|
|
11
|
+
'ignorePattern',
|
|
12
|
+
'ignoreCase',
|
|
13
|
+
'order',
|
|
14
|
+
'type',
|
|
15
|
+
]
|
|
16
|
+
let keys = Object.keys(object)
|
|
17
|
+
for (let key of keys) {
|
|
18
|
+
if (!allowedOptions.includes(key)) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
let perfectionistSettings = settings.perfectionist
|
|
25
|
+
if (!validateOptions(perfectionistSettings)) {
|
|
26
|
+
throw new Error('Invalid Perfectionist settings')
|
|
27
|
+
}
|
|
28
|
+
return settings.perfectionist
|
|
29
|
+
}
|
|
30
|
+
exports.getSettings = getSettings
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let getSettings = (settings = {}) => {
|
|
2
|
+
if (!settings.perfectionist) {
|
|
3
|
+
return {}
|
|
4
|
+
}
|
|
5
|
+
let validateOptions = object => {
|
|
6
|
+
let allowedOptions = [
|
|
7
|
+
'partitionByComment',
|
|
8
|
+
'partitionByNewLine',
|
|
9
|
+
'ignorePattern',
|
|
10
|
+
'ignoreCase',
|
|
11
|
+
'order',
|
|
12
|
+
'type',
|
|
13
|
+
]
|
|
14
|
+
let keys = Object.keys(object)
|
|
15
|
+
for (let key of keys) {
|
|
16
|
+
if (!allowedOptions.includes(key)) {
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
let perfectionistSettings = settings.perfectionist
|
|
23
|
+
if (!validateOptions(perfectionistSettings)) {
|
|
24
|
+
throw new Error('Invalid Perfectionist settings')
|
|
25
|
+
}
|
|
26
|
+
return settings.perfectionist
|
|
27
|
+
}
|
|
28
|
+
export { getSettings }
|
package/dist/utils/use-groups.js
CHANGED
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
|
3
3
|
const minimatch = require('minimatch')
|
|
4
4
|
let useGroups = groups => {
|
|
5
5
|
let group
|
|
6
|
+
let groupsSet = new Set(groups.flat())
|
|
6
7
|
let defineGroup = (value, override = false) => {
|
|
7
|
-
if ((!group || override) &&
|
|
8
|
+
if ((!group || override) && groupsSet.has(value)) {
|
|
8
9
|
group = value
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { minimatch } from 'minimatch'
|
|
2
2
|
let useGroups = groups => {
|
|
3
3
|
let group
|
|
4
|
+
let groupsSet = new Set(groups.flat())
|
|
4
5
|
let defineGroup = (value, override = false) => {
|
|
5
|
-
if ((!group || override) &&
|
|
6
|
+
if ((!group || override) && groupsSet.has(value)) {
|
|
6
7
|
group = value
|
|
7
8
|
}
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
3
|
"description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"homepage": "https://perfectionist.dev",
|
|
6
6
|
"repository": "azat-io/eslint-plugin-perfectionist",
|
|
7
7
|
"author": "Azat S. <to@azat.io>",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"vue-eslint-parser": ">=9.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@typescript-eslint/types": "^8.0
|
|
57
|
-
"@typescript-eslint/utils": "^8.0
|
|
56
|
+
"@typescript-eslint/types": "^8.3.0",
|
|
57
|
+
"@typescript-eslint/utils": "^8.3.0",
|
|
58
58
|
"minimatch": "^10.0.1",
|
|
59
59
|
"natural-compare-lite": "^1.4.0"
|
|
60
60
|
}
|