eslint-plugin-perfectionist 2.7.0 → 2.9.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.
Files changed (84) hide show
  1. package/dist/configs/recommended-alphabetical.js +9 -1
  2. package/dist/configs/recommended-alphabetical.mjs +5 -10
  3. package/dist/configs/recommended-line-length.js +9 -1
  4. package/dist/configs/recommended-line-length.mjs +5 -10
  5. package/dist/configs/recommended-natural.js +9 -1
  6. package/dist/configs/recommended-natural.mjs +5 -10
  7. package/dist/index.js +135 -3
  8. package/dist/index.mjs +76 -2197
  9. package/dist/package.json.js +4 -0
  10. package/dist/package.json.mjs +4 -0
  11. package/dist/rules/sort-array-includes.js +129 -0
  12. package/dist/rules/sort-array-includes.mjs +129 -0
  13. package/dist/rules/sort-astro-attributes.js +161 -0
  14. package/dist/rules/sort-astro-attributes.mjs +161 -0
  15. package/dist/rules/sort-classes.js +213 -0
  16. package/dist/rules/sort-classes.mjs +213 -0
  17. package/dist/rules/sort-enums.js +117 -0
  18. package/dist/rules/sort-enums.mjs +117 -0
  19. package/dist/rules/sort-exports.js +104 -0
  20. package/dist/rules/sort-exports.mjs +104 -0
  21. package/dist/rules/sort-imports.js +439 -0
  22. package/dist/rules/sort-imports.mjs +439 -0
  23. package/dist/rules/sort-interfaces.js +253 -0
  24. package/dist/rules/sort-interfaces.mjs +253 -0
  25. package/dist/rules/sort-intersection-types.js +92 -0
  26. package/dist/rules/sort-intersection-types.mjs +92 -0
  27. package/dist/rules/sort-jsx-props.js +156 -0
  28. package/dist/rules/sort-jsx-props.mjs +156 -0
  29. package/dist/rules/sort-maps.js +125 -0
  30. package/dist/rules/sort-maps.mjs +125 -0
  31. package/dist/rules/sort-named-exports.js +105 -0
  32. package/dist/rules/sort-named-exports.mjs +105 -0
  33. package/dist/rules/sort-named-imports.js +123 -0
  34. package/dist/rules/sort-named-imports.mjs +123 -0
  35. package/dist/rules/sort-object-types.js +189 -0
  36. package/dist/rules/sort-object-types.mjs +189 -0
  37. package/dist/rules/sort-objects.js +265 -0
  38. package/dist/rules/sort-objects.mjs +265 -0
  39. package/dist/rules/sort-svelte-attributes.js +168 -0
  40. package/dist/rules/sort-svelte-attributes.mjs +168 -0
  41. package/dist/rules/sort-union-types.js +120 -0
  42. package/dist/rules/sort-union-types.mjs +120 -0
  43. package/dist/rules/sort-vue-attributes.js +165 -0
  44. package/dist/rules/sort-vue-attributes.mjs +165 -0
  45. package/dist/typings/index.js +29 -0
  46. package/dist/typings/index.mjs +29 -0
  47. package/dist/utils/compare.js +38 -0
  48. package/dist/utils/compare.mjs +38 -0
  49. package/dist/utils/complete.js +4 -0
  50. package/dist/utils/complete.mjs +4 -0
  51. package/dist/utils/create-eslint-rule.js +7 -0
  52. package/dist/utils/create-eslint-rule.mjs +7 -0
  53. package/dist/utils/get-comment-after.js +13 -0
  54. package/dist/utils/get-comment-after.mjs +13 -0
  55. package/dist/utils/get-comment-before.js +14 -0
  56. package/dist/utils/get-comment-before.mjs +14 -0
  57. package/dist/utils/get-group-number.js +12 -0
  58. package/dist/utils/get-group-number.mjs +12 -0
  59. package/dist/utils/get-lines-between.js +10 -0
  60. package/dist/utils/get-lines-between.mjs +10 -0
  61. package/dist/utils/get-node-parent.js +14 -0
  62. package/dist/utils/get-node-parent.mjs +14 -0
  63. package/dist/utils/get-node-range.js +41 -0
  64. package/dist/utils/get-node-range.mjs +41 -0
  65. package/dist/utils/is-member-optional.js +12 -0
  66. package/dist/utils/is-member-optional.mjs +12 -0
  67. package/dist/utils/is-partition-comment.js +11 -0
  68. package/dist/utils/is-partition-comment.mjs +11 -0
  69. package/dist/utils/is-positive.js +4 -0
  70. package/dist/utils/is-positive.mjs +4 -0
  71. package/dist/utils/make-fixes.js +38 -0
  72. package/dist/utils/make-fixes.mjs +38 -0
  73. package/dist/utils/pairwise.js +14 -0
  74. package/dist/utils/pairwise.mjs +14 -0
  75. package/dist/utils/range-to-diff.js +7 -0
  76. package/dist/utils/range-to-diff.mjs +7 -0
  77. package/dist/utils/sort-nodes.js +5 -0
  78. package/dist/utils/sort-nodes.mjs +5 -0
  79. package/dist/utils/to-single-line.js +4 -0
  80. package/dist/utils/to-single-line.mjs +4 -0
  81. package/dist/utils/use-groups.js +35 -0
  82. package/dist/utils/use-groups.mjs +35 -0
  83. package/package.json +1 -1
  84. package/readme.md +20 -19
