eslint-plugin-perfectionist 3.1.2 → 3.2.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 +14 -10
- 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 +68 -0
- package/dist/rules/sort-classes-utils.mjs +66 -0
- package/dist/rules/sort-classes.js +106 -57
- package/dist/rules/sort-classes.mjs +106 -57
- package/dist/rules/sort-enums.js +62 -6
- package/dist/rules/sort-enums.mjs +58 -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 +3 -1
- package/dist/rules/sort-switch-case.mjs +3 -1
- 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 +4 -4
package/dist/rules/sort-maps.js
CHANGED
|
@@ -3,6 +3,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
3
3
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
4
4
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
5
5
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
6
|
+
const getSettings = require('../utils/get-settings.js')
|
|
6
7
|
const isPositive = require('../utils/is-positive.js')
|
|
7
8
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
8
9
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -65,7 +66,8 @@ const sortMaps = createEslintRule.createEslintRule({
|
|
|
65
66
|
) {
|
|
66
67
|
let [{ elements }] = node.arguments
|
|
67
68
|
if (elements.length > 1) {
|
|
68
|
-
let
|
|
69
|
+
let settings = getSettings.getSettings(context.settings)
|
|
70
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
69
71
|
type: 'alphabetical',
|
|
70
72
|
ignoreCase: true,
|
|
71
73
|
order: 'asc',
|
package/dist/rules/sort-maps.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
2
2
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
3
3
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
4
4
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
5
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
5
6
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
6
7
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
7
8
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -64,7 +65,8 @@ const sortMaps = createEslintRule({
|
|
|
64
65
|
) {
|
|
65
66
|
let [{ elements }] = node.arguments
|
|
66
67
|
if (elements.length > 1) {
|
|
67
|
-
let
|
|
68
|
+
let settings = getSettings(context.settings)
|
|
69
|
+
let options = complete(context.options.at(0), settings, {
|
|
68
70
|
type: 'alphabetical',
|
|
69
71
|
ignoreCase: true,
|
|
70
72
|
order: 'asc',
|
|
@@ -3,6 +3,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
3
3
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
4
4
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
5
5
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
6
|
+
const getSettings = require('../utils/get-settings.js')
|
|
6
7
|
const isPositive = require('../utils/is-positive.js')
|
|
7
8
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
8
9
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -62,7 +63,8 @@ const sortNamedExports = createEslintRule.createEslintRule({
|
|
|
62
63
|
create: context => ({
|
|
63
64
|
ExportNamedDeclaration: node => {
|
|
64
65
|
if (node.specifiers.length > 1) {
|
|
65
|
-
let
|
|
66
|
+
let settings = getSettings.getSettings(context.settings)
|
|
67
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
66
68
|
type: 'alphabetical',
|
|
67
69
|
groupKind: 'mixed',
|
|
68
70
|
ignoreCase: true,
|
|
@@ -2,6 +2,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
2
2
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
3
3
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
4
4
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
5
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
5
6
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
6
7
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
7
8
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -61,7 +62,8 @@ const sortNamedExports = createEslintRule({
|
|
|
61
62
|
create: context => ({
|
|
62
63
|
ExportNamedDeclaration: node => {
|
|
63
64
|
if (node.specifiers.length > 1) {
|
|
64
|
-
let
|
|
65
|
+
let settings = getSettings(context.settings)
|
|
66
|
+
let options = complete(context.options.at(0), settings, {
|
|
65
67
|
type: 'alphabetical',
|
|
66
68
|
groupKind: 'mixed',
|
|
67
69
|
ignoreCase: true,
|
|
@@ -3,6 +3,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
3
3
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
4
4
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
5
5
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
6
|
+
const getSettings = require('../utils/get-settings.js')
|
|
6
7
|
const isPositive = require('../utils/is-positive.js')
|
|
7
8
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
8
9
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -70,7 +71,8 @@ const sortNamedImports = createEslintRule.createEslintRule({
|
|
|
70
71
|
({ type }) => type === 'ImportSpecifier',
|
|
71
72
|
)
|
|
72
73
|
if (specifiers.length > 1) {
|
|
73
|
-
let
|
|
74
|
+
let settings = getSettings.getSettings(context.settings)
|
|
75
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
74
76
|
type: 'alphabetical',
|
|
75
77
|
ignoreAlias: false,
|
|
76
78
|
groupKind: 'mixed',
|
|
@@ -2,6 +2,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
2
2
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
3
3
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
4
4
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
5
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
5
6
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
6
7
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
7
8
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -69,7 +70,8 @@ const sortNamedImports = createEslintRule({
|
|
|
69
70
|
({ type }) => type === 'ImportSpecifier',
|
|
70
71
|
)
|
|
71
72
|
if (specifiers.length > 1) {
|
|
72
|
-
let
|
|
73
|
+
let settings = getSettings(context.settings)
|
|
74
|
+
let options = complete(context.options.at(0), settings, {
|
|
73
75
|
type: 'alphabetical',
|
|
74
76
|
ignoreAlias: false,
|
|
75
77
|
groupKind: 'mixed',
|
|
@@ -5,6 +5,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
5
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
6
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
7
7
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
8
|
+
const getSettings = require('../utils/get-settings.js')
|
|
8
9
|
const isPositive = require('../utils/is-positive.js')
|
|
9
10
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
10
11
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -107,7 +108,8 @@ const sortObjectTypes = createEslintRule.createEslintRule({
|
|
|
107
108
|
create: context => ({
|
|
108
109
|
TSTypeLiteral: node => {
|
|
109
110
|
if (node.members.length > 1) {
|
|
110
|
-
let
|
|
111
|
+
let settings = getSettings.getSettings(context.settings)
|
|
112
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
111
113
|
partitionByNewLine: false,
|
|
112
114
|
type: 'alphabetical',
|
|
113
115
|
groupKind: 'mixed',
|
|
@@ -4,6 +4,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
4
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
5
5
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
6
6
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
7
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
7
8
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
8
9
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
9
10
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -106,7 +107,8 @@ const sortObjectTypes = createEslintRule({
|
|
|
106
107
|
create: context => ({
|
|
107
108
|
TSTypeLiteral: node => {
|
|
108
109
|
if (node.members.length > 1) {
|
|
109
|
-
let
|
|
110
|
+
let settings = getSettings(context.settings)
|
|
111
|
+
let options = complete(context.options.at(0), settings, {
|
|
110
112
|
partitionByNewLine: false,
|
|
111
113
|
type: 'alphabetical',
|
|
112
114
|
groupKind: 'mixed',
|
|
@@ -9,6 +9,7 @@ const getSourceCode = require('../utils/get-source-code.js')
|
|
|
9
9
|
const getNodeParent = require('../utils/get-node-parent.js')
|
|
10
10
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
11
11
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
12
|
+
const getSettings = require('../utils/get-settings.js')
|
|
12
13
|
const isPositive = require('../utils/is-positive.js')
|
|
13
14
|
const useGroups = require('../utils/use-groups.js')
|
|
14
15
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -141,7 +142,8 @@ const sortObjects = createEslintRule.createEslintRule({
|
|
|
141
142
|
],
|
|
142
143
|
create: context => {
|
|
143
144
|
let sortObject = node => {
|
|
144
|
-
let
|
|
145
|
+
let settings = getSettings.getSettings(context.settings)
|
|
146
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
145
147
|
partitionByNewLine: false,
|
|
146
148
|
partitionByComment: false,
|
|
147
149
|
styledComponents: true,
|
|
@@ -8,6 +8,7 @@ import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
|
8
8
|
import { getNodeParent } from '../utils/get-node-parent.mjs'
|
|
9
9
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
10
10
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
11
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
11
12
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
12
13
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
13
14
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -140,7 +141,8 @@ const sortObjects = createEslintRule({
|
|
|
140
141
|
],
|
|
141
142
|
create: context => {
|
|
142
143
|
let sortObject = node => {
|
|
143
|
-
let
|
|
144
|
+
let settings = getSettings(context.settings)
|
|
145
|
+
let options = complete(context.options.at(0), settings, {
|
|
144
146
|
partitionByNewLine: false,
|
|
145
147
|
partitionByComment: false,
|
|
146
148
|
styledComponents: true,
|
|
@@ -4,6 +4,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
4
4
|
const getGroupNumber = require('../utils/get-group-number.js')
|
|
5
5
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const useGroups = require('../utils/use-groups.js')
|
|
9
10
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -98,7 +99,8 @@ const sortSvelteAttributes = createEslintRule.createEslintRule({
|
|
|
98
99
|
return {
|
|
99
100
|
SvelteStartTag: node => {
|
|
100
101
|
if (node.attributes.length > 1) {
|
|
101
|
-
let
|
|
102
|
+
let settings = getSettings.getSettings(context.settings)
|
|
103
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
102
104
|
type: 'alphabetical',
|
|
103
105
|
ignoreCase: true,
|
|
104
106
|
customGroups: {},
|
|
@@ -3,6 +3,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
3
3
|
import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
4
4
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
8
9
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -97,7 +98,8 @@ const sortSvelteAttributes = createEslintRule({
|
|
|
97
98
|
return {
|
|
98
99
|
SvelteStartTag: node => {
|
|
99
100
|
if (node.attributes.length > 1) {
|
|
100
|
-
let
|
|
101
|
+
let settings = getSettings(context.settings)
|
|
102
|
+
let options = complete(context.options.at(0), settings, {
|
|
101
103
|
type: 'alphabetical',
|
|
102
104
|
ignoreCase: true,
|
|
103
105
|
customGroups: {},
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
3
3
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
4
4
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
5
|
+
const getSettings = require('../utils/get-settings.js')
|
|
5
6
|
const isPositive = require('../utils/is-positive.js')
|
|
6
7
|
const makeFixes = require('../utils/make-fixes.js')
|
|
7
8
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -54,7 +55,8 @@ const sortSwitchCase = createEslintRule.createEslintRule({
|
|
|
54
55
|
],
|
|
55
56
|
create: context => ({
|
|
56
57
|
SwitchStatement: node => {
|
|
57
|
-
let
|
|
58
|
+
let settings = getSettings.getSettings(context.settings)
|
|
59
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
58
60
|
type: 'alphabetical',
|
|
59
61
|
ignoreCase: true,
|
|
60
62
|
order: 'asc',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
2
2
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
3
3
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
4
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
4
5
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
5
6
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
6
7
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -53,7 +54,8 @@ const sortSwitchCase = createEslintRule({
|
|
|
53
54
|
],
|
|
54
55
|
create: context => ({
|
|
55
56
|
SwitchStatement: node => {
|
|
56
|
-
let
|
|
57
|
+
let settings = getSettings(context.settings)
|
|
58
|
+
let options = complete(context.options.at(0), settings, {
|
|
57
59
|
type: 'alphabetical',
|
|
58
60
|
ignoreCase: true,
|
|
59
61
|
order: 'asc',
|
|
@@ -4,6 +4,7 @@ const getGroupNumber = require('../utils/get-group-number.js')
|
|
|
4
4
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
5
5
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
6
6
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
7
|
+
const getSettings = require('../utils/get-settings.js')
|
|
7
8
|
const isPositive = require('../utils/is-positive.js')
|
|
8
9
|
const useGroups = require('../utils/use-groups.js')
|
|
9
10
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
@@ -75,7 +76,8 @@ const sortUnionTypes = createEslintRule.createEslintRule({
|
|
|
75
76
|
],
|
|
76
77
|
create: context => ({
|
|
77
78
|
TSUnionType: node => {
|
|
78
|
-
let
|
|
79
|
+
let settings = getSettings.getSettings(context.settings)
|
|
80
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
79
81
|
type: 'alphabetical',
|
|
80
82
|
ignoreCase: true,
|
|
81
83
|
order: 'asc',
|
|
@@ -3,6 +3,7 @@ import { getGroupNumber } from '../utils/get-group-number.mjs'
|
|
|
3
3
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
4
4
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
5
5
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
6
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
6
7
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
7
8
|
import { useGroups } from '../utils/use-groups.mjs'
|
|
8
9
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
@@ -74,7 +75,8 @@ const sortUnionTypes = createEslintRule({
|
|
|
74
75
|
],
|
|
75
76
|
create: context => ({
|
|
76
77
|
TSUnionType: node => {
|
|
77
|
-
let
|
|
78
|
+
let settings = getSettings(context.settings)
|
|
79
|
+
let options = complete(context.options.at(0), settings, {
|
|
78
80
|
type: 'alphabetical',
|
|
79
81
|
ignoreCase: true,
|
|
80
82
|
order: 'asc',
|
|
@@ -3,6 +3,7 @@ const createEslintRule = require('../utils/create-eslint-rule.js')
|
|
|
3
3
|
const getSourceCode = require('../utils/get-source-code.js')
|
|
4
4
|
const toSingleLine = require('../utils/to-single-line.js')
|
|
5
5
|
const rangeToDiff = require('../utils/range-to-diff.js')
|
|
6
|
+
const getSettings = require('../utils/get-settings.js')
|
|
6
7
|
const isPositive = require('../utils/is-positive.js')
|
|
7
8
|
const sortNodes = require('../utils/sort-nodes.js')
|
|
8
9
|
const makeFixes = require('../utils/make-fixes.js')
|
|
@@ -56,7 +57,8 @@ const sortVariableDeclarations = createEslintRule.createEslintRule({
|
|
|
56
57
|
create: context => ({
|
|
57
58
|
VariableDeclaration: node => {
|
|
58
59
|
if (node.declarations.length > 1) {
|
|
59
|
-
let
|
|
60
|
+
let settings = getSettings.getSettings(context.settings)
|
|
61
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
60
62
|
type: 'alphabetical',
|
|
61
63
|
ignoreCase: true,
|
|
62
64
|
order: 'asc',
|
|
@@ -2,6 +2,7 @@ import { createEslintRule } from '../utils/create-eslint-rule.mjs'
|
|
|
2
2
|
import { getSourceCode } from '../utils/get-source-code.mjs'
|
|
3
3
|
import { toSingleLine } from '../utils/to-single-line.mjs'
|
|
4
4
|
import { rangeToDiff } from '../utils/range-to-diff.mjs'
|
|
5
|
+
import { getSettings } from '../utils/get-settings.mjs'
|
|
5
6
|
import { isPositive } from '../utils/is-positive.mjs'
|
|
6
7
|
import { sortNodes } from '../utils/sort-nodes.mjs'
|
|
7
8
|
import { makeFixes } from '../utils/make-fixes.mjs'
|
|
@@ -55,7 +56,8 @@ const sortVariableDeclarations = createEslintRule({
|
|
|
55
56
|
create: context => ({
|
|
56
57
|
VariableDeclaration: node => {
|
|
57
58
|
if (node.declarations.length > 1) {
|
|
58
|
-
let
|
|
59
|
+
let settings = getSettings(context.settings)
|
|
60
|
+
let options = complete(context.options.at(0), settings, {
|
|
59
61
|
type: 'alphabetical',
|
|
60
62
|
ignoreCase: true,
|
|
61
63
|
order: 'asc',
|
|
@@ -103,7 +103,8 @@ const sortVueAttributes = createEslintRule.createEslintRule({
|
|
|
103
103
|
return defineTemplateBodyVisitor({
|
|
104
104
|
VStartTag: node => {
|
|
105
105
|
if (node.attributes.length > 1) {
|
|
106
|
-
let
|
|
106
|
+
let settings = context.settings.perfectionist
|
|
107
|
+
let options = complete.complete(context.options.at(0), settings, {
|
|
107
108
|
type: 'alphabetical',
|
|
108
109
|
ignoreCase: true,
|
|
109
110
|
customGroups: {},
|
|
@@ -102,7 +102,8 @@ const sortVueAttributes = createEslintRule({
|
|
|
102
102
|
return defineTemplateBodyVisitor({
|
|
103
103
|
VStartTag: node => {
|
|
104
104
|
if (node.attributes.length > 1) {
|
|
105
|
-
let
|
|
105
|
+
let settings = context.settings.perfectionist
|
|
106
|
+
let options = complete(context.options.at(0), settings, {
|
|
106
107
|
type: 'alphabetical',
|
|
107
108
|
ignoreCase: true,
|
|
108
109
|
customGroups: {},
|
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.2.0",
|
|
5
5
|
"homepage": "https://perfectionist.dev",
|
|
6
6
|
"repository": "azat-io/eslint-plugin-perfectionist",
|
|
7
7
|
"author": "Azat S. <to@azat.io>",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"astro-eslint-parser": "^1.0.2",
|
|
50
50
|
"eslint": ">=8.0.0",
|
|
51
51
|
"svelte": ">=3.0.0",
|
|
52
|
-
"svelte-eslint-parser": "^0.
|
|
52
|
+
"svelte-eslint-parser": "^0.41.0",
|
|
53
53
|
"vue-eslint-parser": ">=9.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@typescript-eslint/types": "^8.
|
|
57
|
-
"@typescript-eslint/utils": "^8.
|
|
56
|
+
"@typescript-eslint/types": "^8.1.0",
|
|
57
|
+
"@typescript-eslint/utils": "^8.1.0",
|
|
58
58
|
"minimatch": "^10.0.1",
|
|
59
59
|
"natural-compare-lite": "^1.4.0"
|
|
60
60
|
}
|