eslint-plugin-perfectionist 1.0.1 → 1.1.1

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var F=Object.defineProperty;var ee=(r,o,a)=>o in r?F(r,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[o]=a;var V=(r,o,a)=>(ee(r,typeof o!="symbol"?o+"":o,a),a);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),te=require("natural-compare-lite"),C=require("minimatch"),ae=require("is-core-module"),re=require("json5"),ne=require("path"),se=require("fs");let A=v.ESLintUtils.RuleCreator(r=>`https://eslint-plugin-perfectionist.azat.io/rules/${r}`),x=r=>r.replaceAll(/\s\s+/g," ").trim(),N=r=>{let[o,a]=r;return a-o};var i=(r=>(r.alphabetical="alphabetical",r["line-length"]="line-length",r.natural="natural",r))(i||{}),p=(r=>(r.desc="desc",r.asc="asc",r))(p||{});let O=(r,o,a)=>{let s=a.order==="asc"?1:-1,c,t=e=>a["ignore-case"]?e.toLowerCase():e;return a.type===i.alphabetical?c=(e,n)=>t(e.name).localeCompare(t(n.name)):a.type===i.natural?c=(e,n)=>te(t(e.name),t(n.name)):c=(e,n)=>e.size-n.size,s*c(r,o)>0},b=(r,o)=>[...r].sort((a,s)=>Number(O(a,s,o))||-1),oe=(r,o)=>{let a=o.getTokenAfter(r,{filter:({type:s,value:c})=>!(s===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(c)),includeComments:!0});return((a==null?void 0:a.type)===u.AST_TOKEN_TYPES.Block||(a==null?void 0:a.type)===u.AST_TOKEN_TYPES.Line)&&r.loc.end.line===a.loc.end.line?a:null},H=(r,o)=>{let[a,s]=o.getTokensBefore(r,{filter:({type:c,value:t})=>!(c===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(t)),includeComments:!0,count:2});return((s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Line)&&r.loc.start.line-s.loc.end.line<=1&&(a==null?void 0:a.loc.end.line)!==s.loc.start.line?s:null},I=(r,o)=>{let a=r.range.at(0),s=r.range.at(1),c=o.text.slice(a,s);if(v.ASTUtils.isParenthesized(r,o)){let e=o.getTokenBefore(r,v.ASTUtils.isOpeningParenToken),n=o.getTokenAfter(r,v.ASTUtils.isClosingParenToken);a=e.range.at(0),s=n.range.at(1)}let t=H(r,o);return(c.endsWith(";")||c.endsWith(","))&&(s-=1),t&&(a=t.range.at(0)),[a,s]},D=(r,o,a,s)=>{let c=[];return o.forEach(({node:t},e)=>{c.push(r.replaceTextRange(I(t,s),s.text.slice(...I(a[e].node,s))));let n=oe(a[e].node,s);if(n){let d=[s.getTokenBefore(n).range.at(1),n.range.at(1)];c.push(r.replaceTextRange(d,""));let m=s.getTokenAfter(t);c.push(r.insertTextAfter((m==null?void 0:m.loc.end.line)===t.loc.end.line?m:t,s.text.slice(...d)))}}),c},P=(r={},o)=>Object.assign(o,r),w=(r,o)=>{if(r.length>1)for(let a=1;a<r.length;a++){let s=r.at(a-1),c=r.at(a);s&&c&&o(s,c,a-1)}};const L="sort-array-includes",le=A({name:L,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1},"spread-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({MemberExpression:o=>{if((o.object.type===u.AST_NODE_TYPES.ArrayExpression||o.object.type===u.AST_NODE_TYPES.NewExpression)&&o.property.type===u.AST_NODE_TYPES.Identifier&&o.property.name==="includes"){let a=o.object.type===u.AST_NODE_TYPES.ArrayExpression?o.object.elements:o.object.arguments;if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1,"spread-last":!1}),c=r.getSourceCode(),t=a.reduce((e,n)=>(n!==null&&e.at(0).push({name:n.type===u.AST_NODE_TYPES.Literal?n.raw:c.text.slice(...n.range),size:N(n.range),type:n.type,node:n}),e),[[],[]]).flat();w(t,(e,n)=>{let l;s["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&n.node.type===u.AST_NODE_TYPES.SpreadElement?l=!1:s["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&n.node.type===u.AST_NODE_TYPES.Literal?l=!0:l=O(e,n,s),l&&r.report({messageId:"unexpectedArrayIncludesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:d=>{let m=b(t,s);return s["spread-last"]&&m.forEach((E,_)=>{E.node.type===u.AST_NODE_TYPES.SpreadElement&&m.push(m.splice(_,1).at(0))}),D(d,t,m,c)}})})}}}})}),M="sort-named-exports",ie=A({name:M,meta:{type:"suggestion",docs:{description:"enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ExportNamedDeclaration:o=>{if(o.specifiers.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),s=r.getSourceCode(),c=o.specifiers.map(t=>({size:N(t.range),name:t.local.name,node:t}));w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedNamedExportsOrder",data:{left:t.name,right:e.name},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),$="sort-named-imports",pe=A({name:$,meta:{type:"suggestion",docs:{description:"enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ImportDeclaration:o=>{let a=o.specifiers.filter(({type:s})=>s===u.AST_NODE_TYPES.ImportSpecifier);if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=r.getSourceCode(),t=a.map(e=>({size:N(e.range),name:e.local.name,node:e}));w(t,(e,n)=>{O(e,n,s)&&r.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:n.name},node:n.node,fix:l=>D(l,t,b(t,s),c)})})}}})}),U="sort-object-types",ce=A({name:U,meta:{type:"suggestion",docs:{description:"enforce sorted object types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSTypeLiteral:o=>{if(o.members.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),s=r.getSourceCode(),c=o.members.map(t=>{var m,E;let e,n=s.text.slice(t.range.at(0),t.range.at(1));if(t.type===u.AST_NODE_TYPES.TSPropertySignature)t.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=t.key:t.key.type===u.AST_NODE_TYPES.Literal?e=`${t.key.value}`:e=s.text.slice(t.range.at(0),(m=t.typeAnnotation)==null?void 0:m.range.at(0));else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let _=((E=t.typeAnnotation)==null?void 0:E.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),_)}else e=s.text.slice(t.range.at(0),t.range.at(1));let d=n.endsWith(";")||n.endsWith(",")?1:0;return{size:N(t.range)-d,node:t,name:e}});w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedObjectTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),B="sort-map-elements",de=A({name:B,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({NewExpression:o=>{if(o.callee.type===u.AST_NODE_TYPES.Identifier&&o.callee.name==="Map"&&o.arguments.length&&o.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let[{elements:a}]=o.arguments;if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=r.getSourceCode();a.reduce((e,n)=>(n===null||n.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(n),e),[[]]).forEach(e=>{let n=e.map(l=>{let d;if(l.type===u.AST_NODE_TYPES.ArrayExpression){let[m]=l.elements;m?m.type===u.AST_NODE_TYPES.Literal?d=m.raw:d=c.text.slice(...m.range):d=`${m}`}else d=c.text.slice(...l.range);return{size:N(l.range),node:l,name:d}});w(n,(l,d)=>{O(l,d,s)&&r.report({messageId:"unexpectedMapElementsOrder",data:{left:x(l.name),right:x(d.name)},node:d.node,fix:m=>D(m,n,b(n,s),c)})})})}}}})}),z="sort-union-types",fe=A({name:z,meta:{type:"suggestion",docs:{description:"enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSUnionType:o=>{let a=r.getSourceCode(),s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=o.types.map(t=>({name:a.text.slice(...t.range),size:N(t.range),node:t}));w(c,(t,e)=>{O(t,e,s)&&r.report({messageId:"unexpectedUnionTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,s),a)})})}})}),q="sort-interfaces",ue=A({name:q,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSInterfaceDeclaration:o=>{if(o.body.body.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc,"ignore-pattern":[]});if(!a["ignore-pattern"].some(s=>C.minimatch(o.id.name,s))){let s=r.getSourceCode(),c=o.body.body.map(t=>{var n,l,d;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 m=((n=t.typeAnnotation)==null?void 0:n.range.at(0))??t.range.at(1)-(t.optional?1:0);e=s.text.slice(t.range.at(0),m)}else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let m=((l=t.typeAnnotation)==null?void 0:l.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),m)}else{let m=((d=t.returnType)==null?void 0:d.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),m)}return{size:N(t.range),node:t,name:e}});w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}}})});let Q=(r,o)=>r.reduce((a,s)=>{let c=o(s);return c in a||(a[c]=[]),a[c].push(s),a},{});const J="sort-jsx-props",ge=A({name:J,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"always-on-top":{type:"array",default:[]},"ignore-case":{type:"boolean",default:!1},shorthand:{enum:["first","last","ignore"]},callback:{enum:["first","last","ignore"]},multiline:{enum:["first","last","ignore"]}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({JSXElement:o=>{if(o.openingElement.attributes.length>1){let a=P(r.options.at(0),{type:i.alphabetical,shorthand:"ignore",multiline:"ignore",callback:"ignore","always-on-top":[],"ignore-case":!1,order:p.asc}),s=r.getSourceCode();o.openingElement.attributes.reduce((t,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return t.push([]),t;let n="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&a["always-on-top"].includes(e.name.name)?n="exception":(a.shorthand!=="ignore"&&e.value===null&&(n=a.shorthand),a.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?n=a.callback:a.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(n=a.multiline));let l={name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:N(e.range),node:e,position:n};return t.at(-1).push(l),t},[[]]).forEach(t=>{w(t,(e,n)=>{let l;if(e.position==="exception"&&n.position==="exception")l=a["always-on-top"].indexOf(e.name)>a["always-on-top"].indexOf(n.name);else if(e.position===n.position)l=O(e,n,a);else{let d={exception:2,first:1,ignore:0,last:-1};l=d[e.position]<d[n.position]}l&&r.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:n.name},node:n.node,fix:d=>{let m=Q(t,({position:y})=>y),E=y=>y in m?m[y]:[],_=[E("exception").sort((y,f)=>a["always-on-top"].indexOf(y.name)-a["always-on-top"].indexOf(f.name)),b(E("first"),a),b(E("ignore"),a),b(E("last"),a)].flat();return D(d,t,_,s)}})})})}}})});class Z{static get(){return this._instance?this._instance:(this._instance=re.parse(se.readFileSync(ne.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}V(Z,"_instance");const X="sort-imports",me=A({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{type:"array",default:["~/**"]},"newlines-between":{enum:["ignore","always","never"],default:"always"},"read-tsconfig":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedImportsOrder:'Expected "{{right}}" to come before "{{left}}"',missedSpacingBetweenImports:'Missed spacing between "{{left}}" and "{{right}}" imports',extraSpacingBetweenImports:'Extra spacing between "{{left}}" and "{{right}}" imports'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>{var n;let o=P(r.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:i.alphabetical,"read-tsconfig":!1,order:p.asc,"ignore-case":!1,groups:[]}),a=[];if(o["read-tsconfig"]){let l=Z.get();(n=l.compilerOptions)!=null&&n.paths&&Object.keys(l.compilerOptions.paths).forEach(d=>{a.push(d)})}let s=r.getSourceCode(),c=[],t=l=>{let d,m=g=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(g),E=g=>g.indexOf("..")===0,_=g=>g.indexOf("./")===0,y=g=>{!d&&o.groups.flat().includes(g)&&(d=g)},f=g=>o["internal-pattern"].length&&o["internal-pattern"].some(S=>C.minimatch(g.source.value,S))||a.some(S=>C.minimatch(g.source.value,S));return l.importKind==="type"&&(l.type===u.AST_NODE_TYPES.ImportDeclaration&&(f(l)?y("internal-type"):m(l.source.value)?y("index-type"):E(l.source.value)?y("parent-type"):_(l.source.value)&&y("sibling-type")),y("type")),!d&&l.type===u.AST_NODE_TYPES.ImportDeclaration&&(ae(l.source.value)?y("builtin"):f(l)?y("internal"):m(l.source.value)?y("index"):E(l.source.value)?y("parent"):_(l.source.value)?y("sibling"):y("external")),d??"unknown"},e=l=>{let d;l.type===u.AST_NODE_TYPES.ImportDeclaration?d=l.source.value:l.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&l.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?d=`${l.moduleReference.expression.value}`:d=s.text.slice(...l.moduleReference.range),c.push({size:N(l.range),group:t(l),name:d,node:l})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let l=y=>{for(let f=0,g=o.groups.length;f<g;f++){let S=o.groups[f];if(y.group===S||Array.isArray(S)&&S.includes(y.group))return f}return o.groups.length},d=(y,f)=>!!s.getTokensBetween(y.node,H(f.node,s)||f.node,{includeComments:!0}).length,m=(y,f)=>s.lines.slice(y.node.loc.end.line,f.node.loc.start.line-1).filter(S=>!S.trim().length).length,E=(y,f)=>{let g=[],S=f.reduce((T,h)=>{let Y=l(h);return Y in T?T[Y]=b([...T[Y],h],o):T[Y]=[h],T},{}),j=Object.keys(S).sort().reduce((T,h)=>[...T,...S[h]],[]);return j.forEach((T,h)=>{if(g.push(y.replaceTextRange(I(f.at(h).node,s),s.text.slice(...I(T.node,s)))),o["newlines-between"]!=="ignore"){let Y=j.at(h+1);if(Y){let k=m(f.at(h),f.at(h+1));(o["newlines-between"]==="always"&&l(T)===l(Y)&&k!==0||o["newlines-between"]==="never"&&k>0)&&g.push(y.removeRange([I(f.at(h).node,s).at(1),I(f.at(h+1).node,s).at(0)-1])),o["newlines-between"]==="always"&&k>1&&g.push(y.replaceTextRange([I(f.at(h).node,s).at(1),I(f.at(h+1).node,s).at(0)-1],`
2
- `)),o["newlines-between"]==="always"&&l(T)!==l(Y)&&k===0&&g.push(y.insertTextAfterRange(I(f.at(h).node,s),`
3
- `))}}}),g};c.reduce((y,f)=>{var S;let g=(S=y.at(-1))==null?void 0:S.at(-1);return g&&d(g,f)?y.push([f]):y.at(-1).push(f),y},[[]]).forEach(y=>{w(y,(f,g)=>{let S=l(f),j=l(g),T=m(f,g);!d(f,g)&&(S>j||S===j&&O(f,g,o))&&r.report({messageId:"unexpectedImportsOrder",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}),o["newlines-between"]==="never"&&T>0&&r.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}),o["newlines-between"]==="always"&&(S<j&&T===0?r.report({messageId:"missedSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}):(T>1||S===j&&T>0)&&r.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}))})})}}}}),G="sort-classes",ye=A({name:G,meta:{type:"suggestion",docs:{description:"enforce sorted classes",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[p.asc,p.desc],default:p.asc},groups:{type:"array",default:["property","constructor","method","unknown"]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ClassBody:o=>{if(o.body.length>1){let a=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),s=r.getSourceCode(),c=o.body.map(e=>{var m;let n,l;e.type===u.AST_NODE_TYPES.StaticBlock?l="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?l=s.text.slice(e.range.at(0),((m=e.typeAnnotation)==null?void 0:m.range.at(0))??e.range.at(1)):e.key.type===u.AST_NODE_TYPES.Identifier?{name:l}=e.key:l=s.text.slice(...e.key.range);let d=E=>{!n&&a.groups.flat().includes(E)&&(n=E)};return e.type===u.AST_NODE_TYPES.MethodDefinition?(e.kind==="constructor"&&d("constructor"),e.static&&d("static-method"),e.accessibility==="private"&&d("private-method"),d("method")):e.type===u.AST_NODE_TYPES.PropertyDefinition&&(e.static&&d("static-property"),e.accessibility==="private"&&d("private-property"),d("property")),{size:N(e.range),group:n??"unknown",node:e,name:l}}),t=e=>{for(let n=0,l=a.groups.length;n<l;n++){let d=a.groups[n];if(e.group===d||Array.isArray(d)&&d.includes(e.group))return n}return a.groups.length};w(c,(e,n)=>{let l=t(e),d=t(n);(l>d||l===d&&O(e,n,a))&&r.report({messageId:"unexpectedClassesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:m=>{let E=[],_=c.reduce((f,g)=>{let S=t(g);return S in f?f[S]=b([...f[S],g],a):f[S]=[g],f},{});return Object.keys(_).sort().reduce((f,g)=>[...f,..._[g]],[]).forEach((f,g)=>{E.push(m.replaceTextRange(I(c.at(g).node,s),s.text.slice(...I(f.node,s))))}),E}})})}}})}),K="sort-objects",Ee=A({name:K,meta:{type:"suggestion",docs:{description:"enforce sorted objects",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1},"always-on-top":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ObjectExpression:o=>{if(o.properties.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc,"always-on-top":[]}),s=r.getSourceCode();(t=>t.reduce((e,n)=>{if(n.type===u.AST_NODE_TYPES.SpreadElement)return e.push([]),e;let l,d="ignore";n.key.type===u.AST_NODE_TYPES.Identifier?{name:l}=n.key:n.key.type===u.AST_NODE_TYPES.Literal?l=`${n.key.value}`:l=s.text.slice(...n.key.range),n.key.type===u.AST_NODE_TYPES.Identifier&&a["always-on-top"].includes(n.key.name)&&(d="exception");let m={size:N(n.range),node:n,position:d,name:l};return e.at(-1).push(m),e},[[]]))(o.properties).forEach(t=>{w(t,(e,n)=>{let l;if(e.position==="exception"&&n.position==="exception")l=a["always-on-top"].indexOf(e.name)>a["always-on-top"].indexOf(n.name);else if(e.position===n.position)l=O(e,n,a);else{let d={exception:1,ignore:0};l=d[e.position]<d[n.position]}if(l){let d=m=>{let E=Q(t,({position:f})=>f),_=f=>f in E?E[f]:[],y=[_("exception").sort((f,g)=>a["always-on-top"].indexOf(f.name)-a["always-on-top"].indexOf(g.name)),b(_("ignore"),a)].flat();return D(m,t,y,s)};r.report({messageId:"unexpectedObjectsOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:d})}})})}}})}),W="sort-enums",Se=A({name:W,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[p.asc,p.desc],default:p.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSEnumDeclaration:o=>{if(o.members.length>1&&o.members.some(({initializer:a})=>a)){let a=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1}),s=r.getSourceCode(),c=o.members.map(t=>({name:t.id.type===u.AST_NODE_TYPES.Literal?`${t.id.value}`:`${s.text.slice(...t.id.range)}`,size:N(t.range),node:t}));w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedEnumsOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),he="eslint-plugin-perfectionist";let R=r=>{let o={[X]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"newlines-between":"always","internal-pattern":["~/**"],"read-tsconfig":!1}],[G]:["error",{groups:["static-property","private-property","property","constructor","static-method","private-method","method","unknown"]}],[J]:["error",{"always-on-top":[],shorthand:"ignore",multiline:"first",callback:"ignore"}],[L]:["error",{"spread-last":!0}],[K]:["error",{"always-on-top":[]}],[$]:["error"],[M]:["error"],[U]:["error"],[B]:["error"],[z]:["error"],[q]:["error"],[W]:["error"]};return{rules:Object.fromEntries(Object.entries(o).map(([a,[s,c={}]])=>[`perfectionist/${a}`,[s,Object.assign(c,r)]])),plugins:["perfectionist"]}};const Te={rules:{[L]:le,[G]:ye,[W]:Se,[X]:me,[q]:ue,[J]:ge,[B]:de,[M]:ie,[$]:pe,[U]:ce,[K]:Ee,[z]:fe},configs:{"recommended-alphabetical":R({type:i.alphabetical,order:p.asc,"ignore-case":!1}),"recommended-natural":R({type:i.natural,order:p.asc,"ignore-case":!1}),"recommended-line-length":R({type:i["line-length"],order:p.desc})},name:he};module.exports=Te;
1
+ "use strict";var ee=Object.defineProperty;var te=(a,o,s)=>o in a?ee(a,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[o]=s;var V=(a,o,s)=>(te(a,typeof o!="symbol"?o+"":o,s),s);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),ae=require("natural-compare-lite"),C=require("minimatch"),H=require("is-core-module"),ne=require("json5"),se=require("path"),re=require("fs");let N=v.ESLintUtils.RuleCreator(a=>`https://eslint-plugin-perfectionist.azat.io/rules/${a}`),O=a=>a.replaceAll(/\s\s+/g," ").trim(),P=a=>{let[o,s]=a;return s-o};var l=(a=>(a.alphabetical="alphabetical",a["line-length"]="line-length",a.natural="natural",a))(l||{}),f=(a=>(a.desc="desc",a.asc="asc",a))(f||{});let A=(a,o,s)=>{var e,i;if((e=o.dependencies)!=null&&e.includes(a.name))return!1;if((i=a.dependencies)!=null&&i.includes(o.name))return!0;let r=s.order==="asc"?1:-1,d,n=t=>s["ignore-case"]?t.toLowerCase():t;return s.type===l.alphabetical?d=(t,p)=>n(t.name).localeCompare(n(p.name)):s.type===l.natural?d=(t,p)=>ae(n(t.name),n(p.name)):d=(t,p)=>t.size-p.size,r*d(a,o)>0},b=(a,o)=>[...a].sort((s,r)=>Number(A(s,r,o))||-1),ie=(a,o)=>{let s=o.getTokenAfter(a,{filter:({type:r,value:d})=>!(r===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(d)),includeComments:!0});return((s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Line)&&a.loc.end.line===s.loc.end.line?s:null},Q=(a,o)=>{let[s,r]=o.getTokensBefore(a,{filter:({type:d,value:n})=>!(d===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(n)),includeComments:!0,count:2});return((r==null?void 0:r.type)===u.AST_TOKEN_TYPES.Block||(r==null?void 0:r.type)===u.AST_TOKEN_TYPES.Line)&&a.loc.start.line-r.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==r.loc.start.line?r:null},D=(a,o)=>{var e;let s=a.range.at(0),r=a.range.at(1),d=o.text.slice(s,r);if(v.ASTUtils.isParenthesized(a,o)){let i=o.getTokenBefore(a,v.ASTUtils.isOpeningParenToken),t=o.getTokenAfter(a,v.ASTUtils.isClosingParenToken);s=i.range.at(0),r=t.range.at(1)}let n=Q(a,o);if(d.endsWith(";")||d.endsWith(",")){let i=o.getTokensAfter(a,{includeComments:!0,count:2});a.loc.start.line!==((e=i.at(1))==null?void 0:e.loc.start.line)?r+=1:r-=1}return n&&(s=n.range.at(0)),[s,r]},Y=(a,o,s,r)=>{let d=[];return o.forEach(({node:n},e)=>{d.push(a.replaceTextRange(D(n,r),r.text.slice(...D(s[e].node,r))));let i=ie(s[e].node,r);if(i){let p=[r.getTokenBefore(i).range.at(1),i.range.at(1)];d.push(a.replaceTextRange(p,""));let g=r.getTokenAfter(n);d.push(a.insertTextAfter((g==null?void 0:g.loc.end.line)===n.loc.end.line?g:n,r.text.slice(...p)))}}),d},w=(a={},o)=>Object.assign(o,a),I=(a,o)=>{if(a.length>1)for(let s=1;s<a.length;s++){let r=a.at(s-1),d=a.at(s);r&&d&&o(r,d,s-1)}};const L="sort-array-includes",oe=N({name:L,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1},"spread-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({MemberExpression:o=>{if((o.object.type===u.AST_NODE_TYPES.ArrayExpression||o.object.type===u.AST_NODE_TYPES.NewExpression)&&o.property.type===u.AST_NODE_TYPES.Identifier&&o.property.name==="includes"){let s=o.object.type===u.AST_NODE_TYPES.ArrayExpression?o.object.elements:o.object.arguments;if(s.length>1){let r=w(a.options.at(0),{type:l.alphabetical,order:f.asc,"ignore-case":!1,"spread-last":!1}),d=a.getSourceCode(),n=s.reduce((e,i)=>(i!==null&&e.at(0).push({name:i.type===u.AST_NODE_TYPES.Literal?i.raw:d.text.slice(...i.range),size:P(i.range),type:i.type,node:i}),e),[[],[]]).flat();I(n,(e,i)=>{let t;r["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&i.node.type===u.AST_NODE_TYPES.SpreadElement?t=!1:r["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&i.node.type===u.AST_NODE_TYPES.Literal?t=!0:t=A(e,i,r),t&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{left:O(e.name),right:O(i.name)},node:i.node,fix:p=>{let g=b(n,r);return r["spread-last"]&&g.forEach((S,T)=>{S.node.type===u.AST_NODE_TYPES.SpreadElement&&g.push(g.splice(T,1).at(0))}),Y(p,n,g,d)}})})}}}})}),$="sort-named-exports",le=N({name:$,meta:{type:"suggestion",docs:{description:"enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({ExportNamedDeclaration:o=>{if(o.specifiers.length>1){let s=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc}),r=a.getSourceCode(),d=o.specifiers.map(n=>({size:P(n.range),name:n.local.name,node:n}));I(d,(n,e)=>{A(n,e,s)&&a.report({messageId:"unexpectedNamedExportsOrder",data:{left:n.name,right:e.name},node:e.node,fix:i=>Y(i,d,b(d,s),r)})})}}})}),B="sort-named-imports",pe=N({name:B,meta:{type:"suggestion",docs:{description:"enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({ImportDeclaration:o=>{let s=o.specifiers.filter(({type:r})=>r===u.AST_NODE_TYPES.ImportSpecifier);if(s.length>1){let r=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc}),d=a.getSourceCode(),n=s.map(e=>({size:P(e.range),name:e.local.name,node:e}));I(n,(e,i)=>{A(e,i,r)&&a.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:i.name},node:i.node,fix:t=>Y(t,n,b(n,r),d)})})}}})}),M="sort-object-types",ce=N({name:M,meta:{type:"suggestion",docs:{description:"enforce sorted object types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({TSTypeLiteral:o=>{if(o.members.length>1){let s=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc}),r=a.getSourceCode(),d=o.members.map(n=>{var S,T;let e,i=r.text.slice(n.range.at(0),n.range.at(1)),t=y=>y.replace(/(,|;)$/,"");if(n.type===u.AST_NODE_TYPES.TSPropertySignature)n.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=n.key:n.key.type===u.AST_NODE_TYPES.Literal?e=`${n.key.value}`:e=r.text.slice(n.range.at(0),(S=n.typeAnnotation)==null?void 0:S.range.at(0));else if(n.type===u.AST_NODE_TYPES.TSIndexSignature){let y=((T=n.typeAnnotation)==null?void 0:T.range.at(0))??n.range.at(1);e=t(r.text.slice(n.range.at(0),y))}else e=t(r.text.slice(n.range.at(0),n.range.at(1)));let g=i.endsWith(";")||i.endsWith(",")?1:0;return{size:P(n.range)-g,node:n,name:e}});I(d,(n,e)=>{A(n,e,s)&&a.report({messageId:"unexpectedObjectTypesOrder",data:{left:O(n.name),right:O(e.name)},node:e.node,fix:i=>Y(i,d,b(d,s),r)})})}}})}),U="sort-map-elements",de=N({name:U,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({NewExpression:o=>{if(o.callee.type===u.AST_NODE_TYPES.Identifier&&o.callee.name==="Map"&&o.arguments.length&&o.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let[{elements:s}]=o.arguments;if(s.length>1){let r=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc}),d=a.getSourceCode();s.reduce((e,i)=>(i===null||i.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(i),e),[[]]).forEach(e=>{let i=e.map(t=>{let p;if(t.type===u.AST_NODE_TYPES.ArrayExpression){let[g]=t.elements;g?g.type===u.AST_NODE_TYPES.Literal?p=g.raw:p=d.text.slice(...g.range):p=`${g}`}else p=d.text.slice(...t.range);return{size:P(t.range),node:t,name:p}});I(i,(t,p)=>{A(t,p,r)&&a.report({messageId:"unexpectedMapElementsOrder",data:{left:O(t.name),right:O(p.name)},node:p.node,fix:g=>Y(g,i,b(i,r),d)})})})}}}})}),z="sort-union-types",fe=N({name:z,meta:{type:"suggestion",docs:{description:"enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({TSUnionType:o=>{let s=a.getSourceCode(),r=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc}),d=o.types.map(n=>({name:s.text.slice(...n.range),size:P(n.range),node:n}));I(d,(n,e)=>{A(n,e,r)&&a.report({messageId:"unexpectedUnionTypesOrder",data:{left:O(n.name),right:O(e.name)},node:e.node,fix:i=>Y(i,d,b(d,r),s)})})}})}),q="sort-interfaces",ue=N({name:q,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({TSInterfaceDeclaration:o=>{if(o.body.body.length>1){let s=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc,"ignore-pattern":[]});if(!s["ignore-pattern"].some(r=>C.minimatch(o.id.name,r))){let r=a.getSourceCode(),d=o.body.body.map(n=>{var i,t,p;let e;if(n.type===u.AST_NODE_TYPES.TSPropertySignature)if(n.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=n.key);else if(n.key.type===u.AST_NODE_TYPES.Literal)e=`${n.key.value}`;else{let g=((i=n.typeAnnotation)==null?void 0:i.range.at(0))??n.range.at(1)-(n.optional?1:0);e=r.text.slice(n.range.at(0),g)}else if(n.type===u.AST_NODE_TYPES.TSIndexSignature){let g=((t=n.typeAnnotation)==null?void 0:t.range.at(0))??n.range.at(1);e=r.text.slice(n.range.at(0),g)}else{let g=((p=n.returnType)==null?void 0:p.range.at(0))??n.range.at(1);e=r.text.slice(n.range.at(0),g)}return{size:P(n.range),node:n,name:e}});I(d,(n,e)=>{A(n,e,s)&&a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:O(n.name),right:O(e.name)},node:e.node,fix:i=>Y(i,d,b(d,s),r)})})}}}})});let Z=(a,o)=>a.reduce((s,r)=>{let d=o(r);return d in s||(s[d]=[]),s[d].push(r),s},{});const J="sort-jsx-props",ge=N({name:J,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"always-on-top":{type:"array",default:[]},"ignore-case":{type:"boolean",default:!1},shorthand:{enum:["first","last","ignore"]},callback:{enum:["first","last","ignore"]},multiline:{enum:["first","last","ignore"]}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({JSXElement:o=>{if(o.openingElement.attributes.length>1){let s=w(a.options.at(0),{type:l.alphabetical,shorthand:"ignore",multiline:"ignore",callback:"ignore","always-on-top":[],"ignore-case":!1,order:f.asc}),r=a.getSourceCode();o.openingElement.attributes.reduce((n,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return n.push([]),n;let i="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&s["always-on-top"].includes(e.name.name)?i="exception":(s.shorthand!=="ignore"&&e.value===null&&(i=s.shorthand),s.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?i=s.callback:s.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(i=s.multiline));let t={name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:P(e.range),node:e,position:i};return n.at(-1).push(t),n},[[]]).forEach(n=>{I(n,(e,i)=>{let t;if(e.position==="exception"&&i.position==="exception")t=s["always-on-top"].indexOf(e.name)>s["always-on-top"].indexOf(i.name);else if(e.position===i.position)t=A(e,i,s);else{let p={exception:2,first:1,ignore:0,last:-1};t=p[e.position]<p[i.position]}t&&a.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:i.name},node:i.node,fix:p=>{let g=Z(n,({position:y})=>y),S=y=>y in g?g[y]:[],T=[S("exception").sort((y,c)=>s["always-on-top"].indexOf(y.name)-s["always-on-top"].indexOf(c.name)),b(S("first"),s),b(S("ignore"),s),b(S("last"),s)].flat();return Y(p,n,T,r)}})})})}}})});class F{static get(){return this._instance?this._instance:(this._instance=ne.parse(re.readFileSync(se.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}V(F,"_instance");const W="sort-imports",me=N({name:W,meta:{type:"suggestion",docs:{description:"enforce sorted imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{type:"array",default:["~/**"]},"newlines-between":{enum:["ignore","always","never"],default:"always"},"read-tsconfig":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedImportsOrder:'Expected "{{right}}" to come before "{{left}}"',missedSpacingBetweenImports:'Missed spacing between "{{left}}" and "{{right}}" imports',extraSpacingBetweenImports:'Extra spacing between "{{left}}" and "{{right}}" imports'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>{var i;let o=w(a.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:l.alphabetical,"read-tsconfig":!1,order:f.asc,"ignore-case":!1,groups:[]}),s=[];if(o["read-tsconfig"]){let t=F.get();(i=t.compilerOptions)!=null&&i.paths&&Object.keys(t.compilerOptions.paths).forEach(p=>{s.push(p)})}let r=a.getSourceCode(),d=[],n=t=>{let p,g=E=>[".less",".scss",".sass",".pcss",".css",".sss"].some(_=>E.endsWith(_)),S=E=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(E),T=E=>E.indexOf("..")===0,y=E=>E.indexOf("./")===0,c=E=>{!p&&o.groups.flat().includes(E)&&(p=E)},m=E=>o["internal-pattern"].length&&o["internal-pattern"].some(_=>C.minimatch(E.source.value,_))||s.some(_=>C.minimatch(E.source.value,_));return t.importKind==="type"&&(t.type===u.AST_NODE_TYPES.ImportDeclaration&&(H(t.source.value)&&c("builtin-type"),m(t)&&c("internal-type"),S(t.source.value)&&c("index-type"),T(t.source.value)&&c("parent-type"),y(t.source.value)&&c("sibling-type")),c("type")),!p&&t.type===u.AST_NODE_TYPES.ImportDeclaration&&(H(t.source.value)&&c("builtin"),m(t)&&c("internal"),g(t.source.value)&&c("style"),t.specifiers.length===0&&c("side-effect"),S(t.source.value)&&c("index"),T(t.source.value)&&c("parent"),y(t.source.value)&&c("sibling"),c("external")),p??"unknown"},e=t=>{let p;t.type===u.AST_NODE_TYPES.ImportDeclaration?p=t.source.value:t.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&t.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?p=`${t.moduleReference.expression.value}`:p=r.text.slice(...t.moduleReference.range),d.push({size:P(t.range),group:n(t),name:p,node:t})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let t=y=>{for(let c=0,m=o.groups.length;c<m;c++){let E=o.groups[c];if(y.group===E||Array.isArray(E)&&E.includes(y.group))return c}return o.groups.length},p=(y,c)=>!!r.getTokensBetween(y.node,Q(c.node,r)||c.node,{includeComments:!0}).length,g=(y,c)=>r.lines.slice(y.node.loc.end.line,c.node.loc.start.line-1).filter(E=>!E.trim().length).length,S=(y,c)=>{let m=[],E=c.reduce((x,h)=>{let j=t(h);return j in x?x[j]=b([...x[j],h],o):x[j]=[h],x},{}),_=Object.keys(E).sort().reduce((x,h)=>[...x,...E[h]],[]);return _.forEach((x,h)=>{if(m.push(y.replaceTextRange(D(c.at(h).node,r),r.text.slice(...D(x.node,r)))),o["newlines-between"]!=="ignore"){let j=_.at(h+1);if(j){let k=g(c.at(h),c.at(h+1));(o["newlines-between"]==="always"&&t(x)===t(j)&&k!==0||o["newlines-between"]==="never"&&k>0)&&m.push(y.removeRange([D(c.at(h).node,r).at(1),D(c.at(h+1).node,r).at(0)-1])),o["newlines-between"]==="always"&&k>1&&m.push(y.replaceTextRange([D(c.at(h).node,r).at(1),D(c.at(h+1).node,r).at(0)-1],`
2
+ `)),o["newlines-between"]==="always"&&t(x)!==t(j)&&k===0&&m.push(y.insertTextAfterRange(D(c.at(h).node,r),`
3
+ `))}}}),m};d.reduce((y,c)=>{var E;let m=(E=y.at(-1))==null?void 0:E.at(-1);return m&&p(m,c)?y.push([c]):y.at(-1).push(c),y},[[]]).forEach(y=>{I(y,(c,m)=>{let E=t(c),_=t(m),x=g(c,m);!p(c,m)&&(E>_||E===_&&A(c,m,o))&&a.report({messageId:"unexpectedImportsOrder",data:{left:c.name,right:m.name},node:m.node,fix:h=>S(h,y)}),o["newlines-between"]==="never"&&x>0&&a.report({messageId:"extraSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:h=>S(h,y)}),o["newlines-between"]==="always"&&(E<_&&x===0?a.report({messageId:"missedSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:h=>S(h,y)}):(x>1||E===_&&x>0)&&a.report({messageId:"extraSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:h=>S(h,y)}))})})}}}}),X="sort-classes",ye=N({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted classes",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[f.asc,f.desc],default:f.asc},groups:{type:"array",default:["property","constructor","method","unknown"]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({ClassBody:o=>{if(o.body.length>1){let s=w(a.options.at(0),{type:l.alphabetical,order:f.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),r=a.getSourceCode(),d=o.body.map(e=>{var g;let i,t;e.type===u.AST_NODE_TYPES.StaticBlock?t="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?t=r.text.slice(e.range.at(0),((g=e.typeAnnotation)==null?void 0:g.range.at(0))??e.range.at(1)):e.key.type===u.AST_NODE_TYPES.Identifier?{name:t}=e.key:t=r.text.slice(...e.key.range);let p=S=>{!i&&s.groups.flat().includes(S)&&(i=S)};return e.type===u.AST_NODE_TYPES.MethodDefinition?(e.kind==="constructor"&&p("constructor"),e.static&&p("static-method"),e.accessibility==="private"&&p("private-method"),p("method")):e.type===u.AST_NODE_TYPES.PropertyDefinition&&(e.static&&p("static-property"),e.accessibility==="private"&&p("private-property"),p("property")),{size:P(e.range),group:i??"unknown",node:e,name:t}}),n=e=>{for(let i=0,t=s.groups.length;i<t;i++){let p=s.groups[i];if(e.group===p||Array.isArray(p)&&p.includes(e.group))return i}return s.groups.length};I(d,(e,i)=>{let t=n(e),p=n(i);(t>p||t===p&&A(e,i,s))&&a.report({messageId:"unexpectedClassesOrder",data:{left:O(e.name),right:O(i.name)},node:i.node,fix:g=>{let S=[],T=d.reduce((c,m)=>{let E=n(m);return E in c?c[E]=b([...c[E],m],s):c[E]=[m],c},{});return Object.keys(T).sort().reduce((c,m)=>[...c,...T[m]],[]).forEach((c,m)=>{S.push(g.replaceTextRange(D(d.at(m).node,r),r.text.slice(...D(c.node,r))))}),S}})})}}})}),G="sort-objects",Ee=N({name:G,meta:{type:"suggestion",docs:{description:"enforce sorted objects",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},order:{enum:[f.asc,f.desc],default:f.asc},"ignore-case":{type:"boolean",default:!1},"always-on-top":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>{let o=s=>{if(s.properties.length>1){let r=w(a.options.at(0),{type:l.alphabetical,"ignore-case":!1,order:f.asc,"always-on-top":[]}),d=a.getSourceCode();(e=>e.reduce((i,t)=>{if(t.type===u.AST_NODE_TYPES.SpreadElement||t.type===u.AST_NODE_TYPES.RestElement)return i.push([]),i;let p,g="ignore",S=[];if(t.key.type===u.AST_NODE_TYPES.Identifier?{name:p}=t.key:t.key.type===u.AST_NODE_TYPES.Literal?p=`${t.key.value}`:p=d.text.slice(...t.key.range),t.key.type===u.AST_NODE_TYPES.Identifier&&r["always-on-top"].includes(t.key.name)&&(g="exception"),t.value.type===u.AST_NODE_TYPES.AssignmentPattern){let y=(c,m)=>{c.right.type===u.AST_NODE_TYPES.Identifier&&S.push(c.right.name),!m&&c.left.type===u.AST_NODE_TYPES.Identifier&&S.push(c.left.name);let E=_=>{_.right.type===u.AST_NODE_TYPES.Identifier&&S.push(_.right.name),_.left.type===u.AST_NODE_TYPES.BinaryExpression&&y(_.left,!1)};c.right.type===u.AST_NODE_TYPES.BinaryExpression&&E(c.right)};y(t.value,!0)}let T={size:P(t.range),dependencies:S,node:t,position:g,name:p};return i.at(-1).push(T),i},[[]]))(s.properties).forEach(e=>{I(e,(i,t)=>{let p;if(i.position==="exception"&&t.position==="exception")p=r["always-on-top"].indexOf(i.name)>r["always-on-top"].indexOf(t.name);else if(i.position===t.position)p=A(i,t,r);else{let g={exception:1,ignore:0};p=g[i.position]<g[t.position]}if(p){let g=S=>{let T=Z(e,({position:m})=>m),y=m=>m in T?T[m]:[],c=[y("exception").sort((m,E)=>r["always-on-top"].indexOf(m.name)-r["always-on-top"].indexOf(E.name)),b(y("ignore"),r)].flat();return Y(S,e,c,d)};a.report({messageId:"unexpectedObjectsOrder",data:{left:O(i.name),right:O(t.name)},node:t.node,fix:g})}})})}};return{ObjectExpression:o,ObjectPattern:o}}}),K="sort-enums",Se=N({name:K,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[l.alphabetical,l.natural,l["line-length"]],default:l.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[f.asc,f.desc],default:f.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:l.alphabetical,order:f.asc}],create:a=>({TSEnumDeclaration:o=>{if(o.members.length>1&&o.members.some(({initializer:s})=>s)){let s=w(a.options.at(0),{type:l.alphabetical,order:f.asc,"ignore-case":!1}),r=a.getSourceCode(),d=o.members.map(n=>({name:n.id.type===u.AST_NODE_TYPES.Literal?`${n.id.value}`:`${r.text.slice(...n.id.range)}`,size:P(n.range),node:n}));I(d,(n,e)=>{A(n,e,s)&&a.report({messageId:"unexpectedEnumsOrder",data:{left:O(n.name),right:O(e.name)},node:e.node,fix:i=>Y(i,d,b(d,s),r)})})}}})}),he="eslint-plugin-perfectionist";let R=a=>{let o={[W]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"newlines-between":"always","internal-pattern":["~/**"],"read-tsconfig":!1}],[X]:["error",{groups:["static-property","private-property","property","constructor","static-method","private-method","method","unknown"]}],[J]:["error",{"always-on-top":[],shorthand:"ignore",multiline:"first",callback:"ignore"}],[L]:["error",{"spread-last":!0}],[G]:["error",{"always-on-top":[]}],[B]:["error"],[$]:["error"],[M]:["error"],[U]:["error"],[z]:["error"],[q]:["error"],[K]:["error"]};return{rules:Object.fromEntries(Object.entries(o).map(([s,[r,d={}]])=>[`perfectionist/${s}`,[r,Object.assign(d,a)]])),plugins:["perfectionist"]}};const Te={rules:{[L]:oe,[X]:ye,[K]:Se,[W]:me,[q]:ue,[J]:ge,[U]:de,[$]:le,[B]:pe,[M]:ce,[G]:Ee,[z]:fe},configs:{"recommended-alphabetical":R({type:l.alphabetical,order:f.asc,"ignore-case":!1}),"recommended-natural":R({type:l.natural,order:f.asc,"ignore-case":!1}),"recommended-line-length":R({type:l["line-length"],order:f.desc})},name:he};module.exports=Te;