@@ -0,0 +1,156 @@
1
+ import path from "node:path";
2
+ import { createEslintRule } from "../utils/create-eslint-rule.mjs";
3
+ import { getGroupNumber } from "../utils/get-group-number.mjs";
4
+ import { rangeToDiff } from "../utils/range-to-diff.mjs";
5
+ import { isPositive } from "../utils/is-positive.mjs";
6
+ import { SortType, SortOrder } from "../typings/index.mjs";
7
+ import { useGroups } from "../utils/use-groups.mjs";
8
+ import { makeFixes } from "../utils/make-fixes.mjs";
9
+ import { sortNodes } from "../utils/sort-nodes.mjs";
10
+ import { pairwise } from "../utils/pairwise.mjs";
11
+ import { complete } from "../utils/complete.mjs";
12
+ import { compare } from "../utils/compare.mjs";
13
+ const RULE_NAME = "sort-jsx-props";
14
+ const sortJsxProps = createEslintRule({
15
+ name: RULE_NAME,
16
+ meta: {
17
+ type: "suggestion",
18
+ docs: {
19
+ description: "enforce sorted JSX props"
20
+ },
21
+ fixable: "code",
22
+ schema: [
23
+ {
24
+ type: "object",
25
+ properties: {
26
+ "custom-groups": {
27
+ type: "object"
28
+ },
29
+ type: {
30
+ enum: [
31
+ SortType.alphabetical,
32
+ SortType.natural,
33
+ SortType["line-length"]
34
+ ],
35
+ default: SortType.alphabetical,
36
+ type: "string"
37
+ },
38
+ order: {
39
+ enum: [SortOrder.asc, SortOrder.desc],
40
+ default: SortOrder.asc,
41
+ type: "string"
42
+ },
43
+ groups: {
44
+ type: "array"
45
+ },
46
+ "ignore-case": {
47
+ type: "boolean",
48
+ default: false
49
+ }
50
+ },
51
+ additionalProperties: false
52
+ }
53
+ ],
54
+ messages: {
55
+ unexpectedJSXPropsOrder: 'Expected "{{right}}" to come before "{{left}}"'
56
+ }
57
+ },
58
+ defaultOptions: [
59
+ {
60
+ type: SortType.alphabetical,
61
+ order: SortOrder.asc
62
+ }
63
+ ],
64
+ create: (context) => {
65
+ if ([".svelte", ".astro", ".vue"].includes(path.extname(context.filename))) {
66
+ return {};
67
+ }
68
+ return {
69
+ JSXElement: (node) => {
70
+ if (node.openingElement.attributes.length > 1) {
71
+ let options = complete(context.options.at(0), {
72
+ type: SortType.alphabetical,
73
+ "ignore-case": false,
74
+ order: SortOrder.asc,
75
+ "custom-groups": {},
76
+ groups: []
77
+ });
78
+ let parts = node.openingElement.attributes.reduce(
79
+ (accumulator, attribute) => {
80
+ if (attribute.type === "JSXSpreadAttribute") {
81
+ accumulator.push([]);
82
+ return accumulator;
83
+ }
84
+ let name = attribute.name.type === "JSXNamespacedName" ? `${attribute.name.namespace.name}:${attribute.name.name.name}` : attribute.name.name;
85
+ let { getGroup, defineGroup, setCustomGroups } = useGroups(
86
+ options.groups
87
+ );
88
+ setCustomGroups(options["custom-groups"], name);
89
+ if (attribute.value === null) {
90
+ defineGroup("shorthand");
91
+ }
92
+ if (attribute.loc.start.line !== attribute.loc.end.line) {
93
+ defineGroup("multiline");
94
+ }
95
+ let jsxNode = {
96
+ size: rangeToDiff(attribute.range),
97
+ group: getGroup(),
98
+ node: attribute,
99
+ name
100
+ };
101
+ accumulator.at(-1).push(jsxNode);
102
+ return accumulator;
103
+ },
104
+ [[]]
105
+ );
106
+ for (let nodes of parts) {
107
+ pairwise(nodes, (left, right) => {
108
+ let leftNum = getGroupNumber(options.groups, left);
109
+ let rightNum = getGroupNumber(options.groups, right);
110
+ if (leftNum > rightNum || leftNum === rightNum && isPositive(compare(left, right, options))) {
111
+ context.report({
112
+ messageId: "unexpectedJSXPropsOrder",
113
+ data: {
114
+ left: left.name,
115
+ right: right.name
116
+ },
117
+ node: right.node,
118
+ fix: (fixer) => {
119
+ let grouped = {};
120
+ for (let currentNode of nodes) {
121
+ let groupNum = getGroupNumber(options.groups, currentNode);
122
+ if (!(groupNum in grouped)) {
123
+ grouped[groupNum] = [currentNode];
124
+ } else {
125
+ grouped[groupNum] = sortNodes(
126
+ [...grouped[groupNum], currentNode],
127
+ options
128
+ );
129
+ }
130
+ }
131
+ let sortedNodes = [];
132
+ for (let group of Object.keys(grouped).sort(
133
+ (a, b) => Number(a) - Number(b)
134
+ )) {
135
+ sortedNodes.push(...sortNodes(grouped[group], options));
136
+ }
137
+ return makeFixes(
138
+ fixer,
139
+ nodes,
140
+ sortedNodes,
141
+ context.sourceCode
142
+ );
143
+ }
144
+ });
145
+ }
146
+ });
147
+ }
148
+ }
149
+ }
150
+ };
151
+ }
152
+ });
153
+ export {
154
+ RULE_NAME,
155
+ sortJsxProps as default
156
+ };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const createEslintRule = require("../utils/create-eslint-rule.js");
4
+ const toSingleLine = require("../utils/to-single-line.js");
5
+ const rangeToDiff = require("../utils/range-to-diff.js");
6
+ const isPositive = require("../utils/is-positive.js");
7
+ const index = require("../typings/index.js");
8
+ const sortNodes = require("../utils/sort-nodes.js");
9
+ const makeFixes = require("../utils/make-fixes.js");
10
+ const complete = require("../utils/complete.js");
11
+ const pairwise = require("../utils/pairwise.js");
12
+ const compare = require("../utils/compare.js");
13
+ const RULE_NAME = "sort-maps";
14
+ const sortMaps = createEslintRule.createEslintRule({
15
+ name: RULE_NAME,
16
+ meta: {
17
+ type: "suggestion",
18
+ docs: {
19
+ description: "enforce sorted Map elements"
20
+ },
21
+ fixable: "code",
22
+ schema: [
23
+ {
24
+ type: "object",
25
+ properties: {
26
+ type: {
27
+ enum: [
28
+ index.SortType.alphabetical,
29
+ index.SortType.natural,
30
+ index.SortType["line-length"]
31
+ ],
32
+ default: index.SortType.alphabetical,
33
+ type: "string"
34
+ },
35
+ order: {
36
+ enum: [index.SortOrder.asc, index.SortOrder.desc],
37
+ default: index.SortOrder.asc,
38
+ type: "string"
39
+ },
40
+ "ignore-case": {
41
+ type: "boolean",
42
+ default: false
43
+ }
44
+ },
45
+ additionalProperties: false
46
+ }
47
+ ],
48
+ messages: {
49
+ unexpectedMapElementsOrder: 'Expected "{{right}}" to come before "{{left}}"'
50
+ }
51
+ },
52
+ defaultOptions: [
53
+ {
54
+ type: index.SortType.alphabetical,
55
+ order: index.SortOrder.asc
56
+ }
57
+ ],
58
+ create: (context) => ({
59
+ NewExpression: (node) => {
60
+ if (node.callee.type === "Identifier" && node.callee.name === "Map" && node.arguments.length && node.arguments[0].type === "ArrayExpression") {
61
+ let [{ elements }] = node.arguments;
62
+ if (elements.length > 1) {
63
+ let options = complete.complete(context.options.at(0), {
64
+ type: index.SortType.alphabetical,
65
+ "ignore-case": false,
66
+ order: index.SortOrder.asc
67
+ });
68
+ let parts = elements.reduce(
69
+ (accumulator, element) => {
70
+ if (element === null || element.type === "SpreadElement") {
71
+ accumulator.push([]);
72
+ } else {
73
+ accumulator.at(-1).push(element);
74
+ }
75
+ return accumulator;
76
+ },
77
+ [[]]
78
+ );
79
+ for (let part of parts) {
80
+ let nodes = part.map((element) => {
81
+ let name;
82
+ if (element.type === "ArrayExpression") {
83
+ let [left] = element.elements;
84
+ if (!left) {
85
+ name = `${left}`;
86
+ } else if (left.type === "Literal") {
87
+ name = left.raw;
88
+ } else {
89
+ name = context.sourceCode.text.slice(...left.range);
90
+ }
91
+ } else {
92
+ name = context.sourceCode.text.slice(...element.range);
93
+ }
94
+ return {
95
+ size: rangeToDiff.rangeToDiff(element.range),
96
+ node: element,
97
+ name
98
+ };
99
+ });
100
+ pairwise.pairwise(nodes, (left, right) => {
101
+ if (isPositive.isPositive(compare.compare(left, right, options))) {
102
+ context.report({
103
+ messageId: "unexpectedMapElementsOrder",
104
+ data: {
105
+ left: toSingleLine.toSingleLine(left.name),
106
+ right: toSingleLine.toSingleLine(right.name)
107
+ },
108
+ node: right.node,
109
+ fix: (fixer) => makeFixes.makeFixes(
110
+ fixer,
111
+ nodes,
112
+ sortNodes.sortNodes(nodes, options),
113
+ context.sourceCode
114
+ )
115
+ });
116
+ }
117
+ });
118
+ }
119
+ }
120
+ }
121
+ }
122
+ })
123
+ });
124
+ exports.RULE_NAME = RULE_NAME;
125
+ exports.default = sortMaps;
@@ -0,0 +1,125 @@
1
+ import { createEslintRule } from "../utils/create-eslint-rule.mjs";
2
+ import { toSingleLine } from "../utils/to-single-line.mjs";
3
+ import { rangeToDiff } from "../utils/range-to-diff.mjs";
4
+ import { isPositive } from "../utils/is-positive.mjs";
5
+ import { SortType, SortOrder } from "../typings/index.mjs";
6
+ import { sortNodes } from "../utils/sort-nodes.mjs";
7
+ import { makeFixes } from "../utils/make-fixes.mjs";
8
+ import { complete } from "../utils/complete.mjs";
9
+ import { pairwise } from "../utils/pairwise.mjs";
10
+ import { compare } from "../utils/compare.mjs";
11
+ const RULE_NAME = "sort-maps";
12
+ const sortMaps = createEslintRule({
13
+ name: RULE_NAME,
14
+ meta: {
15
+ type: "suggestion",
16
+ docs: {
17
+ description: "enforce sorted Map elements"
18
+ },
19
+ fixable: "code",
20
+ schema: [
21
+ {
22
+ type: "object",
23
+ properties: {
24
+ type: {
25
+ enum: [
26
+ SortType.alphabetical,
27
+ SortType.natural,
28
+ SortType["line-length"]
29
+ ],
30
+ default: SortType.alphabetical,
31
+ type: "string"
32
+ },
33
+ order: {
34
+ enum: [SortOrder.asc, SortOrder.desc],
35
+ default: SortOrder.asc,
36
+ type: "string"
37
+ },
38
+ "ignore-case": {
39
+ type: "boolean",
40
+ default: false
41
+ }
42
+ },
43
+ additionalProperties: false
44
+ }
45
+ ],
46
+ messages: {
47
+ unexpectedMapElementsOrder: 'Expected "{{right}}" to come before "{{left}}"'
48
+ }
49
+ },
50
+ defaultOptions: [
51
+ {
52
+ type: SortType.alphabetical,
53
+ order: SortOrder.asc
54
+ }
55
+ ],
56
+ create: (context) => ({
57
+ NewExpression: (node) => {
58
+ if (node.callee.type === "Identifier" && node.callee.name === "Map" && node.arguments.length && node.arguments[0].type === "ArrayExpression") {
59
+ let [{ elements }] = node.arguments;
60
+ if (elements.length > 1) {
61
+ let options = complete(context.options.at(0), {
62
+ type: SortType.alphabetical,
63
+ "ignore-case": false,
64
+ order: SortOrder.asc
65
+ });
66
+ let parts = elements.reduce(
67
+ (accumulator, element) => {
68
+ if (element === null || element.type === "SpreadElement") {
69
+ accumulator.push([]);
70
+ } else {
71
+ accumulator.at(-1).push(element);
72
+ }
73
+ return accumulator;
74
+ },
75
+ [[]]
76
+ );
77
+ for (let part of parts) {
78
+ let nodes = part.map((element) => {
79
+ let name;
80
+ if (element.type === "ArrayExpression") {
81
+ let [left] = element.elements;
82
+ if (!left) {
83
+ name = `${left}`;
84
+ } else if (left.type === "Literal") {
85
+ name = left.raw;
86
+ } else {
87
+ name = context.sourceCode.text.slice(...left.range);
88
+ }
89
+ } else {
90
+ name = context.sourceCode.text.slice(...element.range);
91
+ }
92
+ return {
93
+ size: rangeToDiff(element.range),
94
+ node: element,
95
+ name
96
+ };
97
+ });
98
+ pairwise(nodes, (left, right) => {
99
+ if (isPositive(compare(left, right, options))) {
100
+ context.report({
101
+ messageId: "unexpectedMapElementsOrder",
102
+ data: {
103
+ left: toSingleLine(left.name),
104
+ right: toSingleLine(right.name)
105
+ },
106
+ node: right.node,
107
+ fix: (fixer) => makeFixes(
108
+ fixer,
109
+ nodes,
110
+ sortNodes(nodes, options),
111
+ context.sourceCode
112
+ )
113
+ });
114
+ }
115
+ });
116
+ }
117
+ }
118
+ }
119
+ }
120
+ })
121
+ });
122
+ export {
123
+ RULE_NAME,
124
+ sortMaps as default
125
+ };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const createEslintRule = require("../utils/create-eslint-rule.js");
4
+ const index = require("../typings/index.js");
5
+ const getGroupNumber = require("../utils/get-group-number.js");
6
+ const rangeToDiff = require("../utils/range-to-diff.js");
7
+ const isPositive = require("../utils/is-positive.js");
8
+ const sortNodes = require("../utils/sort-nodes.js");
9
+ const makeFixes = require("../utils/make-fixes.js");
10
+ const complete = require("../utils/complete.js");
11
+ const pairwise = require("../utils/pairwise.js");
12
+ const compare = require("../utils/compare.js");
13
+ const RULE_NAME = "sort-named-exports";
14
+ const sortNamedExports = createEslintRule.createEslintRule({
15
+ name: RULE_NAME,
16
+ meta: {
17
+ type: "suggestion",
18
+ docs: {
19
+ description: "enforce sorted named exports"
20
+ },
21
+ fixable: "code",
22
+ schema: [
23
+ {
24
+ type: "object",
25
+ properties: {
26
+ type: {
27
+ enum: [
28
+ index.SortType.alphabetical,
29
+ index.SortType.natural,
30
+ index.SortType["line-length"]
31
+ ],
32
+ default: index.SortType.alphabetical,
33
+ type: "string"
34
+ },
35
+ order: {
36
+ enum: [index.SortOrder.asc, index.SortOrder.desc],
37
+ default: index.SortOrder.asc,
38
+ type: "string"
39
+ },
40
+ "ignore-case": {
41
+ type: "boolean",
42
+ default: false
43
+ },
44
+ "group-kind": {
45
+ enum: [
46
+ index.GroupKind.mixed,
47
+ index.GroupKind["values-first"],
48
+ index.GroupKind["types-first"]
49
+ ],
50
+ default: index.GroupKind.mixed,
51
+ type: "string"
52
+ }
53
+ },
54
+ additionalProperties: false
55
+ }
56
+ ],
57
+ messages: {
58
+ unexpectedNamedExportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
59
+ }
60
+ },
61
+ defaultOptions: [
62
+ {
63
+ type: index.SortType.alphabetical,
64
+ order: index.SortOrder.asc
65
+ }
66
+ ],
67
+ create: (context) => ({
68
+ ExportNamedDeclaration: (node) => {
69
+ if (node.specifiers.length > 1) {
70
+ let options = complete.complete(context.options.at(0), {
71
+ type: index.SortType.alphabetical,
72
+ "ignore-case": false,
73
+ order: index.SortOrder.asc,
74
+ "group-kind": index.GroupKind.mixed
75
+ });
76
+ let nodes = node.specifiers.map((specifier) => ({
77
+ size: rangeToDiff.rangeToDiff(specifier.range),
78
+ name: specifier.local.name,
79
+ node: specifier,
80
+ group: specifier.exportKind
81
+ }));
82
+ let shouldGroupByKind = options["group-kind"] !== index.GroupKind.mixed;
83
+ let groupKindOrder = options["group-kind"] === index.GroupKind["values-first"] ? ["value", "type"] : ["type", "value"];
84
+ pairwise.pairwise(nodes, (left, right) => {
85
+ let leftNum = getGroupNumber.getGroupNumber(groupKindOrder, left);
86
+ let rightNum = getGroupNumber.getGroupNumber(groupKindOrder, right);
87
+ if (shouldGroupByKind && leftNum > rightNum || (!shouldGroupByKind || leftNum === rightNum) && isPositive.isPositive(compare.compare(left, right, options))) {
88
+ let sortedNodes = shouldGroupByKind ? groupKindOrder.map((group) => nodes.filter((n) => n.group === group)).map((groupedNodes) => sortNodes.sortNodes(groupedNodes, options)).flat() : sortNodes.sortNodes(nodes, options);
89
+ context.report({
90
+ messageId: "unexpectedNamedExportsOrder",
91
+ data: {
92
+ left: left.name,
93
+ right: right.name
94
+ },
95
+ node: right.node,
96
+ fix: (fixer) => makeFixes.makeFixes(fixer, nodes, sortedNodes, context.sourceCode)
97
+ });
98
+ }
99
+ });
100
+ }
101
+ }
102
+ })
103
+ });
104
+ exports.RULE_NAME = RULE_NAME;
105
+ exports.default = sortNamedExports;
@@ -0,0 +1,105 @@
1
+ import { createEslintRule } from "../utils/create-eslint-rule.mjs";
2
+ import { SortType, SortOrder, GroupKind } from "../typings/index.mjs";
3
+ import { getGroupNumber } from "../utils/get-group-number.mjs";
4
+ import { rangeToDiff } from "../utils/range-to-diff.mjs";
5
+ import { isPositive } from "../utils/is-positive.mjs";
6
+ import { sortNodes } from "../utils/sort-nodes.mjs";
7
+ import { makeFixes } from "../utils/make-fixes.mjs";
8
+ import { complete } from "../utils/complete.mjs";
9
+ import { pairwise } from "../utils/pairwise.mjs";
10
+ import { compare } from "../utils/compare.mjs";
11
+ const RULE_NAME = "sort-named-exports";
12
+ const sortNamedExports = createEslintRule({
13
+ name: RULE_NAME,
14
+ meta: {
15
+ type: "suggestion",
16
+ docs: {
17
+ description: "enforce sorted named exports"
18
+ },
19
+ fixable: "code",
20
+ schema: [
21
+ {
22
+ type: "object",
23
+ properties: {
24
+ type: {
25
+ enum: [
26
+ SortType.alphabetical,
27
+ SortType.natural,
28
+ SortType["line-length"]
29
+ ],
30
+ default: SortType.alphabetical,
31
+ type: "string"
32
+ },
33
+ order: {
34
+ enum: [SortOrder.asc, SortOrder.desc],
35
+ default: SortOrder.asc,
36
+ type: "string"
37
+ },
38
+ "ignore-case": {
39
+ type: "boolean",
40
+ default: false
41
+ },
42
+ "group-kind": {
43
+ enum: [
44
+ GroupKind.mixed,
45
+ GroupKind["values-first"],
46
+ GroupKind["types-first"]
47
+ ],
48
+ default: GroupKind.mixed,
49
+ type: "string"
50
+ }
51
+ },
52
+ additionalProperties: false
53
+ }
54
+ ],
55
+ messages: {
56
+ unexpectedNamedExportsOrder: 'Expected "{{right}}" to come before "{{left}}"'
57
+ }
58
+ },
59
+ defaultOptions: [
60
+ {
61
+ type: SortType.alphabetical,
62
+ order: SortOrder.asc
63
+ }
64
+ ],
65
+ create: (context) => ({
66
+ ExportNamedDeclaration: (node) => {
67
+ if (node.specifiers.length > 1) {
68
+ let options = complete(context.options.at(0), {
69
+ type: SortType.alphabetical,
70
+ "ignore-case": false,
71
+ order: SortOrder.asc,
72
+ "group-kind": GroupKind.mixed
73
+ });
74
+ let nodes = node.specifiers.map((specifier) => ({
75
+ size: rangeToDiff(specifier.range),
76
+ name: specifier.local.name,
77
+ node: specifier,
78
+ group: specifier.exportKind
79
+ }));
80
+ let shouldGroupByKind = options["group-kind"] !== GroupKind.mixed;
81
+ let groupKindOrder = options["group-kind"] === GroupKind["values-first"] ? ["value", "type"] : ["type", "value"];
82
+ pairwise(nodes, (left, right) => {
83
+ let leftNum = getGroupNumber(groupKindOrder, left);
84
+ let rightNum = getGroupNumber(groupKindOrder, right);
85
+ if (shouldGroupByKind && leftNum > rightNum || (!shouldGroupByKind || leftNum === rightNum) && isPositive(compare(left, right, options))) {
86
+ let sortedNodes = shouldGroupByKind ? groupKindOrder.map((group) => nodes.filter((n) => n.group === group)).map((groupedNodes) => sortNodes(groupedNodes, options)).flat() : sortNodes(nodes, options);
87
+ context.report({
88
+ messageId: "unexpectedNamedExportsOrder",
89
+ data: {
90
+ left: left.name,
91
+ right: right.name
92
+ },
93
+ node: right.node,
94
+ fix: (fixer) => makeFixes(fixer, nodes, sortedNodes, context.sourceCode)
95
+ });
96
+ }
97
+ });
98
+ }
99
+ }
100
+ })
101
+ });
102
+ export {
103
+ RULE_NAME,
104
+ sortNamedExports as default
105
+ };