eslint-plugin-perfectionist 0.4.0 → 0.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/configs/recommended-alphabetical.js +1 -0
- package/dist/configs/recommended-alphabetical.mjs +13 -0
- package/dist/configs/recommended-line-length.js +1 -0
- package/dist/configs/recommended-line-length.mjs +13 -0
- package/dist/configs/recommended-natural.js +1 -0
- package/dist/configs/recommended-natural.mjs +13 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +478 -222
- package/license +20 -0
- package/package.json +15 -3
- package/readme.md +10 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-alphabetical"].rules};module.exports=r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import e from "../index.mjs";
|
|
2
|
+
import "@typescript-eslint/types";
|
|
3
|
+
import "@typescript-eslint/utils";
|
|
4
|
+
import "natural-compare-lite";
|
|
5
|
+
const m = {
|
|
6
|
+
plugins: {
|
|
7
|
+
perfectionist: e
|
|
8
|
+
},
|
|
9
|
+
rules: e.configs["recommended-alphabetical"].rules
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
m as default
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-line-length"].rules};module.exports=r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import e from "../index.mjs";
|
|
2
|
+
import "@typescript-eslint/types";
|
|
3
|
+
import "@typescript-eslint/utils";
|
|
4
|
+
import "natural-compare-lite";
|
|
5
|
+
const m = {
|
|
6
|
+
plugins: {
|
|
7
|
+
perfectionist: e
|
|
8
|
+
},
|
|
9
|
+
rules: e.configs["recommended-line-length"].rules
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
m as default
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-natural"].rules};module.exports=r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import r from "../index.mjs";
|
|
2
|
+
import "@typescript-eslint/types";
|
|
3
|
+
import "@typescript-eslint/utils";
|
|
4
|
+
import "natural-compare-lite";
|
|
5
|
+
const i = {
|
|
6
|
+
plugins: {
|
|
7
|
+
perfectionist: r
|
|
8
|
+
},
|
|
9
|
+
rules: r.configs["recommended-natural"].rules
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
i as default
|
|
13
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";const u=require("@typescript-eslint/types"),Y=require("@typescript-eslint/utils"),L=require("natural-compare-lite"),C="eslint-plugin-perfectionist",M="azat-io/eslint-plugin-perfectionist";let g=Y.ESLintUtils.RuleCreator(a=>`https://github.com/${M}/blob/main/docs/rules/${a}.md`),y=a=>{let[l,d]=a;return d-l};var s=(a=>(a.alphabetical="alphabetical",a.natural="natural",a["line-length"]="line-length",a))(s||{}),n=(a=>(a.asc="asc",a.desc="desc",a))(n||{});let m=(a,l,d)=>{let p=d.order==="asc"?1:-1,o;return d.type===s.alphabetical?o=(t,e)=>t.name.localeCompare(e.name):d.type===s.natural?o=(t,e)=>L(t.name,e.name):o=(t,e)=>t.size-e.size,p*o(a,l)>0},E=(a,l,d,p)=>{let o=[...d].sort((e,r)=>Number(m(e,r,p))||-1);p.spreadLast&&o.forEach((e,r)=>{e.node.type===u.AST_NODE_TYPES.SpreadElement&&o.push(o.splice(r,1).at(0))});let t=e=>[e.range.at(0),e.range.at(1)];return d.map(({node:e},r)=>a.replaceTextRange(t(e),l.slice(...t(o[r].node))))},h=(a={},l)=>Object.assign(l,a);const T="sort-array-includes",R=g({name:T,meta:{type:"suggestion",docs:{description:"Enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc},spreadLast:{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({MemberExpression:l=>{if((l.object.type===u.AST_NODE_TYPES.ArrayExpression||l.object.type===u.AST_NODE_TYPES.NewExpression)&&l.property.type===u.AST_NODE_TYPES.Identifier&&l.property.name==="includes"){let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc,spreadLast:!1}),p=l.object.type===u.AST_NODE_TYPES.ArrayExpression?l.object.elements:l.object.arguments;if(p.length>1){let o=a.getSourceCode().text,t=p.reduce((e,r)=>(r===null||e.at(0).push({name:r.type===u.AST_NODE_TYPES.Literal?r.raw:o.slice(...r.range),size:y(r.range),type:r.type,node:r}),e),[[],[]]).flat();for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e),c;d.spreadLast&&r.node.type===u.AST_NODE_TYPES.Literal&&i.node.type===u.AST_NODE_TYPES.SpreadElement?c=!1:d.spreadLast&&r.node.type===u.AST_NODE_TYPES.SpreadElement&&i.node.type===u.AST_NODE_TYPES.Literal?c=!0:c=m(r,i,d),c&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{first:r.name,second:i.name},node:i.node,fix:f=>{let b=a.getSourceCode(),{text:S}=b;return E(f,S,t,d)}})}}}}})}),_="sort-interfaces",$=g({name:_,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({TSInterfaceBody:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.body.length>1){let p=a.getSourceCode().text,o=l.body.map(t=>{var r,i,c;let e;if(t.type===u.AST_NODE_TYPES.TSPropertySignature)if(t.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=t.key);else if(t.key.type===u.AST_NODE_TYPES.Literal)e=`${t.key.value}`;else{let f;if((r=t.typeAnnotation)!=null&&r.range.at(0))f=t.typeAnnotation.range.at(0);else{let b=t.optional?1:0;f=t.range.at(1)-b}e=p.slice(t.range.at(0),f)}else t.type===u.AST_NODE_TYPES.TSIndexSignature?e=p.slice(t.range.at(0),((i=t.typeAnnotation)==null?void 0:i.range.at(0))??t.range.at(1)):e=p.slice(t.range.at(0),((c=t.returnType)==null?void 0:c.range.at(0))??t.range.at(1));return{size:y(t.range),node:t,name:e}});for(let t=1;t<o.length;t++){let e=o.at(t-1),r=o.at(t);if(m(e,r,d)){let i=l.body[t];a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{first:e.name,second:r.name},node:i,fix:c=>E(c,p,o,d)})}}}}})}),x="sort-jsx-props",U=g({name:x,meta:{type:"suggestion",docs:{description:"Enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({JSXElement:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});l.openingElement.attributes.reduce((o,t)=>(t.type==="JSXAttribute"?o.at(-1).push(t):o.push([]),o),[[]]).forEach(o=>{let t=o.map(e=>({name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:y(e.range),node:e}));for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e);m(r,i,d)&&a.report({messageId:"unexpectedJSXPropsOrder",data:{first:r.name,second:i.name},node:i.node,fix:c=>{let f=a.getSourceCode().text;return E(c,f,t,d)}})}})}})}),N="sort-map-elements",k=g({name:N,meta:{type:"suggestion",docs:{description:"Enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({NewExpression:l=>{if(l.callee.type===u.AST_NODE_TYPES.Identifier&&l.callee.name==="Map"&&l.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),[{elements:p}]=l.arguments,o=a.getSourceCode().text;p.length>1&&p.reduce((e,r)=>(r===null||r.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(r),e),[[]]).forEach(e=>{let r=e.map(i=>{let c;if(i.type===u.AST_NODE_TYPES.ArrayExpression){let[f]=i.elements;f?f.type===u.AST_NODE_TYPES.Literal?c=f.raw:c=o.slice(...f.range):c=`${f}`}else c=o.slice(...i.range);return{size:y(i.range),node:i,name:c}});for(let i=1;i<r.length;i++){let c=r.at(i-1),f=r.at(i);m(c,f,d)&&a.report({messageId:"unexpectedMapElementsOrder",data:{first:c.name,second:f.name},node:f.node,fix:b=>{let S=a.getSourceCode(),{text:I}=S;return E(b,I,r,d)}})}})}}})}),A="sort-named-exports",z=g({name:A,meta:{type:"suggestion",docs:{description:"Enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ExportNamedDeclaration:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.specifiers.length>1){let p=l.specifiers.map(o=>{let{range:t,local:{name:e}}=o;return{size:y(t),node:o,name:e}});for(let o=1;o<p.length;o++){let t=p.at(o-1),e=p.at(o);if(m(t,e,d)){let r=l.specifiers[o];a.report({messageId:"unexpectedNamedExportsOrder",data:{first:t.name,second:e.name},node:r,fix:i=>{let c=a.getSourceCode(),{text:f}=c;return E(i,f,p,d)}})}}}}})}),P="sort-named-imports",v=g({name:P,meta:{type:"suggestion",docs:{description:"Enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ImportDeclaration:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.specifiers.length>1){let p=l.specifiers.map(o=>{let{range:t,local:{name:e}}=o;return{size:y(t),node:o,name:e}});for(let o=1;o<p.length;o++){let t=p.at(o-1),e=p.at(o);if(m(t,e,d)){let r=l.specifiers[o];a.report({messageId:"unexpectedNamedImportsOrder",data:{first:t.name,second:e.name},node:r,fix:i=>{let c=a.getSourceCode(),{text:f}=c;return E(i,f,p,d)}})}}}}})}),D="sort-object-keys",J=g({name:D,meta:{type:"suggestion",docs:{description:"Enforce sorted object keys",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedObjectKeysOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ObjectExpression:l=>{if(l.properties.length>1){let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),p=a.getSourceCode().text;(t=>t.reduce((e,r)=>{if(r.type===u.AST_NODE_TYPES.SpreadElement)return e.push([]),e;let i;r.key.type===u.AST_NODE_TYPES.Identifier?{name:i}=r.key:r.key.type===u.AST_NODE_TYPES.Literal?i=`${r.key.value}`:i=p.slice(...r.key.range);let c={size:y(r.range),node:r,name:i};return e.at(-1).push(c),e},[[]]))(l.properties).forEach(t=>{if(t.length>1)for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e);m(r,i,d)&&a.report({messageId:"unexpectedObjectKeysOrder",data:{first:r.name,second:i.name},node:i.node,fix:c=>E(c,p,t,d)})}})}}})}),j="sort-union-types",X=g({name:j,meta:{type:"suggestion",docs:{description:"Enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({TSUnionType:l=>{let d=a.getSourceCode().text,p=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),o=l.types.map(t=>{let{range:e}=t,r=d.slice(...e);return{size:y(e),node:t,name:r}});for(let t=1;t<o.length;t++){let e=o.at(t-1),r=o.at(t);if(m(e,r,p)){let i=l.types[t];a.report({messageId:"unexpectedUnionTypesOrder",data:{first:e.name,second:r.name},node:i,fix:c=>{let f=a.getSourceCode(),{text:b}=f;return E(c,b,o,p)}})}}}})});let O=a=>{let l={[T]:["error",{spreadLast:!0}],[_]:["error"],[x]:["error"],[N]:["error"],[A]:["error"],[P]:["error"],[D]:["error"],[j]:["error"]};return Object.fromEntries(Object.entries(l).map(([d,[p,o={}]])=>[d,[p,Object.assign(o,a)]]))};const w={name:C,rules:{[T]:R,[_]:$,[x]:U,[N]:k,[A]:z,[P]:v,[D]:J,[j]:X},configs:{"recommended-alphabetical":O({type:s.alphabetical,order:n.asc}),"recommended-natural":O({type:s.natural,order:n.asc}),"recommended-line-length":O({type:s["line-length"],order:n.desc})}};module.exports=w;
|
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,196 @@
|
|
|
1
|
-
import { AST_NODE_TYPES as
|
|
2
|
-
import { ESLintUtils as
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
(
|
|
7
|
-
), y = (
|
|
8
|
-
let [
|
|
9
|
-
return
|
|
1
|
+
import { AST_NODE_TYPES as u } from "@typescript-eslint/types";
|
|
2
|
+
import { ESLintUtils as R } from "@typescript-eslint/utils";
|
|
3
|
+
import $ from "natural-compare-lite";
|
|
4
|
+
const U = "eslint-plugin-perfectionist", k = "azat-io/eslint-plugin-perfectionist";
|
|
5
|
+
let g = R.RuleCreator(
|
|
6
|
+
(r) => `https://github.com/${k}/blob/main/docs/rules/${r}.md`
|
|
7
|
+
), y = (r) => {
|
|
8
|
+
let [l, d] = r;
|
|
9
|
+
return d - l;
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
return
|
|
15
|
-
|
|
11
|
+
var s = /* @__PURE__ */ ((r) => (r.alphabetical = "alphabetical", r.natural = "natural", r["line-length"] = "line-length", r))(s || {}), n = /* @__PURE__ */ ((r) => (r.asc = "asc", r.desc = "desc", r))(n || {});
|
|
12
|
+
let m = (r, l, d) => {
|
|
13
|
+
let p = d.order === "asc" ? 1 : -1, o;
|
|
14
|
+
return d.type === s.alphabetical ? o = (t, e) => t.name.localeCompare(e.name) : d.type === s.natural ? o = (t, e) => $(t.name, e.name) : o = (t, e) => t.size - e.size, p * o(r, l) > 0;
|
|
15
|
+
}, h = (r, l, d, p) => {
|
|
16
|
+
let o = [...d].sort((e, a) => Number(m(e, a, p)) || -1);
|
|
17
|
+
p.spreadLast && o.forEach((e, a) => {
|
|
18
|
+
e.node.type === u.SpreadElement && o.push(o.splice(a, 1).at(0));
|
|
19
|
+
});
|
|
20
|
+
let t = (e) => [e.range.at(0), e.range.at(1)];
|
|
21
|
+
return d.map(
|
|
22
|
+
({ node: e }, a) => r.replaceTextRange(t(e), l.slice(...t(o[a].node)))
|
|
16
23
|
);
|
|
17
|
-
},
|
|
18
|
-
const
|
|
19
|
-
name:
|
|
24
|
+
}, b = (r = {}, l) => Object.assign(l, r);
|
|
25
|
+
const N = "sort-array-includes", z = g({
|
|
26
|
+
name: N,
|
|
20
27
|
meta: {
|
|
21
28
|
type: "suggestion",
|
|
22
29
|
docs: {
|
|
23
|
-
description: "Enforce sorted
|
|
30
|
+
description: "Enforce sorted arrays before include method",
|
|
24
31
|
recommended: !1
|
|
25
32
|
},
|
|
26
|
-
messages: {
|
|
27
|
-
unexpectedInterfacePropertiesOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
28
|
-
},
|
|
29
33
|
fixable: "code",
|
|
30
34
|
schema: [
|
|
31
35
|
{
|
|
32
36
|
type: "object",
|
|
33
37
|
properties: {
|
|
34
38
|
type: {
|
|
35
|
-
enum: [
|
|
39
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
40
|
+
default: s.natural
|
|
36
41
|
},
|
|
37
42
|
order: {
|
|
38
|
-
enum: [
|
|
43
|
+
enum: [n.asc, n.desc],
|
|
44
|
+
default: n.asc
|
|
45
|
+
},
|
|
46
|
+
spreadLast: {
|
|
47
|
+
type: "boolean",
|
|
48
|
+
default: !1
|
|
39
49
|
}
|
|
40
50
|
},
|
|
41
51
|
additionalProperties: !1
|
|
42
52
|
}
|
|
43
|
-
]
|
|
53
|
+
],
|
|
54
|
+
messages: {
|
|
55
|
+
unexpectedArrayIncludesOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
56
|
+
}
|
|
44
57
|
},
|
|
45
58
|
defaultOptions: [
|
|
46
59
|
{
|
|
47
|
-
type:
|
|
48
|
-
order:
|
|
60
|
+
type: s.alphabetical,
|
|
61
|
+
order: n.asc
|
|
49
62
|
}
|
|
50
63
|
],
|
|
51
|
-
create: (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
create: (r) => ({
|
|
65
|
+
MemberExpression: (l) => {
|
|
66
|
+
if ((l.object.type === u.ArrayExpression || l.object.type === u.NewExpression) && l.property.type === u.Identifier && l.property.name === "includes") {
|
|
67
|
+
let d = b(r.options.at(0), {
|
|
68
|
+
type: s.alphabetical,
|
|
69
|
+
order: n.asc,
|
|
70
|
+
spreadLast: !1
|
|
71
|
+
}), p = l.object.type === u.ArrayExpression ? l.object.elements : l.object.arguments;
|
|
72
|
+
if (p.length > 1) {
|
|
73
|
+
let o = r.getSourceCode().text, t = p.reduce(
|
|
74
|
+
(e, a) => (a === null || e.at(0).push({
|
|
75
|
+
name: a.type === u.Literal ? a.raw : o.slice(...a.range),
|
|
76
|
+
size: y(a.range),
|
|
77
|
+
type: a.type,
|
|
78
|
+
node: a
|
|
79
|
+
}), e),
|
|
80
|
+
[[], []]
|
|
81
|
+
).flat();
|
|
82
|
+
for (let e = 1; e < t.length; e++) {
|
|
83
|
+
let a = t.at(e - 1), i = t.at(e), c;
|
|
84
|
+
d.spreadLast && a.node.type === u.Literal && i.node.type === u.SpreadElement ? c = !1 : d.spreadLast && a.node.type === u.SpreadElement && i.node.type === u.Literal ? c = !0 : c = m(a, i, d), c && r.report({
|
|
85
|
+
messageId: "unexpectedArrayIncludesOrder",
|
|
86
|
+
data: {
|
|
87
|
+
first: a.name,
|
|
88
|
+
second: i.name
|
|
89
|
+
},
|
|
90
|
+
node: i.node,
|
|
91
|
+
fix: (f) => {
|
|
92
|
+
let E = r.getSourceCode(), { text: x } = E;
|
|
93
|
+
return h(f, x, t, d);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
79
96
|
}
|
|
80
|
-
};
|
|
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
|
-
node: e,
|
|
83
|
-
name: s,
|
|
84
|
-
size: r
|
|
85
|
-
};
|
|
86
|
-
});
|
|
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
|
-
t.report({
|
|
92
|
-
messageId: "unexpectedInterfacePropertiesOrder",
|
|
93
|
-
data: {
|
|
94
|
-
first: n.name,
|
|
95
|
-
second: p.name
|
|
96
|
-
},
|
|
97
|
-
node: m,
|
|
98
|
-
fix: (u) => {
|
|
99
|
-
let g = t.getSourceCode(), { text: f } = g;
|
|
100
|
-
return N(u, f, d, a);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
97
|
}
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
})
|
|
107
|
-
}),
|
|
108
|
-
name:
|
|
101
|
+
}), S = "sort-interfaces", T = g({
|
|
102
|
+
name: S,
|
|
109
103
|
meta: {
|
|
110
104
|
type: "suggestion",
|
|
111
105
|
docs: {
|
|
112
106
|
description: "Enforce sorted interface properties",
|
|
113
107
|
recommended: !1
|
|
114
108
|
},
|
|
109
|
+
fixable: "code",
|
|
110
|
+
schema: [
|
|
111
|
+
{
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: {
|
|
114
|
+
type: {
|
|
115
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
116
|
+
default: s.natural
|
|
117
|
+
},
|
|
118
|
+
order: {
|
|
119
|
+
enum: [n.asc, n.desc],
|
|
120
|
+
default: n.asc
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
additionalProperties: !1
|
|
124
|
+
}
|
|
125
|
+
],
|
|
115
126
|
messages: {
|
|
116
|
-
|
|
127
|
+
unexpectedInterfacePropertiesOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
defaultOptions: [
|
|
131
|
+
{
|
|
132
|
+
type: s.alphabetical,
|
|
133
|
+
order: n.asc
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
create: (r) => ({
|
|
137
|
+
TSInterfaceBody: (l) => {
|
|
138
|
+
let d = b(r.options.at(0), {
|
|
139
|
+
type: s.alphabetical,
|
|
140
|
+
order: n.asc
|
|
141
|
+
});
|
|
142
|
+
if (l.body.length > 1) {
|
|
143
|
+
let p = r.getSourceCode().text, o = l.body.map((t) => {
|
|
144
|
+
var a, i, c;
|
|
145
|
+
let e;
|
|
146
|
+
if (t.type === u.TSPropertySignature)
|
|
147
|
+
if (t.key.type === u.Identifier)
|
|
148
|
+
({ name: e } = t.key);
|
|
149
|
+
else if (t.key.type === u.Literal)
|
|
150
|
+
e = `${t.key.value}`;
|
|
151
|
+
else {
|
|
152
|
+
let f;
|
|
153
|
+
if ((a = t.typeAnnotation) != null && a.range.at(0))
|
|
154
|
+
f = t.typeAnnotation.range.at(0);
|
|
155
|
+
else {
|
|
156
|
+
let E = t.optional ? 1 : 0;
|
|
157
|
+
f = t.range.at(1) - E;
|
|
158
|
+
}
|
|
159
|
+
e = p.slice(t.range.at(0), f);
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
t.type === u.TSIndexSignature ? e = p.slice(t.range.at(0), ((i = t.typeAnnotation) == null ? void 0 : i.range.at(0)) ?? t.range.at(1)) : e = p.slice(t.range.at(0), ((c = t.returnType) == null ? void 0 : c.range.at(0)) ?? t.range.at(1));
|
|
163
|
+
return {
|
|
164
|
+
size: y(t.range),
|
|
165
|
+
node: t,
|
|
166
|
+
name: e
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
for (let t = 1; t < o.length; t++) {
|
|
170
|
+
let e = o.at(t - 1), a = o.at(t);
|
|
171
|
+
if (m(e, a, d)) {
|
|
172
|
+
let i = l.body[t];
|
|
173
|
+
r.report({
|
|
174
|
+
messageId: "unexpectedInterfacePropertiesOrder",
|
|
175
|
+
data: {
|
|
176
|
+
first: e.name,
|
|
177
|
+
second: a.name
|
|
178
|
+
},
|
|
179
|
+
node: i,
|
|
180
|
+
fix: (c) => h(c, p, o, d)
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
})
|
|
187
|
+
}), j = "sort-jsx-props", _ = g({
|
|
188
|
+
name: j,
|
|
189
|
+
meta: {
|
|
190
|
+
type: "suggestion",
|
|
191
|
+
docs: {
|
|
192
|
+
description: "Enforce sorted JSX props",
|
|
193
|
+
recommended: !1
|
|
117
194
|
},
|
|
118
195
|
fixable: "code",
|
|
119
196
|
schema: [
|
|
@@ -121,65 +198,145 @@ const b = "sort-interfaces", _ = E({
|
|
|
121
198
|
type: "object",
|
|
122
199
|
properties: {
|
|
123
200
|
type: {
|
|
124
|
-
enum: [
|
|
201
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
202
|
+
default: s.natural
|
|
125
203
|
},
|
|
126
204
|
order: {
|
|
127
|
-
enum: [
|
|
205
|
+
enum: [n.asc, n.desc],
|
|
206
|
+
default: n.asc
|
|
128
207
|
}
|
|
129
208
|
},
|
|
130
209
|
additionalProperties: !1
|
|
131
210
|
}
|
|
132
|
-
]
|
|
211
|
+
],
|
|
212
|
+
messages: {
|
|
213
|
+
unexpectedJSXPropsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
214
|
+
}
|
|
133
215
|
},
|
|
134
216
|
defaultOptions: [
|
|
135
217
|
{
|
|
136
|
-
type:
|
|
137
|
-
order:
|
|
218
|
+
type: s.alphabetical,
|
|
219
|
+
order: n.asc
|
|
138
220
|
}
|
|
139
221
|
],
|
|
140
|
-
create: (
|
|
141
|
-
JSXElement: (
|
|
142
|
-
let
|
|
143
|
-
type:
|
|
144
|
-
order:
|
|
222
|
+
create: (r) => ({
|
|
223
|
+
JSXElement: (l) => {
|
|
224
|
+
let d = b(r.options.at(0), {
|
|
225
|
+
type: s.alphabetical,
|
|
226
|
+
order: n.asc
|
|
145
227
|
});
|
|
146
|
-
|
|
147
|
-
(
|
|
228
|
+
l.openingElement.attributes.reduce(
|
|
229
|
+
(o, t) => (t.type === "JSXAttribute" ? o.at(-1).push(t) : o.push([]), o),
|
|
148
230
|
[[]]
|
|
149
|
-
).forEach((
|
|
150
|
-
let
|
|
151
|
-
name:
|
|
152
|
-
size: y(
|
|
153
|
-
node:
|
|
231
|
+
).forEach((o) => {
|
|
232
|
+
let t = o.map((e) => ({
|
|
233
|
+
name: e.name.type === u.JSXNamespacedName ? `${e.name.namespace.name}:${e.name.name.name}` : e.name.name,
|
|
234
|
+
size: y(e.range),
|
|
235
|
+
node: e
|
|
154
236
|
}));
|
|
155
|
-
for (let
|
|
156
|
-
let
|
|
157
|
-
|
|
237
|
+
for (let e = 1; e < t.length; e++) {
|
|
238
|
+
let a = t.at(e - 1), i = t.at(e);
|
|
239
|
+
m(a, i, d) && r.report({
|
|
158
240
|
messageId: "unexpectedJSXPropsOrder",
|
|
159
241
|
data: {
|
|
160
|
-
first:
|
|
161
|
-
second:
|
|
242
|
+
first: a.name,
|
|
243
|
+
second: i.name
|
|
162
244
|
},
|
|
163
|
-
node:
|
|
164
|
-
fix: (
|
|
165
|
-
let f =
|
|
166
|
-
return
|
|
245
|
+
node: i.node,
|
|
246
|
+
fix: (c) => {
|
|
247
|
+
let f = r.getSourceCode().text;
|
|
248
|
+
return h(c, f, t, d);
|
|
167
249
|
}
|
|
168
250
|
});
|
|
169
251
|
}
|
|
170
252
|
});
|
|
171
253
|
}
|
|
172
254
|
})
|
|
173
|
-
}),
|
|
174
|
-
name:
|
|
255
|
+
}), I = "sort-map-elements", v = g({
|
|
256
|
+
name: I,
|
|
175
257
|
meta: {
|
|
176
258
|
type: "suggestion",
|
|
177
259
|
docs: {
|
|
178
|
-
description: "Enforce sorted
|
|
260
|
+
description: "Enforce sorted Map elements",
|
|
179
261
|
recommended: !1
|
|
180
262
|
},
|
|
263
|
+
fixable: "code",
|
|
264
|
+
schema: [
|
|
265
|
+
{
|
|
266
|
+
type: "object",
|
|
267
|
+
properties: {
|
|
268
|
+
type: {
|
|
269
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
270
|
+
default: s.natural
|
|
271
|
+
},
|
|
272
|
+
order: {
|
|
273
|
+
enum: [n.asc, n.desc],
|
|
274
|
+
default: n.asc
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
additionalProperties: !1
|
|
278
|
+
}
|
|
279
|
+
],
|
|
181
280
|
messages: {
|
|
182
|
-
|
|
281
|
+
unexpectedMapElementsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
defaultOptions: [
|
|
285
|
+
{
|
|
286
|
+
type: s.alphabetical,
|
|
287
|
+
order: n.asc
|
|
288
|
+
}
|
|
289
|
+
],
|
|
290
|
+
create: (r) => ({
|
|
291
|
+
NewExpression: (l) => {
|
|
292
|
+
if (l.callee.type === u.Identifier && l.callee.name === "Map" && l.arguments[0].type === u.ArrayExpression) {
|
|
293
|
+
let d = b(r.options.at(0), {
|
|
294
|
+
type: s.alphabetical,
|
|
295
|
+
order: n.asc
|
|
296
|
+
}), [{ elements: p }] = l.arguments, o = r.getSourceCode().text;
|
|
297
|
+
p.length > 1 && p.reduce(
|
|
298
|
+
(e, a) => (a === null || a.type === u.SpreadElement ? e.push([]) : e.at(-1).push(a), e),
|
|
299
|
+
[[]]
|
|
300
|
+
).forEach((e) => {
|
|
301
|
+
let a = e.map((i) => {
|
|
302
|
+
let c;
|
|
303
|
+
if (i.type === u.ArrayExpression) {
|
|
304
|
+
let [f] = i.elements;
|
|
305
|
+
f ? f.type === u.Literal ? c = f.raw : c = o.slice(...f.range) : c = `${f}`;
|
|
306
|
+
} else
|
|
307
|
+
c = o.slice(...i.range);
|
|
308
|
+
return {
|
|
309
|
+
size: y(i.range),
|
|
310
|
+
node: i,
|
|
311
|
+
name: c
|
|
312
|
+
};
|
|
313
|
+
});
|
|
314
|
+
for (let i = 1; i < a.length; i++) {
|
|
315
|
+
let c = a.at(i - 1), f = a.at(i);
|
|
316
|
+
m(c, f, d) && r.report({
|
|
317
|
+
messageId: "unexpectedMapElementsOrder",
|
|
318
|
+
data: {
|
|
319
|
+
first: c.name,
|
|
320
|
+
second: f.name
|
|
321
|
+
},
|
|
322
|
+
node: f.node,
|
|
323
|
+
fix: (E) => {
|
|
324
|
+
let x = r.getSourceCode(), { text: M } = x;
|
|
325
|
+
return h(E, M, a, d);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
}), L = "sort-named-exports", J = g({
|
|
334
|
+
name: L,
|
|
335
|
+
meta: {
|
|
336
|
+
type: "suggestion",
|
|
337
|
+
docs: {
|
|
338
|
+
description: "Enforce sorted named exports",
|
|
339
|
+
recommended: !1
|
|
183
340
|
},
|
|
184
341
|
fixable: "code",
|
|
185
342
|
schema: [
|
|
@@ -187,54 +344,59 @@ const b = "sort-interfaces", _ = E({
|
|
|
187
344
|
type: "object",
|
|
188
345
|
properties: {
|
|
189
346
|
type: {
|
|
190
|
-
enum: [
|
|
347
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
348
|
+
default: s.natural
|
|
191
349
|
},
|
|
192
350
|
order: {
|
|
193
|
-
enum: [
|
|
351
|
+
enum: [n.asc, n.desc],
|
|
352
|
+
default: n.asc
|
|
194
353
|
}
|
|
195
354
|
},
|
|
196
355
|
additionalProperties: !1
|
|
197
356
|
}
|
|
198
|
-
]
|
|
357
|
+
],
|
|
358
|
+
messages: {
|
|
359
|
+
unexpectedNamedExportsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
360
|
+
}
|
|
199
361
|
},
|
|
200
362
|
defaultOptions: [
|
|
201
363
|
{
|
|
202
|
-
type:
|
|
203
|
-
order:
|
|
364
|
+
type: s.alphabetical,
|
|
365
|
+
order: n.asc
|
|
204
366
|
}
|
|
205
367
|
],
|
|
206
|
-
create: (
|
|
207
|
-
ExportNamedDeclaration: (
|
|
208
|
-
let
|
|
209
|
-
type:
|
|
210
|
-
order:
|
|
368
|
+
create: (r) => ({
|
|
369
|
+
ExportNamedDeclaration: (l) => {
|
|
370
|
+
let d = b(r.options.at(0), {
|
|
371
|
+
type: s.alphabetical,
|
|
372
|
+
order: n.asc
|
|
211
373
|
});
|
|
212
|
-
if (
|
|
213
|
-
let
|
|
374
|
+
if (l.specifiers.length > 1) {
|
|
375
|
+
let p = l.specifiers.map((o) => {
|
|
214
376
|
let {
|
|
215
|
-
range:
|
|
216
|
-
local: { name:
|
|
217
|
-
} =
|
|
377
|
+
range: t,
|
|
378
|
+
local: { name: e }
|
|
379
|
+
} = o;
|
|
218
380
|
return {
|
|
219
|
-
size: y(
|
|
220
|
-
node:
|
|
221
|
-
name:
|
|
381
|
+
size: y(t),
|
|
382
|
+
node: o,
|
|
383
|
+
name: e
|
|
222
384
|
};
|
|
223
385
|
});
|
|
224
|
-
for (let
|
|
225
|
-
let
|
|
226
|
-
if (
|
|
227
|
-
let
|
|
228
|
-
|
|
386
|
+
for (let o = 1; o < p.length; o++) {
|
|
387
|
+
let t = p.at(o - 1), e = p.at(o);
|
|
388
|
+
if (m(t, e, d)) {
|
|
389
|
+
let a = l.specifiers[o];
|
|
390
|
+
r.report({
|
|
229
391
|
messageId: "unexpectedNamedExportsOrder",
|
|
230
392
|
data: {
|
|
231
|
-
first:
|
|
232
|
-
second:
|
|
393
|
+
first: t.name,
|
|
394
|
+
second: e.name
|
|
233
395
|
},
|
|
234
|
-
node:
|
|
235
|
-
fix: (
|
|
236
|
-
let
|
|
237
|
-
return
|
|
396
|
+
node: a,
|
|
397
|
+
fix: (i) => {
|
|
398
|
+
let c = r.getSourceCode(), { text: f } = c;
|
|
399
|
+
return h(i, f, p, d);
|
|
238
400
|
}
|
|
239
401
|
});
|
|
240
402
|
}
|
|
@@ -242,71 +404,73 @@ const b = "sort-interfaces", _ = E({
|
|
|
242
404
|
}
|
|
243
405
|
}
|
|
244
406
|
})
|
|
245
|
-
}),
|
|
246
|
-
name:
|
|
407
|
+
}), A = "sort-named-imports", X = g({
|
|
408
|
+
name: A,
|
|
247
409
|
meta: {
|
|
248
410
|
type: "suggestion",
|
|
249
411
|
docs: {
|
|
250
|
-
description: "Enforce sorted
|
|
412
|
+
description: "Enforce sorted named imports",
|
|
251
413
|
recommended: !1
|
|
252
414
|
},
|
|
253
|
-
messages: {
|
|
254
|
-
unexpectedNamedImportsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
255
|
-
},
|
|
256
415
|
fixable: "code",
|
|
257
416
|
schema: [
|
|
258
417
|
{
|
|
259
418
|
type: "object",
|
|
260
419
|
properties: {
|
|
261
420
|
type: {
|
|
262
|
-
enum: [
|
|
421
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
422
|
+
default: s.natural
|
|
263
423
|
},
|
|
264
424
|
order: {
|
|
265
|
-
enum: [
|
|
425
|
+
enum: [n.asc, n.desc],
|
|
426
|
+
default: n.asc
|
|
266
427
|
}
|
|
267
428
|
},
|
|
268
429
|
additionalProperties: !1
|
|
269
430
|
}
|
|
270
|
-
]
|
|
431
|
+
],
|
|
432
|
+
messages: {
|
|
433
|
+
unexpectedNamedImportsOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
434
|
+
}
|
|
271
435
|
},
|
|
272
436
|
defaultOptions: [
|
|
273
437
|
{
|
|
274
|
-
type:
|
|
275
|
-
order:
|
|
438
|
+
type: s.alphabetical,
|
|
439
|
+
order: n.asc
|
|
276
440
|
}
|
|
277
441
|
],
|
|
278
|
-
create: (
|
|
279
|
-
ImportDeclaration: (
|
|
280
|
-
let
|
|
281
|
-
type:
|
|
282
|
-
order:
|
|
442
|
+
create: (r) => ({
|
|
443
|
+
ImportDeclaration: (l) => {
|
|
444
|
+
let d = b(r.options.at(0), {
|
|
445
|
+
type: s.alphabetical,
|
|
446
|
+
order: n.asc
|
|
283
447
|
});
|
|
284
|
-
if (
|
|
285
|
-
let
|
|
448
|
+
if (l.specifiers.length > 1) {
|
|
449
|
+
let p = l.specifiers.map((o) => {
|
|
286
450
|
let {
|
|
287
|
-
range:
|
|
288
|
-
local: { name:
|
|
289
|
-
} =
|
|
451
|
+
range: t,
|
|
452
|
+
local: { name: e }
|
|
453
|
+
} = o;
|
|
290
454
|
return {
|
|
291
|
-
size: y(
|
|
292
|
-
node:
|
|
293
|
-
name:
|
|
455
|
+
size: y(t),
|
|
456
|
+
node: o,
|
|
457
|
+
name: e
|
|
294
458
|
};
|
|
295
459
|
});
|
|
296
|
-
for (let
|
|
297
|
-
let
|
|
298
|
-
if (
|
|
299
|
-
let
|
|
300
|
-
|
|
460
|
+
for (let o = 1; o < p.length; o++) {
|
|
461
|
+
let t = p.at(o - 1), e = p.at(o);
|
|
462
|
+
if (m(t, e, d)) {
|
|
463
|
+
let a = l.specifiers[o];
|
|
464
|
+
r.report({
|
|
301
465
|
messageId: "unexpectedNamedImportsOrder",
|
|
302
466
|
data: {
|
|
303
|
-
first:
|
|
304
|
-
second:
|
|
467
|
+
first: t.name,
|
|
468
|
+
second: e.name
|
|
305
469
|
},
|
|
306
|
-
node:
|
|
307
|
-
fix: (
|
|
308
|
-
let
|
|
309
|
-
return
|
|
470
|
+
node: a,
|
|
471
|
+
fix: (i) => {
|
|
472
|
+
let c = r.getSourceCode(), { text: f } = c;
|
|
473
|
+
return h(i, f, p, d);
|
|
310
474
|
}
|
|
311
475
|
});
|
|
312
476
|
}
|
|
@@ -314,16 +478,87 @@ const b = "sort-interfaces", _ = E({
|
|
|
314
478
|
}
|
|
315
479
|
}
|
|
316
480
|
})
|
|
317
|
-
}),
|
|
318
|
-
name:
|
|
481
|
+
}), C = "sort-object-keys", w = g({
|
|
482
|
+
name: C,
|
|
319
483
|
meta: {
|
|
320
484
|
type: "suggestion",
|
|
321
485
|
docs: {
|
|
322
|
-
description: "Enforce sorted
|
|
486
|
+
description: "Enforce sorted object keys",
|
|
323
487
|
recommended: !1
|
|
324
488
|
},
|
|
489
|
+
fixable: "code",
|
|
490
|
+
schema: [
|
|
491
|
+
{
|
|
492
|
+
type: "object",
|
|
493
|
+
properties: {
|
|
494
|
+
type: {
|
|
495
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
496
|
+
default: s.natural
|
|
497
|
+
},
|
|
498
|
+
order: {
|
|
499
|
+
enum: [n.asc, n.desc],
|
|
500
|
+
default: n.asc
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
additionalProperties: !1
|
|
504
|
+
}
|
|
505
|
+
],
|
|
325
506
|
messages: {
|
|
326
|
-
|
|
507
|
+
unexpectedObjectKeysOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
defaultOptions: [
|
|
511
|
+
{
|
|
512
|
+
type: s.alphabetical,
|
|
513
|
+
order: n.asc
|
|
514
|
+
}
|
|
515
|
+
],
|
|
516
|
+
create: (r) => ({
|
|
517
|
+
ObjectExpression: (l) => {
|
|
518
|
+
if (l.properties.length > 1) {
|
|
519
|
+
let d = b(r.options.at(0), {
|
|
520
|
+
type: s.alphabetical,
|
|
521
|
+
order: n.asc
|
|
522
|
+
}), p = r.getSourceCode().text;
|
|
523
|
+
((t) => t.reduce(
|
|
524
|
+
(e, a) => {
|
|
525
|
+
if (a.type === u.SpreadElement)
|
|
526
|
+
return e.push([]), e;
|
|
527
|
+
let i;
|
|
528
|
+
a.key.type === u.Identifier ? { name: i } = a.key : a.key.type === u.Literal ? i = `${a.key.value}` : i = p.slice(...a.key.range);
|
|
529
|
+
let c = {
|
|
530
|
+
size: y(a.range),
|
|
531
|
+
node: a,
|
|
532
|
+
name: i
|
|
533
|
+
};
|
|
534
|
+
return e.at(-1).push(c), e;
|
|
535
|
+
},
|
|
536
|
+
[[]]
|
|
537
|
+
))(l.properties).forEach((t) => {
|
|
538
|
+
if (t.length > 1)
|
|
539
|
+
for (let e = 1; e < t.length; e++) {
|
|
540
|
+
let a = t.at(e - 1), i = t.at(e);
|
|
541
|
+
m(a, i, d) && r.report({
|
|
542
|
+
messageId: "unexpectedObjectKeysOrder",
|
|
543
|
+
data: {
|
|
544
|
+
first: a.name,
|
|
545
|
+
second: i.name
|
|
546
|
+
},
|
|
547
|
+
node: i.node,
|
|
548
|
+
fix: (c) => h(c, p, t, d)
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
}), P = "sort-union-types", D = g({
|
|
556
|
+
name: P,
|
|
557
|
+
meta: {
|
|
558
|
+
type: "suggestion",
|
|
559
|
+
docs: {
|
|
560
|
+
description: "Enforce sorted union types",
|
|
561
|
+
recommended: !1
|
|
327
562
|
},
|
|
328
563
|
fixable: "code",
|
|
329
564
|
schema: [
|
|
@@ -331,49 +566,54 @@ const b = "sort-interfaces", _ = E({
|
|
|
331
566
|
type: "object",
|
|
332
567
|
properties: {
|
|
333
568
|
type: {
|
|
334
|
-
enum: [
|
|
569
|
+
enum: [s.alphabetical, s.natural, s["line-length"]],
|
|
570
|
+
default: s.natural
|
|
335
571
|
},
|
|
336
572
|
order: {
|
|
337
|
-
enum: [
|
|
573
|
+
enum: [n.asc, n.desc],
|
|
574
|
+
default: n.asc
|
|
338
575
|
}
|
|
339
576
|
},
|
|
340
577
|
additionalProperties: !1
|
|
341
578
|
}
|
|
342
|
-
]
|
|
579
|
+
],
|
|
580
|
+
messages: {
|
|
581
|
+
unexpectedUnionTypesOrder: 'Expected "{{second}}" to come before "{{first}}"'
|
|
582
|
+
}
|
|
343
583
|
},
|
|
344
584
|
defaultOptions: [
|
|
345
585
|
{
|
|
346
|
-
type:
|
|
347
|
-
order:
|
|
586
|
+
type: s.alphabetical,
|
|
587
|
+
order: n.asc
|
|
348
588
|
}
|
|
349
589
|
],
|
|
350
|
-
create: (
|
|
351
|
-
TSUnionType: (
|
|
352
|
-
let
|
|
353
|
-
type:
|
|
354
|
-
order:
|
|
355
|
-
}),
|
|
356
|
-
let { range:
|
|
590
|
+
create: (r) => ({
|
|
591
|
+
TSUnionType: (l) => {
|
|
592
|
+
let d = r.getSourceCode().text, p = b(r.options.at(0), {
|
|
593
|
+
type: s.alphabetical,
|
|
594
|
+
order: n.asc
|
|
595
|
+
}), o = l.types.map((t) => {
|
|
596
|
+
let { range: e } = t, a = d.slice(...e);
|
|
357
597
|
return {
|
|
358
|
-
size: y(
|
|
359
|
-
node:
|
|
360
|
-
name:
|
|
598
|
+
size: y(e),
|
|
599
|
+
node: t,
|
|
600
|
+
name: a
|
|
361
601
|
};
|
|
362
602
|
});
|
|
363
|
-
for (let
|
|
364
|
-
let
|
|
365
|
-
if (
|
|
366
|
-
let
|
|
367
|
-
|
|
603
|
+
for (let t = 1; t < o.length; t++) {
|
|
604
|
+
let e = o.at(t - 1), a = o.at(t);
|
|
605
|
+
if (m(e, a, p)) {
|
|
606
|
+
let i = l.types[t];
|
|
607
|
+
r.report({
|
|
368
608
|
messageId: "unexpectedUnionTypesOrder",
|
|
369
609
|
data: {
|
|
370
|
-
first:
|
|
371
|
-
second:
|
|
610
|
+
first: e.name,
|
|
611
|
+
second: a.name
|
|
372
612
|
},
|
|
373
|
-
node:
|
|
374
|
-
fix: (
|
|
375
|
-
let f =
|
|
376
|
-
return
|
|
613
|
+
node: i,
|
|
614
|
+
fix: (c) => {
|
|
615
|
+
let f = r.getSourceCode(), { text: E } = f;
|
|
616
|
+
return h(c, E, o, p);
|
|
377
617
|
}
|
|
378
618
|
});
|
|
379
619
|
}
|
|
@@ -381,35 +621,51 @@ const b = "sort-interfaces", _ = E({
|
|
|
381
621
|
}
|
|
382
622
|
})
|
|
383
623
|
});
|
|
384
|
-
let
|
|
385
|
-
let
|
|
386
|
-
[
|
|
624
|
+
let O = (r) => {
|
|
625
|
+
let l = {
|
|
626
|
+
[N]: ["error", { spreadLast: !0 }],
|
|
627
|
+
[S]: ["error"],
|
|
628
|
+
[j]: ["error"],
|
|
629
|
+
[I]: ["error"],
|
|
630
|
+
[L]: ["error"],
|
|
631
|
+
[A]: ["error"],
|
|
387
632
|
[C]: ["error"],
|
|
388
|
-
[R]: ["error"],
|
|
389
|
-
[T]: ["error"],
|
|
390
633
|
[P]: ["error"]
|
|
391
634
|
};
|
|
392
635
|
return Object.fromEntries(
|
|
393
|
-
Object.entries(
|
|
394
|
-
|
|
395
|
-
[
|
|
636
|
+
Object.entries(l).map(([d, [p, o = {}]]) => [
|
|
637
|
+
d,
|
|
638
|
+
[p, Object.assign(o, r)]
|
|
396
639
|
])
|
|
397
640
|
);
|
|
398
641
|
};
|
|
399
|
-
const
|
|
400
|
-
name:
|
|
642
|
+
const V = {
|
|
643
|
+
name: U,
|
|
401
644
|
rules: {
|
|
402
|
-
[
|
|
403
|
-
[
|
|
404
|
-
[
|
|
405
|
-
[
|
|
406
|
-
[
|
|
645
|
+
[N]: z,
|
|
646
|
+
[S]: T,
|
|
647
|
+
[j]: _,
|
|
648
|
+
[I]: v,
|
|
649
|
+
[L]: J,
|
|
650
|
+
[A]: X,
|
|
651
|
+
[C]: w,
|
|
652
|
+
[P]: D
|
|
407
653
|
},
|
|
408
654
|
configs: {
|
|
409
|
-
"recommended-
|
|
410
|
-
|
|
655
|
+
"recommended-alphabetical": O({
|
|
656
|
+
type: s.alphabetical,
|
|
657
|
+
order: n.asc
|
|
658
|
+
}),
|
|
659
|
+
"recommended-natural": O({
|
|
660
|
+
type: s.natural,
|
|
661
|
+
order: n.asc
|
|
662
|
+
}),
|
|
663
|
+
"recommended-line-length": O({
|
|
664
|
+
type: s["line-length"],
|
|
665
|
+
order: n.desc
|
|
666
|
+
})
|
|
411
667
|
}
|
|
412
668
|
};
|
|
413
669
|
export {
|
|
414
|
-
|
|
670
|
+
V as default
|
|
415
671
|
};
|
package/license
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright 2023 Azat S. <to@azat.io>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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.6.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>",
|
|
@@ -22,14 +22,26 @@
|
|
|
22
22
|
"require": "./dist/index.js",
|
|
23
23
|
"import": "./dist/index.mjs"
|
|
24
24
|
},
|
|
25
|
+
"./configs/recommended-alphabetical": {
|
|
26
|
+
"require": "./dist/configs/recommended-alphabetical.js",
|
|
27
|
+
"import": "./dist/configs/recommended-alphabetical.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./configs/recommended-line-length": {
|
|
30
|
+
"require": "./dist/configs/recommended-line-length.js",
|
|
31
|
+
"import": "./dist/configs/recommended-line-length.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./configs/recommended-natural": {
|
|
34
|
+
"require": "./dist/configs/recommended-natural.js",
|
|
35
|
+
"import": "./dist/configs/recommended-natural.mjs"
|
|
36
|
+
},
|
|
25
37
|
"./package.json": "./package.json"
|
|
26
38
|
},
|
|
27
39
|
"peerDependencies": {
|
|
28
40
|
"eslint": "^8.39.0"
|
|
29
41
|
},
|
|
30
42
|
"dependencies": {
|
|
31
|
-
"@typescript-eslint/types": "^5.59.
|
|
32
|
-
"@typescript-eslint/utils": "^5.59.
|
|
43
|
+
"@typescript-eslint/types": "^5.59.7",
|
|
44
|
+
"@typescript-eslint/utils": "^5.59.7",
|
|
33
45
|
"natural-compare-lite": "^1.4.0"
|
|
34
46
|
}
|
|
35
47
|
}
|
package/readme.md
CHANGED
|
@@ -22,13 +22,16 @@ npm install --save-dev eslint-plugin-perfectionist
|
|
|
22
22
|
|
|
23
23
|
## Rules
|
|
24
24
|
|
|
25
|
-
| Name
|
|
26
|
-
|
|
|
27
|
-
| [sort-
|
|
28
|
-
| [sort-
|
|
29
|
-
| [sort-
|
|
30
|
-
| [sort-
|
|
31
|
-
| [sort-
|
|
25
|
+
| Name | Description | 💼 | 🛠 |
|
|
26
|
+
| :------------------------------------------------------------------------------------------- | :------------------------------------------ | :-- | :-- |
|
|
27
|
+
| [sort-array-includes](https://eslint-plugin-perfectionist.azat.io/rules/sort-array-includes) | Enforce sorted arrays before include method | ✅ | 🔧 |
|
|
28
|
+
| [sort-interfaces](https://eslint-plugin-perfectionist.azat.io/rules/sort-interfaces) | Enforce sorted interface properties | ✅ | 🔧 |
|
|
29
|
+
| [sort-jsx-props](https://eslint-plugin-perfectionist.azat.io/rules/sort-jsx-props) | Enforce sorted JSX props | ✅ | 🔧 |
|
|
30
|
+
| [sort-map-elements](https://eslint-plugin-perfectionist.azat.io/rules/sort-map-elements) | Enforce sorted Map elements | ✅ | 🔧 |
|
|
31
|
+
| [sort-named-exports](https://eslint-plugin-perfectionist.azat.io/rules/sort-named-exports) | Enforce sorted named exports | ✅ | 🔧 |
|
|
32
|
+
| [sort-named-imports](https://eslint-plugin-perfectionist.azat.io/rules/sort-named-imports) | Enforce sorted named imports | ✅ | 🔧 |
|
|
33
|
+
| [sort-object-keys](https://eslint-plugin-perfectionist.azat.io/rules/sort-object-keys) | Enforce sorted object keys | ✅ | 🔧 |
|
|
34
|
+
| [sort-union-types](https://eslint-plugin-perfectionist.azat.io/rules/sort-union-types) | Enforce sorted union types | ✅ | 🔧 |
|
|
32
35
|
|
|
33
36
|
## See also
|
|
34
37
|
|