eslint-plugin-perfectionist 0.3.0 → 0.4.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.js +1 -1
- package/dist/index.mjs +255 -113
- package/package.json +1 -1
- package/readme.md +1 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const h=require("@typescript-eslint/types"),j=require("@typescript-eslint/utils"),U=require("natural-compare-lite"),z="eslint-plugin-perfectionist",D="azat-io/eslint-plugin-perfectionist";let S=j.ESLintUtils.RuleCreator(t=>`https://github.com/${D}/blob/main/docs/rules/${t}.md`),x=t=>{let[n,a]=t;return a-n};var i=(t=>(t.natural="natural",t["line-length"]="line-length",t))(i||{}),l=(t=>(t.asc="asc",t.desc="desc",t))(l||{});let E=(t,n,a)=>(a.order==="asc"?1:-1)*(a.type===i.natural?U(t.name,n.name):t.size-n.size)>0,I=(t,n,a,d)=>{let e=[...a].sort((r,o)=>Number(E(r,o,d))||-1),s=r=>[r.range.at(0),r.range.at(1)];return a.map(({node:r},o)=>t.replaceTextRange(s(r),n.slice(...s(e[o].node))))},N=(t={},n)=>Object.assign(n,t);const T="sort-interfaces",$=S({name:T,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},messages:{unexpectedInterfacePropertiesOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.natural,i["line-length"]]},order:{enum:[l.asc,l.desc]}},additionalProperties:!1}]},defaultOptions:[{type:i.natural,order:l.asc}],create:t=>({TSInterfaceBody:n=>{let a=N(t.options.at(0),{type:i.natural,order:l.asc}),d=n.body.map(e=>{let s="",r=0,o=c=>{r+=c},p=c=>{o(x(c.key.range))},m=c=>{let{length:y}="[]";o(c.parameters.reduce((O,{range:R})=>O+x(R),y))},u=c=>{if(c.optional){let{length:y}="?";o(y)}},g=c=>{var O;let y=(O=c.typeAnnotation)==null?void 0:O.range;y&&o(x(y))},f=c=>{if(c.type===h.AST_NODE_TYPES.Identifier)({name:s}=c);else if(c.type===h.AST_NODE_TYPES.TSIndexSignature){let y=c.parameters.at(0);y&&f(y)}};return e.type===h.AST_NODE_TYPES.TSPropertySignature?(f(e.key),p(e),u(e),g(e)):e.type===h.AST_NODE_TYPES.TSIndexSignature&&(f(e),m(e),g(e)),{node:e,name:s,size:r}});for(let e=1;e<d.length;e++){let s=e-1,r=e,o=d.at(s),p=d.at(r);if(E(o,p,a)){let m=n.body[r];t.report({messageId:"unexpectedInterfacePropertiesOrder",data:{first:o.name,second:p.name},node:m,fix:u=>{let g=t.getSourceCode(),{text:f}=g;return I(u,f,d,a)}})}}}})}),b="sort-jsx-props",v=S({name:b,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},messages:{unexpectedJSXPropsOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.natural,i["line-length"]]},order:{enum:[l.asc,l.desc]}},additionalProperties:!1}]},defaultOptions:[{type:i.natural,order:l.asc}],create:t=>({JSXElement:n=>{let a=N(t.options.at(0),{type:i.natural,order:l.asc});n.openingElement.attributes.reduce((e,s)=>(s.type==="JSXAttribute"?e.at(-1).push(s):e.push([]),e),[[]]).forEach(e=>{let s=e.map(r=>({name:r.name.type===h.AST_NODE_TYPES.JSXNamespacedName?`${r.name.namespace.name}:${r.name.name.name}`:r.name.name,size:x(r.range),node:r}));for(let r=1;r<s.length;r++){let o=r-1,p=r,m=s.at(o),u=s.at(p);E(m,u,a)&&t.report({messageId:"unexpectedJSXPropsOrder",data:{first:m.name,second:u.name},node:u.node,fix:g=>{let f=t.getSourceCode(),{text:c}=f;return I(g,c,s,a)}})}})}})}),P="sort-named-exports",J=S({name:P,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},messages:{unexpectedNamedExportsOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.natural,i["line-length"]]},order:{enum:[l.asc,l.desc]}},additionalProperties:!1}]},defaultOptions:[{type:i.natural,order:l.asc}],create:t=>({ExportNamedDeclaration:n=>{let a=N(t.options.at(0),{type:i.natural,order:l.asc});if(n.specifiers.length>1){let d=n.specifiers.map(e=>{let{range:s,local:{name:r}}=e;return{size:x(s),node:e,name:r}});for(let e=1;e<d.length;e++){let s=e-1,r=e,o=d.at(s),p=d.at(r);if(E(o,p,a)){let m=n.specifiers[r];t.report({messageId:"unexpectedNamedExportsOrder",data:{first:o.name,second:p.name},node:m,fix:u=>{let g=t.getSourceCode(),{text:f}=g;return I(u,f,d,a)}})}}}}})}),_="sort-named-imports",L=S({name:_,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},messages:{unexpectedNamedImportsOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.natural,i["line-length"]]},order:{enum:[l.asc,l.desc]}},additionalProperties:!1}]},defaultOptions:[{type:i.natural,order:l.asc}],create:t=>({ImportDeclaration:n=>{let a=N(t.options.at(0),{type:i.natural,order:l.asc});if(n.specifiers.length>1){let d=n.specifiers.map(e=>{let{range:s,local:{name:r}}=e;return{size:x(s),node:e,name:r}});for(let e=1;e<d.length;e++){let s=e-1,r=e,o=d.at(s),p=d.at(r);if(E(o,p,a)){let m=n.specifiers[r];t.report({messageId:"unexpectedNamedImportsOrder",data:{first:o.name,second:p.name},node:m,fix:u=>{let g=t.getSourceCode(),{text:f}=g;return I(u,f,d,a)}})}}}}})}),A="sort-union-types",M=S({name:A,meta:{type:"suggestion",docs:{description:"Enforce sorted union types",recommended:!1},messages:{unexpectedUnionTypesOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.natural,i["line-length"]]},order:{enum:[l.asc,l.desc]}},additionalProperties:!1}]},defaultOptions:[{type:i.natural,order:l.asc}],create:t=>({TSUnionType:n=>{let a=t.getSourceCode().text,d=N(t.options.at(0),{type:i.natural,order:l.asc}),e=n.types.map(s=>{let{range:r}=s,o=a.slice(...r);return{size:x(r),node:s,name:o}});for(let s=1;s<e.length;s++){let r=s-1,o=s,p=e.at(r),m=e.at(o);if(E(p,m,d)){let u=n.types[o];t.report({messageId:"unexpectedUnionTypesOrder",data:{first:p.name,second:m.name},node:u,fix:g=>{let f=t.getSourceCode(),{text:c}=f;return I(g,c,e,d)}})}}}})});let C=t=>{let n={[T]:["error"],[b]:["error"],[P]:["error"],[_]:["error"],[A]:["error"]};return Object.fromEntries(Object.entries(n).map(([a,[d,e={}]])=>[a,[d,Object.assign(e,t)]]))};const X={name:z,rules:{[T]:$,[b]:v,[P]:J,[_]:L,[A]:M},configs:{"recommended-natural":C({type:"natural",order:"asc"}),"recommended-line-length":C({type:"line-length",order:"desc"})}};module.exports=X;
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { AST_NODE_TYPES as
|
|
2
|
-
import { ESLintUtils as
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
(t) => `https://github.com/${
|
|
7
|
-
),
|
|
8
|
-
let [
|
|
9
|
-
return a -
|
|
1
|
+
import { AST_NODE_TYPES as I } from "@typescript-eslint/types";
|
|
2
|
+
import { ESLintUtils as U } from "@typescript-eslint/utils";
|
|
3
|
+
import z from "natural-compare-lite";
|
|
4
|
+
const $ = "eslint-plugin-perfectionist", v = "azat-io/eslint-plugin-perfectionist";
|
|
5
|
+
let E = U.RuleCreator(
|
|
6
|
+
(t) => `https://github.com/${v}/blob/main/docs/rules/${t}.md`
|
|
7
|
+
), y = (t) => {
|
|
8
|
+
let [o, a] = t;
|
|
9
|
+
return a - o;
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
let
|
|
13
|
-
let e = [...a].sort((r,
|
|
11
|
+
var i = /* @__PURE__ */ ((t) => (t.natural = "natural", t["line-length"] = "line-length", t))(i || {}), l = /* @__PURE__ */ ((t) => (t.asc = "asc", t.desc = "desc", t))(l || {});
|
|
12
|
+
let h = (t, o, a) => (a.order === "asc" ? 1 : -1) * (a.type === i.natural ? z(t.name, o.name) : t.size - o.size) > 0, N = (t, o, a, d) => {
|
|
13
|
+
let e = [...a].sort((r, n) => Number(h(r, n, d)) || -1), s = (r) => [r.range.at(0), r.range.at(1)];
|
|
14
14
|
return a.map(
|
|
15
|
-
({ node: r },
|
|
15
|
+
({ node: r }, n) => t.replaceTextRange(s(r), o.slice(...s(e[n].node)))
|
|
16
16
|
);
|
|
17
|
-
},
|
|
18
|
-
const
|
|
19
|
-
name:
|
|
17
|
+
}, O = (t = {}, o) => Object.assign(o, t);
|
|
18
|
+
const b = "sort-interfaces", _ = E({
|
|
19
|
+
name: b,
|
|
20
20
|
meta: {
|
|
21
21
|
type: "suggestion",
|
|
22
22
|
docs: {
|
|
@@ -32,10 +32,10 @@ const E = "sort-interfaces", $ = O({
|
|
|
32
32
|
type: "object",
|
|
33
33
|
properties: {
|
|
34
34
|
type: {
|
|
35
|
-
enum: [
|
|
35
|
+
enum: [i.natural, i["line-length"]]
|
|
36
36
|
},
|
|
37
37
|
order: {
|
|
38
|
-
enum: [
|
|
38
|
+
enum: [l.asc, l.desc]
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
additionalProperties: !1
|
|
@@ -44,68 +44,68 @@ const E = "sort-interfaces", $ = O({
|
|
|
44
44
|
},
|
|
45
45
|
defaultOptions: [
|
|
46
46
|
{
|
|
47
|
-
type:
|
|
48
|
-
order:
|
|
47
|
+
type: i.natural,
|
|
48
|
+
order: l.asc
|
|
49
49
|
}
|
|
50
50
|
],
|
|
51
51
|
create: (t) => ({
|
|
52
|
-
TSInterfaceBody: (
|
|
53
|
-
let a =
|
|
54
|
-
type:
|
|
55
|
-
order:
|
|
56
|
-
}),
|
|
57
|
-
let
|
|
58
|
-
r +=
|
|
59
|
-
}, p = (
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
let { length:
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
if (
|
|
66
|
-
let { length:
|
|
67
|
-
|
|
52
|
+
TSInterfaceBody: (o) => {
|
|
53
|
+
let a = O(t.options.at(0), {
|
|
54
|
+
type: i.natural,
|
|
55
|
+
order: l.asc
|
|
56
|
+
}), d = o.body.map((e) => {
|
|
57
|
+
let s = "", r = 0, n = (c) => {
|
|
58
|
+
r += c;
|
|
59
|
+
}, p = (c) => {
|
|
60
|
+
n(y(c.key.range));
|
|
61
|
+
}, m = (c) => {
|
|
62
|
+
let { length: x } = "[]";
|
|
63
|
+
n(c.parameters.reduce((S, { range: A }) => S + y(A), x));
|
|
64
|
+
}, u = (c) => {
|
|
65
|
+
if (c.optional) {
|
|
66
|
+
let { length: x } = "?";
|
|
67
|
+
n(x);
|
|
68
68
|
}
|
|
69
|
-
},
|
|
70
|
-
var
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
}, f = (
|
|
74
|
-
if (
|
|
75
|
-
({ name:
|
|
76
|
-
else if (
|
|
77
|
-
let
|
|
78
|
-
|
|
69
|
+
}, g = (c) => {
|
|
70
|
+
var S;
|
|
71
|
+
let x = (S = c.typeAnnotation) == null ? void 0 : S.range;
|
|
72
|
+
x && n(y(x));
|
|
73
|
+
}, f = (c) => {
|
|
74
|
+
if (c.type === I.Identifier)
|
|
75
|
+
({ name: s } = c);
|
|
76
|
+
else if (c.type === I.TSIndexSignature) {
|
|
77
|
+
let x = c.parameters.at(0);
|
|
78
|
+
x && f(x);
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
return e.type ===
|
|
81
|
+
return e.type === I.TSPropertySignature ? (f(e.key), p(e), u(e), g(e)) : e.type === I.TSIndexSignature && (f(e), m(e), g(e)), {
|
|
82
82
|
node: e,
|
|
83
|
-
name:
|
|
83
|
+
name: s,
|
|
84
84
|
size: r
|
|
85
85
|
};
|
|
86
86
|
});
|
|
87
|
-
for (let e = 1; e <
|
|
88
|
-
let
|
|
89
|
-
if (
|
|
90
|
-
let
|
|
87
|
+
for (let e = 1; e < d.length; e++) {
|
|
88
|
+
let s = e - 1, r = e, n = d.at(s), p = d.at(r);
|
|
89
|
+
if (h(n, p, a)) {
|
|
90
|
+
let m = o.body[r];
|
|
91
91
|
t.report({
|
|
92
92
|
messageId: "unexpectedInterfacePropertiesOrder",
|
|
93
93
|
data: {
|
|
94
|
-
first:
|
|
94
|
+
first: n.name,
|
|
95
95
|
second: p.name
|
|
96
96
|
},
|
|
97
|
-
node:
|
|
98
|
-
fix: (
|
|
99
|
-
let
|
|
100
|
-
return
|
|
97
|
+
node: m,
|
|
98
|
+
fix: (u) => {
|
|
99
|
+
let g = t.getSourceCode(), { text: f } = g;
|
|
100
|
+
return N(u, f, d, a);
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
})
|
|
107
|
-
}),
|
|
108
|
-
name:
|
|
107
|
+
}), C = "sort-jsx-props", J = E({
|
|
108
|
+
name: C,
|
|
109
109
|
meta: {
|
|
110
110
|
type: "suggestion",
|
|
111
111
|
docs: {
|
|
@@ -121,10 +121,10 @@ const E = "sort-interfaces", $ = O({
|
|
|
121
121
|
type: "object",
|
|
122
122
|
properties: {
|
|
123
123
|
type: {
|
|
124
|
-
enum: [
|
|
124
|
+
enum: [i.natural, i["line-length"]]
|
|
125
125
|
},
|
|
126
126
|
order: {
|
|
127
|
-
enum: [
|
|
127
|
+
enum: [l.asc, l.desc]
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
additionalProperties: !1
|
|
@@ -133,45 +133,117 @@ const E = "sort-interfaces", $ = O({
|
|
|
133
133
|
},
|
|
134
134
|
defaultOptions: [
|
|
135
135
|
{
|
|
136
|
-
type:
|
|
137
|
-
order:
|
|
136
|
+
type: i.natural,
|
|
137
|
+
order: l.asc
|
|
138
138
|
}
|
|
139
139
|
],
|
|
140
140
|
create: (t) => ({
|
|
141
|
-
JSXElement: (
|
|
142
|
-
let a =
|
|
143
|
-
type:
|
|
144
|
-
order:
|
|
141
|
+
JSXElement: (o) => {
|
|
142
|
+
let a = O(t.options.at(0), {
|
|
143
|
+
type: i.natural,
|
|
144
|
+
order: l.asc
|
|
145
145
|
});
|
|
146
|
-
|
|
147
|
-
(e,
|
|
146
|
+
o.openingElement.attributes.reduce(
|
|
147
|
+
(e, s) => (s.type === "JSXAttribute" ? e.at(-1).push(s) : e.push([]), e),
|
|
148
148
|
[[]]
|
|
149
149
|
).forEach((e) => {
|
|
150
|
-
let
|
|
151
|
-
name: r.name.type ===
|
|
152
|
-
size:
|
|
150
|
+
let s = e.map((r) => ({
|
|
151
|
+
name: r.name.type === I.JSXNamespacedName ? `${r.name.namespace.name}:${r.name.name.name}` : r.name.name,
|
|
152
|
+
size: y(r.range),
|
|
153
153
|
node: r
|
|
154
154
|
}));
|
|
155
|
-
for (let r = 1; r <
|
|
156
|
-
let
|
|
157
|
-
|
|
155
|
+
for (let r = 1; r < s.length; r++) {
|
|
156
|
+
let n = r - 1, p = r, m = s.at(n), u = s.at(p);
|
|
157
|
+
h(m, u, a) && t.report({
|
|
158
158
|
messageId: "unexpectedJSXPropsOrder",
|
|
159
159
|
data: {
|
|
160
|
-
first:
|
|
161
|
-
second:
|
|
160
|
+
first: m.name,
|
|
161
|
+
second: u.name
|
|
162
162
|
},
|
|
163
|
-
node:
|
|
164
|
-
fix: (
|
|
165
|
-
let f = t.getSourceCode(), { text:
|
|
166
|
-
return
|
|
163
|
+
node: u.node,
|
|
164
|
+
fix: (g) => {
|
|
165
|
+
let f = t.getSourceCode(), { text: c } = f;
|
|
166
|
+
return N(g, c, s, a);
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
})
|
|
173
|
-
}),
|
|
174
|
-
name:
|
|
173
|
+
}), R = "sort-named-exports", L = E({
|
|
174
|
+
name: R,
|
|
175
|
+
meta: {
|
|
176
|
+
type: "suggestion",
|
|
177
|
+
docs: {
|
|
178
|
+
description: "Enforce sorted interface properties",
|
|
179
|
+
recommended: !1
|
|
180
|
+
},
|
|
181
|
+
messages: {
|
|
182
|
+
unexpectedNamedExportsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
183
|
+
},
|
|
184
|
+
fixable: "code",
|
|
185
|
+
schema: [
|
|
186
|
+
{
|
|
187
|
+
type: "object",
|
|
188
|
+
properties: {
|
|
189
|
+
type: {
|
|
190
|
+
enum: [i.natural, i["line-length"]]
|
|
191
|
+
},
|
|
192
|
+
order: {
|
|
193
|
+
enum: [l.asc, l.desc]
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
additionalProperties: !1
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
defaultOptions: [
|
|
201
|
+
{
|
|
202
|
+
type: i.natural,
|
|
203
|
+
order: l.asc
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
create: (t) => ({
|
|
207
|
+
ExportNamedDeclaration: (o) => {
|
|
208
|
+
let a = O(t.options.at(0), {
|
|
209
|
+
type: i.natural,
|
|
210
|
+
order: l.asc
|
|
211
|
+
});
|
|
212
|
+
if (o.specifiers.length > 1) {
|
|
213
|
+
let d = o.specifiers.map((e) => {
|
|
214
|
+
let {
|
|
215
|
+
range: s,
|
|
216
|
+
local: { name: r }
|
|
217
|
+
} = e;
|
|
218
|
+
return {
|
|
219
|
+
size: y(s),
|
|
220
|
+
node: e,
|
|
221
|
+
name: r
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
for (let e = 1; e < d.length; e++) {
|
|
225
|
+
let s = e - 1, r = e, n = d.at(s), p = d.at(r);
|
|
226
|
+
if (h(n, p, a)) {
|
|
227
|
+
let m = o.specifiers[r];
|
|
228
|
+
t.report({
|
|
229
|
+
messageId: "unexpectedNamedExportsOrder",
|
|
230
|
+
data: {
|
|
231
|
+
first: n.name,
|
|
232
|
+
second: p.name
|
|
233
|
+
},
|
|
234
|
+
node: m,
|
|
235
|
+
fix: (u) => {
|
|
236
|
+
let g = t.getSourceCode(), { text: f } = g;
|
|
237
|
+
return N(u, f, d, a);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
}), T = "sort-named-imports", M = E({
|
|
246
|
+
name: T,
|
|
175
247
|
meta: {
|
|
176
248
|
type: "suggestion",
|
|
177
249
|
docs: {
|
|
@@ -187,10 +259,10 @@ const E = "sort-interfaces", $ = O({
|
|
|
187
259
|
type: "object",
|
|
188
260
|
properties: {
|
|
189
261
|
type: {
|
|
190
|
-
enum: [
|
|
262
|
+
enum: [i.natural, i["line-length"]]
|
|
191
263
|
},
|
|
192
264
|
order: {
|
|
193
|
-
enum: [
|
|
265
|
+
enum: [l.asc, l.desc]
|
|
194
266
|
}
|
|
195
267
|
},
|
|
196
268
|
additionalProperties: !1
|
|
@@ -199,42 +271,42 @@ const E = "sort-interfaces", $ = O({
|
|
|
199
271
|
},
|
|
200
272
|
defaultOptions: [
|
|
201
273
|
{
|
|
202
|
-
type:
|
|
203
|
-
order:
|
|
274
|
+
type: i.natural,
|
|
275
|
+
order: l.asc
|
|
204
276
|
}
|
|
205
277
|
],
|
|
206
278
|
create: (t) => ({
|
|
207
|
-
ImportDeclaration: (
|
|
208
|
-
let a =
|
|
209
|
-
type:
|
|
210
|
-
order:
|
|
279
|
+
ImportDeclaration: (o) => {
|
|
280
|
+
let a = O(t.options.at(0), {
|
|
281
|
+
type: i.natural,
|
|
282
|
+
order: l.asc
|
|
211
283
|
});
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
284
|
+
if (o.specifiers.length > 1) {
|
|
285
|
+
let d = o.specifiers.map((e) => {
|
|
214
286
|
let {
|
|
215
|
-
range:
|
|
287
|
+
range: s,
|
|
216
288
|
local: { name: r }
|
|
217
289
|
} = e;
|
|
218
290
|
return {
|
|
219
|
-
size:
|
|
291
|
+
size: y(s),
|
|
220
292
|
node: e,
|
|
221
293
|
name: r
|
|
222
294
|
};
|
|
223
295
|
});
|
|
224
|
-
for (let e = 1; e <
|
|
225
|
-
let
|
|
226
|
-
if (
|
|
227
|
-
let
|
|
296
|
+
for (let e = 1; e < d.length; e++) {
|
|
297
|
+
let s = e - 1, r = e, n = d.at(s), p = d.at(r);
|
|
298
|
+
if (h(n, p, a)) {
|
|
299
|
+
let m = o.specifiers[r];
|
|
228
300
|
t.report({
|
|
229
301
|
messageId: "unexpectedNamedImportsOrder",
|
|
230
302
|
data: {
|
|
231
|
-
first:
|
|
303
|
+
first: n.name,
|
|
232
304
|
second: p.name
|
|
233
305
|
},
|
|
234
|
-
node:
|
|
235
|
-
fix: (
|
|
236
|
-
let
|
|
237
|
-
return
|
|
306
|
+
node: m,
|
|
307
|
+
fix: (u) => {
|
|
308
|
+
let g = t.getSourceCode(), { text: f } = g;
|
|
309
|
+
return N(u, f, d, a);
|
|
238
310
|
}
|
|
239
311
|
});
|
|
240
312
|
}
|
|
@@ -242,25 +314,95 @@ const E = "sort-interfaces", $ = O({
|
|
|
242
314
|
}
|
|
243
315
|
}
|
|
244
316
|
})
|
|
317
|
+
}), P = "sort-union-types", X = E({
|
|
318
|
+
name: P,
|
|
319
|
+
meta: {
|
|
320
|
+
type: "suggestion",
|
|
321
|
+
docs: {
|
|
322
|
+
description: "Enforce sorted union types",
|
|
323
|
+
recommended: !1
|
|
324
|
+
},
|
|
325
|
+
messages: {
|
|
326
|
+
unexpectedUnionTypesOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
327
|
+
},
|
|
328
|
+
fixable: "code",
|
|
329
|
+
schema: [
|
|
330
|
+
{
|
|
331
|
+
type: "object",
|
|
332
|
+
properties: {
|
|
333
|
+
type: {
|
|
334
|
+
enum: [i.natural, i["line-length"]]
|
|
335
|
+
},
|
|
336
|
+
order: {
|
|
337
|
+
enum: [l.asc, l.desc]
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
additionalProperties: !1
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
},
|
|
344
|
+
defaultOptions: [
|
|
345
|
+
{
|
|
346
|
+
type: i.natural,
|
|
347
|
+
order: l.asc
|
|
348
|
+
}
|
|
349
|
+
],
|
|
350
|
+
create: (t) => ({
|
|
351
|
+
TSUnionType: (o) => {
|
|
352
|
+
let a = t.getSourceCode().text, d = O(t.options.at(0), {
|
|
353
|
+
type: i.natural,
|
|
354
|
+
order: l.asc
|
|
355
|
+
}), e = o.types.map((s) => {
|
|
356
|
+
let { range: r } = s, n = a.slice(...r);
|
|
357
|
+
return {
|
|
358
|
+
size: y(r),
|
|
359
|
+
node: s,
|
|
360
|
+
name: n
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
for (let s = 1; s < e.length; s++) {
|
|
364
|
+
let r = s - 1, n = s, p = e.at(r), m = e.at(n);
|
|
365
|
+
if (h(p, m, d)) {
|
|
366
|
+
let u = o.types[n];
|
|
367
|
+
t.report({
|
|
368
|
+
messageId: "unexpectedUnionTypesOrder",
|
|
369
|
+
data: {
|
|
370
|
+
first: p.name,
|
|
371
|
+
second: m.name
|
|
372
|
+
},
|
|
373
|
+
node: u,
|
|
374
|
+
fix: (g) => {
|
|
375
|
+
let f = t.getSourceCode(), { text: c } = f;
|
|
376
|
+
return N(g, c, e, d);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
})
|
|
245
383
|
});
|
|
246
384
|
let j = (t) => {
|
|
247
|
-
let
|
|
248
|
-
[
|
|
385
|
+
let o = {
|
|
386
|
+
[b]: ["error"],
|
|
387
|
+
[C]: ["error"],
|
|
249
388
|
[R]: ["error"],
|
|
389
|
+
[T]: ["error"],
|
|
250
390
|
[P]: ["error"]
|
|
251
391
|
};
|
|
252
392
|
return Object.fromEntries(
|
|
253
|
-
Object.entries(
|
|
393
|
+
Object.entries(o).map(([a, [d, e = {}]]) => [
|
|
254
394
|
a,
|
|
255
|
-
[
|
|
395
|
+
[d, Object.assign(e, t)]
|
|
256
396
|
])
|
|
257
397
|
);
|
|
258
398
|
};
|
|
259
|
-
const
|
|
260
|
-
name:
|
|
399
|
+
const B = {
|
|
400
|
+
name: $,
|
|
261
401
|
rules: {
|
|
262
|
-
[
|
|
263
|
-
[
|
|
402
|
+
[b]: _,
|
|
403
|
+
[C]: J,
|
|
404
|
+
[R]: L,
|
|
405
|
+
[T]: M,
|
|
264
406
|
[P]: X
|
|
265
407
|
},
|
|
266
408
|
configs: {
|
|
@@ -269,5 +411,5 @@ const D = {
|
|
|
269
411
|
}
|
|
270
412
|
};
|
|
271
413
|
export {
|
|
272
|
-
|
|
414
|
+
B as default
|
|
273
415
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-perfectionist",
|
|
3
3
|
"description": "ESLint plugin for code formatting in perfectionist style",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"homepage": "https://eslint-plugin-perfectionist.azat.io",
|
|
6
6
|
"repository": "azat-io/eslint-plugin-perfectionist",
|
|
7
7
|
"author": "Azat S. <to@azat.io>",
|
package/readme.md
CHANGED
|
@@ -26,6 +26,7 @@ npm install --save-dev eslint-plugin-perfectionist
|
|
|
26
26
|
| :----------------------------------------------------------------------------------------- | :---------------------------------- | :-- | :-- |
|
|
27
27
|
| [sort-interfaces](https://eslint-plugin-perfectionist.azat.io/rules/sort-interfaces) | Enforce sorted interface properties | ✅ | 🔧 |
|
|
28
28
|
| [sort-jsx-props](https://eslint-plugin-perfectionist.azat.io/rules/sort-jsx-props) | Enforce sorted JSX props | ✅ | 🔧 |
|
|
29
|
+
| [sort-named-exports](https://eslint-plugin-perfectionist.azat.io/rules/sort-named-exports) | Enforce sorted named exports | ✅ | 🔧 |
|
|
29
30
|
| [sort-named-imports](https://eslint-plugin-perfectionist.azat.io/rules/sort-named-imports) | Enforce sorted named imports | ✅ | 🔧 |
|
|
30
31
|
| [sort-union-types](https://eslint-plugin-perfectionist.azat.io/rules/sort-union-types) | Enforce sorted union types | ✅ | 🔧 |
|
|
31
32
|
|