eslint-plugin-perfectionist 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";const W=require("node:path"),_=require("@typescript-eslint/utils"),$=require("minimatch"),ue=require("natural-compare-lite"),de=require("node:module");let I=_.ESLintUtils.RuleCreator(t=>`https://eslint-plugin-perfectionist.azat.io/rules/${t}`),E=(t,n)=>{for(let s=0,l=t.length;s<l;s++){let r=t[s];if(n.group===r||Array.isArray(r)&&typeof n.group=="string"&&r.includes(n.group))return s}return t.length},O=t=>{let[n,s]=t;return s-n},j=t=>t>0;var p=(t=>(t.alphabetical="alphabetical",t["line-length"]="line-length",t.natural="natural",t))(p||{}),f=(t=>(t.desc="desc",t.asc="asc",t))(f||{});let M=t=>{let n,s=r=>{!n&&t.flat().includes(r)&&(n=r)};return{getGroup:()=>n??"unknown",setCustomGroups:(r,e)=>{if(r)for(let[a,i]of Object.entries(r))Array.isArray(i)&&i.some(o=>$.minimatch(e,o,{nocomment:!0}))&&s(a),typeof i=="string"&&$.minimatch(e,i,{nocomment:!0})&&s(a)},defineGroup:s}},A=(t,n,s)=>{var a,i;if((a=n.dependencies)!=null&&a.includes(t.name))return-1;if((i=t.dependencies)!=null&&i.includes(n.name))return 1;let l=s.order==="asc"?1:-1,r,e=o=>s["ignore-case"]?o.toLowerCase():o;return s.type===p.alphabetical?r=(o,u)=>e(o.name).localeCompare(e(u.name)):s.type===p.natural?r=(o,u)=>ue(e(o.name),e(u.name)):r=(o,u)=>{let y=o.size,m=u.size,c=s["max-line-length"];if(c){let d=(g,b)=>g>c&&b.hasMultipleImportDeclarations;d(y,o)&&(y=o.name.length+10),d(m,u)&&(m=u.name.length+10)}return y-m},l*r(t,n)},w=(t,n)=>[...t].sort((s,l)=>A(s,l,n)),ce=(t,n)=>{let s=n.getTokenAfter(t,{filter:({value:l,type:r})=>!(r==="Punctuator"&&[",",";"].includes(l)),includeComments:!0});return((s==null?void 0:s.type)==="Block"||(s==null?void 0:s.type)==="Line")&&t.loc.end.line===s.loc.end.line?s:null},pe=(t,n)=>Array.isArray(t)&&t.some(s=>$.minimatch(n.trim(),s,{nocomment:!0}))||typeof t=="string"&&$.minimatch(n.trim(),t,{nocomment:!0})||t===!0,V=(t,n)=>{let[s,l]=n.getTokensBefore(t,{filter:({value:r,type:e})=>!(e==="Punctuator"&&[",",";"].includes(r)),includeComments:!0,count:2});return((l==null?void 0:l.type)==="Block"||(l==null?void 0:l.type)==="Line")&&t.loc.start.line-l.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==l.loc.start.line?l:null},L=(t,n,s)=>{var i;let l=t.range.at(0),r=t.range.at(1),e=n.text.slice(l,r);if(_.ASTUtils.isParenthesized(t,n)){let o=n.getTokenBefore(t,_.ASTUtils.isOpeningParenToken),u=n.getTokenAfter(t,_.ASTUtils.isClosingParenToken);l=o.range.at(0),r=u.range.at(1)}let a=V(t,n);if(e.endsWith(";")||e.endsWith(",")){let o=n.getTokensAfter(t,{includeComments:!0,count:2});t.loc.start.line===((i=o.at(1))==null?void 0:i.loc.start.line)&&(r-=1)}return a&&!pe((s==null?void 0:s.partitionComment)??!1,a.value)&&(l=a.range.at(0)),[l,r]},T=(t,n,s,l,r)=>{var i,o;let e=[],a=((i=n.at(0))==null?void 0:i.node.loc.start.line)===((o=n.at(-1))==null?void 0:o.node.loc.end.line);for(let u=0,y=n.length;u<y;u++){let{node:m}=n.at(u);e.push(t.replaceTextRange(L(m,l,r),l.text.slice(...L(s.at(u).node,l,r))));let c=ce(s.at(u).node,l);if(c&&!a){let g=[l.getTokenBefore(c).range.at(1),c.range.at(1)];e.push(t.replaceTextRange(g,""));let b=l.getTokenAfter(m);e.push(t.insertTextAfter((b==null?void 0:b.loc.end.line)===m.loc.end.line?b:m,l.text.slice(...g)))}}return e},k=(t={},n)=>Object.assign(n,t),P=(t,n)=>{if(t.length>1)for(let s=1;s<t.length;s++){let l=t.at(s-1),r=t.at(s);l&&r&&n(l,r,s-1)}};const J="sort-svelte-attributes",fe=I({name:J,meta:{type:"suggestion",docs:{description:"enforce sorted Svelte attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedSvelteAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>W.extname(t.filename)!==".svelte"?{}:{SvelteStartTag:n=>{if(n.attributes.length>1){let s=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),l=n.attributes.reduce((r,e)=>{if(e.type==="SvelteSpreadAttribute")return r.push([]),r;let a,{getGroup:i,defineGroup:o,setCustomGroups:u}=M(s.groups);return e.key.type==="SvelteSpecialDirectiveKey"?a=t.sourceCode.text.slice(...e.key.range):typeof e.key.name=="string"?{name:a}=e.key:a=t.sourceCode.text.slice(...e.key.range),u(s["custom-groups"],a),e.type==="SvelteShorthandAttribute"&&(o("svelte-shorthand"),o("shorthand")),(!("value"in e)||Array.isArray(e.value)&&!e.value.at(0))&&o("shorthand"),e.loc.start.line!==e.loc.end.line&&o("multiline"),r.at(-1).push({size:O(e.range),node:e,group:i(),name:a}),r},[[]]);for(let r of l)P(r,(e,a)=>{let i=E(s.groups,e),o=E(s.groups,a);(i>o||i===o&&j(A(e,a,s)))&&t.report({messageId:"unexpectedSvelteAttributesOrder",data:{left:e.name,right:a.name},node:a.node,fix:u=>{let y={};for(let c of r){let d=E(s.groups,c);d in y?y[d]=w([...y[d],c],s):y[d]=[c]}let m=[];for(let c of Object.keys(y).sort((d,g)=>Number(d)-Number(g)))m.push(...w(y[c],s));return T(u,r,m,t.sourceCode)}})})}}}}),X="sort-astro-attributes",ge=I({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted Astro attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedAstroAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>W.extname(t.filename)!==".astro"?{}:{JSXElement:n=>{let{attributes:s}=n.openingElement;if(s.length>1){let l=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),r=s.reduce((e,a)=>{if(a.type==="JSXSpreadAttribute")return e.push([]),e;let i=typeof a.name.name=="string"?a.name.name:t.sourceCode.text.slice(...a.name.range),{getGroup:o,defineGroup:u,setCustomGroups:y}=M(l.groups);return y(l["custom-groups"],i),a.type==="AstroShorthandAttribute"&&(u("astro-shorthand"),u("shorthand")),a.value===null&&u("shorthand"),a.loc.start.line!==a.loc.end.line&&u("multiline"),e.at(-1).push({size:O(a.range),node:a,group:o(),name:i}),e},[[]]);for(let e of r)P(e,(a,i)=>{let o=E(l.groups,a),u=E(l.groups,i);(o>u||o===u&&j(A(a,i,l)))&&t.report({messageId:"unexpectedAstroAttributesOrder",data:{left:a.name,right:i.name},node:i.node,fix:y=>{let m={};for(let d of e){let g=E(l.groups,d);g in m?m[g]=w([...m[g],d],l):m[g]=[d]}let c=[];for(let d of Object.keys(m).sort((g,b)=>Number(g)-Number(b)))c.push(...w(m[d],l));return T(y,e,c,t.sourceCode)}})})}}}});let v=t=>t.replaceAll(/\s\s+/g," ").trim();const K="sort-array-includes",ye=I({name:K,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"spread-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({MemberExpression:n=>{if((n.object.type==="ArrayExpression"||n.object.type==="NewExpression")&&n.property.type==="Identifier"&&n.property.name==="includes"){let s=n.object.type==="ArrayExpression"?n.object.elements:n.object.arguments;if(s.length>1){let l=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1,"spread-last":!1}),r=s.reduce((e,a)=>(a!==null&&e.at(0).push({name:a.type==="Literal"?`${a.value}`:t.sourceCode.text.slice(...a.range),size:O(a.range),type:a.type,node:a}),e),[[],[]]).flat();P(r,(e,a)=>{let i;l["spread-last"]&&e.node.type==="Literal"&&a.node.type==="SpreadElement"?i=!1:l["spread-last"]&&e.node.type==="SpreadElement"&&a.node.type==="Literal"?i=!0:i=j(A(e,a,l)),i&&t.report({messageId:"unexpectedArrayIncludesOrder",data:{left:v(e.name),right:v(a.name)},node:a.node,fix:o=>{let u=w(r,l);if(l["spread-last"])for(let y=0,m=u.length;y<m;y++)u.at(y).node.type==="SpreadElement"&&u.push(u.splice(y,1).at(0));return T(o,r,u,t.sourceCode)}})})}}}})}),H="sort-vue-attributes",me=I({name:H,meta:{type:"suggestion",docs:{description:"enforce sorted Vue attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedVueAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>{if(W.extname(t.filename)!==".vue")return{};if(!("defineTemplateBodyVisitor"in t.sourceCode.parserServices))return{};let{defineTemplateBodyVisitor:n}=t.sourceCode.parserServices;return n({VStartTag:s=>{if(s.attributes.length>1){let l=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),r=s.attributes.reduce((e,a)=>{if(a.key.type==="VDirectiveKey"&&a.key.name.rawName==="bind")return e.push([]),e;let i,{getGroup:o,defineGroup:u,setCustomGroups:y}=M(l.groups);return typeof a.key.name=="string"&&a.key.type!=="VDirectiveKey"?i=a.key.rawName:i=t.sourceCode.text.slice(...a.key.range),y(l["custom-groups"],i),a.value===null&&u("shorthand"),a.loc.start.line!==a.loc.end.line&&u("multiline"),e.at(-1).push({size:O(a.range),node:a,group:o(),name:i}),e},[[]]);for(let e of r)P(e,(a,i)=>{let o=E(l.groups,a),u=E(l.groups,i);(o>u||o===u&&j(A(a,i,l)))&&t.report({messageId:"unexpectedVueAttributesOrder",data:{left:a.name,right:i.name},node:i.node,fix:y=>{let m={};for(let d of e){let g=E(l.groups,d);g in m?m[g]=w([...m[g],d],l):m[g]=[d]}let c=[];for(let d of Object.keys(m).sort((g,b)=>Number(g)-Number(b)))c.push(...w(m[d],l));return T(y,e,c,t.sourceCode)}})})}}})}}),Q="sort-named-exports",he=I({name:Q,meta:{type:"suggestion",docs:{description:"enforce sorted named exports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({ExportNamedDeclaration:n=>{if(n.specifiers.length>1){let s=k(t.options.at(0),{type:p.alphabetical,"ignore-case":!1,order:f.asc}),l=n.specifiers.map(r=>({size:O(r.range),name:r.local.name,node:r}));P(l,(r,e)=>{j(A(r,e,s))&&t.report({messageId:"unexpectedNamedExportsOrder",data:{left:r.name,right:e.name},node:e.node,fix:a=>T(a,l,w(l,s),t.sourceCode)})})}}})}),Y="sort-named-imports",be=I({name:Y,meta:{type:"suggestion",docs:{description:"enforce sorted named imports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-alias":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({ImportDeclaration:n=>{let s=n.specifiers.filter(({type:l})=>l==="ImportSpecifier");if(s.length>1){let l=k(t.options.at(0),{type:p.alphabetical,"ignore-alias":!0,"ignore-case":!1,order:f.asc}),r=s.map(e=>{let{name:a}=e.local;return l["ignore-alias"]&&e.type==="ImportSpecifier"&&({name:a}=e.imported),{size:O(e.range),node:e,name:a}});P(r,(e,a)=>{j(A(e,a,l))&&t.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:a.name},node:a.node,fix:i=>T(i,r,w(r,l),t.sourceCode)})})}}})});let z=(t,n,s)=>t.lines.slice(n.node.loc.end.line,s.node.loc.start.line-1).filter(r=>!r.trim().length).length;const Z="sort-object-types",xe=I({name:Z,meta:{type:"suggestion",docs:{description:"enforce sorted object types"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"partition-by-new-line":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({TSTypeLiteral:n=>{if(n.members.length>1){let s=k(t.options.at(0),{"partition-by-new-line":!1,type:p.alphabetical,"ignore-case":!1,order:f.asc,"custom-groups":{},groups:[]}),l=n.members.reduce((r,e)=>{var N,h,C,x;let a,i=t.sourceCode.text.slice(e.range.at(0),e.range.at(1)),o=(N=r.at(-1))==null?void 0:N.at(-1),{getGroup:u,defineGroup:y,setCustomGroups:m}=M(s.groups),c=S=>S.replace(/(,|;)$/,"");if(e.type==="TSPropertySignature")e.key.type==="Identifier"?{name:a}=e.key:e.key.type==="Literal"?a=`${e.key.value}`:a=t.sourceCode.text.slice(e.range.at(0),(h=e.typeAnnotation)==null?void 0:h.range.at(0));else if(e.type==="TSIndexSignature"){let S=((C=e.typeAnnotation)==null?void 0:C.range.at(0))??e.range.at(1);a=c(t.sourceCode.text.slice(e.range.at(0),S))}else a=c(t.sourceCode.text.slice(e.range.at(0),e.range.at(1)));m(s["custom-groups"],a),e.loc.start.line!==e.loc.end.line&&y("multiline");let g=i.endsWith(";")||i.endsWith(",")?1:0,b={size:O(e.range)-g,node:e,name:a};return s["partition-by-new-line"]&&o&&z(t.sourceCode,o,b)&&r.push([]),(x=r.at(-1))==null||x.push({...b,group:u()}),r},[[]]);for(let r of l)P(r,(e,a)=>{let i=E(s.groups,e),o=E(s.groups,a);(i>o||i===o&&j(A(e,a,s)))&&t.report({messageId:"unexpectedObjectTypesOrder",data:{left:v(e.name),right:v(a.name)},node:a.node,fix:u=>{let y={};for(let c of r){let d=E(s.groups,c);d in y?y[d]=w([...y[d],c],s):y[d]=[c]}let m=[];for(let c of Object.keys(y).sort((d,g)=>Number(d)-Number(g)))m.push(...w(y[c],s));return T(u,r,m,t.sourceCode)}})})}}})}),F="sort-union-types",Ee=I({name:F,meta:{type:"suggestion",docs:{description:"enforce sorted union types"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"nullable-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({TSUnionType:n=>{let s=k(t.options.at(0),{type:p.alphabetical,"nullable-last":!1,"ignore-case":!1,order:f.asc}),l=n.types.map(r=>({group:r.type==="TSNullKeyword"||r.type==="TSUndefinedKeyword"?"nullable":"unknown",name:t.sourceCode.text.slice(...r.range),size:O(r.range),node:r}));P(l,(r,e)=>{let a=j(A(r,e,s));s["nullable-last"]&&(r.group==="nullable"&&e.group==="unknown"?a=!0:r.group==="unknown"&&e.group==="nullable"&&(a=!1)),a&&t.report({messageId:"unexpectedUnionTypesOrder",data:{left:v(r.name),right:v(e.name)},node:e.node,fix:i=>{let o=[];if(s["nullable-last"]){let u=[],y=l.filter(m=>m.group==="nullable"?(u.push(m),!1):!0);o=[...w(y,s),...w(u,s)]}else o=w(l,s);return T(i,l,o,t.sourceCode)}})})}})}),ee="sort-interfaces",Ce=I({name:ee,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{items:{type:"string"},type:"array"},groups:{type:"array",default:[]},"partition-by-new-line":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({TSInterfaceDeclaration:n=>{if(n.body.body.length>1){let s=k(t.options.at(0),{"partition-by-new-line":!1,type:p.alphabetical,"ignore-case":!1,order:f.asc,"ignore-pattern":[],"custom-groups":{},groups:[]});if(!s["ignore-pattern"].some(l=>$.minimatch(n.id.name,l,{nocomment:!0}))){let l=n.body.body.reduce((r,e)=>{var c,d,g,b;if(e.type==="TSCallSignatureDeclaration")return r.push([]),r;let a=(c=r.at(-1))==null?void 0:c.at(-1),i,{getGroup:o,defineGroup:u,setCustomGroups:y}=M(s.groups);if(e.type==="TSPropertySignature")if(e.key.type==="Identifier")({name:i}=e.key);else if(e.key.type==="Literal")i=`${e.key.value}`;else{let N=((d=e.typeAnnotation)==null?void 0:d.range.at(0))??e.range.at(1)-(e.optional?1:0);i=t.sourceCode.text.slice(e.range.at(0),N)}else if(e.type==="TSIndexSignature"){let N=((g=e.typeAnnotation)==null?void 0:g.range.at(0))??e.range.at(1);i=t.sourceCode.text.slice(e.range.at(0),N)}else{let N=((b=e.returnType)==null?void 0:b.range.at(0))??e.range.at(1);i=t.sourceCode.text.slice(e.range.at(0),N)}let m={size:O(e.range),node:e,name:i};return s["partition-by-new-line"]&&a&&z(t.sourceCode,a,m)&&r.push([]),y(s["custom-groups"],i),e.loc.start.line!==e.loc.end.line&&u("multiline"),r.at(-1).push({...m,group:o()}),r},[[]]);for(let r of l)P(r,(e,a)=>{let i=E(s.groups,e),o=E(s.groups,a);(i>o||i===o&&j(A(e,a,s)))&&t.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:v(e.name),right:v(a.name)},node:a.node,fix:u=>{let y={};for(let c of r){let d=E(s.groups,c);d in y?y[d]=w([...y[d],c],s):y[d]=[c]}let m=[];for(let c of Object.keys(y).sort((d,g)=>Number(d)-Number(g)))m.push(...w(y[c],s));return T(u,r,m,t.sourceCode)}})})}}}})}),te="sort-jsx-props",Ne=I({name:te,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},groups:{type:"array"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>[".svelte",".astro",".vue"].includes(W.extname(t.filename))?{}:{JSXElement:n=>{if(n.openingElement.attributes.length>1){let s=k(t.options.at(0),{type:p.alphabetical,"ignore-case":!1,order:f.asc,"custom-groups":{},groups:[]}),l=n.openingElement.attributes.reduce((r,e)=>{if(e.type==="JSXSpreadAttribute")return r.push([]),r;let a=e.name.type==="JSXNamespacedName"?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,{getGroup:i,defineGroup:o,setCustomGroups:u}=M(s.groups);u(s["custom-groups"],a),e.value===null&&o("shorthand"),e.loc.start.line!==e.loc.end.line&&o("multiline");let y={size:O(e.range),group:i(),node:e,name:a};return r.at(-1).push(y),r},[[]]);for(let r of l)P(r,(e,a)=>{let i=E(s.groups,e),o=E(s.groups,a);(i>o||i===o&&j(A(e,a,s)))&&t.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:a.name},node:a.node,fix:u=>{let y={};for(let c of r){let d=E(s.groups,c);d in y?y[d]=w([...y[d],c],s):y[d]=[c]}let m=[];for(let c of Object.keys(y).sort((d,g)=>Number(d)-Number(g)))m.push(...w(y[c],s));return T(u,r,m,t.sourceCode)}})})}}}}),re="sort-exports",we=I({name:re,meta:{type:"suggestion",docs:{description:"enforce sorted exports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>{let n=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1}),s=[[]],l=r=>{r.type==="ExportAllDeclaration"&&r.exported===null?s.push([]):s.at(-1).push({size:O(r.range),name:r.source.value,node:r})};return{ExportAllDeclaration:l,ExportNamedDeclaration:r=>{r.source!==null&&l(r)},"Program:exit":()=>{for(let r of s)P(r,(e,a)=>{j(A(e,a,n))&&t.report({messageId:"unexpectedExportsOrder",data:{left:e.name,right:a.name},node:a.node,fix:i=>T(i,r,w(r,n),t.sourceCode)})})}}}}),se="sort-imports",Se=I({name:se,meta:{type:"suggestion",docs:{description:"enforce sorted imports"},fixable:"code",schema:[{id:"sort-imports",type:"object",properties:{"custom-groups":{type:"object",properties:{type:{type:"object"},value:{type:"object"}},additionalProperties:!1},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{items:{type:"string"},type:"array"},"newlines-between":{enum:["ignore","always","never"],default:"always",type:"string"},"max-line-length":{type:"integer",minimum:0,exclusiveMinimum:!0}},allOf:[{$ref:"#/definitions/max-line-length-requires-line-length-type"}],additionalProperties:!1,dependencies:{"max-line-length":["type"]},definitions:{"is-line-length":{properties:{type:{enum:[p["line-length"]],type:"string"}},required:["type"],type:"object"},"max-line-length-requires-line-length-type":{anyOf:[{not:{required:["max-line-length"],type:"object"},type:"object"},{$ref:"#/definitions/is-line-length"}]}}}],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:p.alphabetical,order:f.asc}],create:t=>{let n=k(t.options.at(0),{"newlines-between":"always","custom-groups":{type:{},value:{}},"internal-pattern":["~/**"],type:p.alphabetical,order:f.asc,"ignore-case":!1,groups:[]}),s=!1;for(let o of n.groups)if(Array.isArray(o))for(let u of o)u==="unknown"&&(s=!0);else o==="unknown"&&(s=!0);s||(n.groups=[...n.groups,"unknown"]);let l=[],r=o=>o.type==="ImportDeclaration"&&o.specifiers.length===0,e=o=>{let u=x=>[".less",".scss",".sass",".styl",".pcss",".css",".sss"].some(S=>x.endsWith(S)),y=x=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(x),m=x=>x.indexOf("..")===0,c=x=>x.indexOf("./")===0,{getGroup:d,defineGroup:g,setCustomGroups:b}=M(n.groups),N=x=>n["internal-pattern"].length&&n["internal-pattern"].some(S=>$.minimatch(x.source.value,S,{nocomment:!0})),h=x=>{let S=["bun","bun:ffi","bun:jsc","bun:sqlite","bun:test","bun:wrap","detect-libc","undici","ws"];return de.builtinModules.includes(x.startsWith("node:")?x.split("node:")[1]:x)||S.includes(x)},C=x=>!(x.startsWith(".")||x.startsWith("/"));return o.importKind==="type"&&(o.type==="ImportDeclaration"&&(b(n["custom-groups"].type,o.source.value),y(o.source.value)&&g("index-type"),c(o.source.value)&&g("sibling-type"),m(o.source.value)&&g("parent-type"),N(o)&&g("internal-type"),h(o.source.value)&&g("builtin-type"),C(o.source.value)&&g("external-type")),g("type")),o.type==="ImportDeclaration"&&(b(n["custom-groups"].value,o.source.value),r(o)&&u(o.source.value)&&g("side-effect-style"),r(o)&&g("side-effect"),u(o.source.value)&&g("style"),y(o.source.value)&&g("index"),c(o.source.value)&&g("sibling"),m(o.source.value)&&g("parent"),N(o)&&g("internal"),h(o.source.value)&&g("builtin"),C(o.source.value)&&g("external")),d()},a=o=>o.specifiers.length>1,i=o=>{let u;o.type==="ImportDeclaration"?u=o.source.value:o.moduleReference.type==="TSExternalModuleReference"&&o.moduleReference.expression.type==="Literal"?u=`${o.moduleReference.expression.value}`:u=t.sourceCode.text.slice(...o.moduleReference.range),l.push({size:O(o.range),group:e(o),name:u,node:o,...n.type===p["line-length"]&&n["max-line-length"]&&{hasMultipleImportDeclarations:a(o)}})};return{TSImportEqualsDeclaration:i,ImportDeclaration:i,"Program:exit":()=>{var m;let o=(c,d)=>!!t.sourceCode.getTokensBetween(c.node,V(d.node,t.sourceCode)||d.node,{includeComments:!0}).length,u=(c,d)=>{let g=[],b={};for(let h of d){let C=E(n.groups,h);C in b?b[C]=w([...b[C],h],n):b[C]=[h]}let N=Object.keys(b).sort((h,C)=>Number(h)-Number(C)).reduce((h,C)=>[...h,...b[C]],[]);for(let h=0,C=N.length;h<C;h++){let x=N.at(h);if(g.push(c.replaceTextRange(L(d.at(h).node,t.sourceCode),t.sourceCode.text.slice(...L(x.node,t.sourceCode)))),n["newlines-between"]!=="ignore"){let S=N.at(h+1);if(S){let G=z(t.sourceCode,d.at(h),d.at(h+1));(n["newlines-between"]==="always"&&E(n.groups,x)===E(n.groups,S)&&G!==0||n["newlines-between"]==="never"&&G>0)&&g.push(c.removeRange([L(d.at(h).node,t.sourceCode).at(1),L(d.at(h+1).node,t.sourceCode).at(0)-1])),n["newlines-between"]==="always"&&E(n.groups,x)!==E(n.groups,S)&&G>1&&g.push(c.replaceTextRange([L(d.at(h).node,t.sourceCode).at(1),L(d.at(h+1).node,t.sourceCode).at(0)-1],`
2
- `)),n["newlines-between"]==="always"&&E(n.groups,x)!==E(n.groups,S)&&G===0&&g.push(c.insertTextAfterRange(L(d.at(h).node,t.sourceCode),`
3
- `))}}}return g},y=[[]];for(let c of l){let d=(m=y.at(-1))==null?void 0:m.at(-1);d&&o(d,c)?y.push([c]):y.at(-1).push(c)}for(let c of y)P(c,(d,g)=>{let b=E(n.groups,d),N=E(n.groups,g),h=z(t.sourceCode,d,g);!(r(d.node)&&r(g.node))&&!o(d,g)&&(b>N||b===N&&j(A(d,g,n)))&&t.report({messageId:"unexpectedImportsOrder",data:{left:d.name,right:g.name},node:g.node,fix:C=>u(C,c)}),n["newlines-between"]==="never"&&h>0&&t.report({messageId:"extraSpacingBetweenImports",data:{left:d.name,right:g.name},node:g.node,fix:C=>u(C,c)}),n["newlines-between"]==="always"&&(b<N&&h===0?t.report({messageId:"missedSpacingBetweenImports",data:{left:d.name,right:g.name},node:g.node,fix:C=>u(C,c)}):(h>1||b===N&&h>0)&&t.report({messageId:"extraSpacingBetweenImports",data:{left:d.name,right:g.name},node:g.node,fix:C=>u(C,c)}))})}}}}),ae="sort-objects",Ae=I({name:ae,meta:{type:"suggestion",docs:{description:"enforce sorted objects"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},"partition-by-comment":{type:["boolean","string","array"],default:!1},"partition-by-new-line":{type:"boolean",default:!1},"styled-components":{type:"boolean",default:!0},type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{items:{type:"string"},type:"array"},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>{let n=s=>{let l=k(t.options.at(0),{"partition-by-new-line":!1,"partition-by-comment":!1,type:p.alphabetical,"styled-components":!0,"ignore-case":!1,"ignore-pattern":[],order:f.asc,"custom-groups":{},groups:[]}),r=s.parent.type==="VariableDeclarator"&&s.parent.id.type==="Identifier"?s.parent.id.name:null;if(!(l["ignore-pattern"].length&&typeof r=="string"?l["ignore-pattern"].some(a=>$.minimatch(r,a,{nocomment:!0})):!1)&&s.properties.length>1){let a=u=>u.type==="Identifier"&&u.name==="styled",i=u=>u!==void 0&&u.type==="CallExpression"&&(u.callee.type==="MemberExpression"&&a(u.callee.object)||u.callee.type==="CallExpression"&&a(u.callee.callee));if(!l["styled-components"]&&(i(s.parent)||s.parent.type==="ArrowFunctionExpression"&&i(s.parent.parent)))return;let o=u=>u.reduce((y,m)=>{var G;if(m.type==="SpreadElement"||m.type==="RestElement")return y.push([]),y;let c=V(m,t.sourceCode),d=(G=y.at(-1))==null?void 0:G.at(-1);l["partition-by-comment"]&&c&&pe(l["partition-by-comment"],c.value)&&y.push([]);let g,b="ignore",N=[],{getGroup:h,setCustomGroups:C}=M(l.groups);m.key.type==="Identifier"?{name:g}=m.key:m.key.type==="Literal"?g=`${m.key.value}`:g=t.sourceCode.text.slice(...m.key.range);let x={size:O(m.range),node:m,name:g};l["partition-by-new-line"]&&d&&z(t.sourceCode,d,x)&&y.push([]),m.value.type==="AssignmentPattern"&&(B=>{B.right.type==="Identifier"&&N.push(B.right.name);let ie=R=>{let D=[];switch(R.type){case"ArrowFunctionExpression":D.push(R.body);break;case"ConditionalExpression":D.push(R.consequent,R.alternate);break;case"LogicalExpression":case"BinaryExpression":D.push(R.left,R.right);break;case"CallExpression":D.push(...R.arguments);break}D.forEach(U=>{U.type==="Identifier"&&N.push(U.name),(U.type==="BinaryExpression"||U.type==="ConditionalExpression")&&ie(U)})};switch(B.right.type){case"ArrowFunctionExpression":case"ConditionalExpression":case"LogicalExpression":case"BinaryExpression":case"CallExpression":ie(B.right);break}})(m.value),C(l["custom-groups"],g);let S={...x,group:h(),dependencies:N,position:b};return y.at(-1).push(S),y},[[]]);for(let u of o(s.properties))P(u,(y,m)=>{let c=E(l.groups,y),d=E(l.groups,m);if(c>d||c===d&&j(A(y,m,l))){let g=b=>{let N={};for(let C of u){let x=E(l.groups,C);x in N?N[x]=w([...N[x],C],l):N[x]=[C]}let h=[];for(let C of Object.keys(N).sort((x,S)=>Number(x)-Number(S)))h.push(...w(N[C],l));return T(b,u,h,t.sourceCode,{partitionComment:l["partition-by-comment"]})};t.report({messageId:"unexpectedObjectsOrder",data:{left:v(y.name),right:v(m.name)},node:m.node,fix:g})}})}};return{ObjectExpression:n,ObjectPattern:n}}}),oe="sort-classes",ve=I({name:oe,meta:{type:"suggestion",docs:{description:"enforce sorted classes"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},"ignore-case":{type:"boolean",default:!1},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},groups:{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({ClassBody:n=>{if(n.body.length>1){let s=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),l=n.body.map(r=>{var y;let e,{getGroup:a,defineGroup:i}=M(s.groups);r.type==="StaticBlock"?e="static":r.type==="TSIndexSignature"?e=t.sourceCode.text.slice(r.range.at(0),((y=r.typeAnnotation)==null?void 0:y.range.at(0))??r.range.at(1)):r.key.type==="Identifier"?{name:e}=r.key:e=t.sourceCode.text.slice(...r.key.range);let o=e.startsWith("_")||e.startsWith("#"),u="decorators"in r&&r.decorators.length>0;if(r.type==="MethodDefinition"){r.kind==="constructor"&&i("constructor");let m=r.accessibility==="private"||o,c=r.static;u&&(r.kind==="get"&&i("decorated-get-method"),r.kind==="set"&&i("decorated-set-method"),i("decorated-method")),m&&c&&i("static-private-method"),m&&i("private-method"),c&&i("static-method"),r.kind==="get"&&i("get-method"),r.kind==="set"&&i("set-method"),i("method")}else r.type==="TSIndexSignature"?i("index-signature"):r.type==="AccessorProperty"?u&&((r.accessibility==="private"||o)&&i("private-decorated-accessor-property"),i("decorated-accessor-property")):r.type==="PropertyDefinition"&&(u&&((r.accessibility==="private"||o)&&i("private-decorated-property"),i("decorated-property")),(r.accessibility==="private"||o)&&i("private-property"),r.static&&i("static-property"),i("property"));return{size:O(r.range),group:a(),node:r,name:e}});P(l,(r,e)=>{let a=E(s.groups,r),i=E(s.groups,e);r.name!==e.name&&(a>i||a===i&&j(A(r,e,s)))&&t.report({messageId:"unexpectedClassesOrder",data:{left:v(r.name),right:v(e.name)},node:e.node,fix:o=>{let u=[],y=l.reduce((c,d)=>{let g=E(s.groups,d);return g in c?c[g]=w([...c[g],d],s):c[g]=[d],c},{}),m=Object.keys(y).sort((c,d)=>Number(c)-Number(d)).reduce((c,d)=>[...c,...y[d]],[]);for(let c=0,d=m.length;c<d;c++)u.push(o.replaceTextRange(L(l.at(c).node,t.sourceCode),t.sourceCode.text.slice(...L(m.at(c).node,t.sourceCode))));return u}})})}}})}),ne="sort-enums",Ie=I({name:ne,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},"ignore-case":{type:"boolean",default:!1},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({TSEnumDeclaration:n=>{if(n.members.length>1&&n.members.every(({initializer:s})=>s)){let s=k(t.options.at(0),{type:p.alphabetical,order:f.asc,"ignore-case":!1}),l=n.members.map(r=>({name:r.id.type==="Literal"?`${r.id.value}`:`${t.sourceCode.text.slice(...r.id.range)}`,size:O(r.range),node:r}));P(l,(r,e)=>{j(A(r,e,s))&&t.report({messageId:"unexpectedEnumsOrder",data:{left:v(r.name),right:v(e.name)},node:e.node,fix:a=>T(a,l,w(l,s),t.sourceCode)})})}}})}),le="sort-maps",Oe=I({name:le,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[p.alphabetical,p.natural,p["line-length"]],default:p.alphabetical,type:"string"},order:{enum:[f.asc,f.desc],default:f.asc,type:"string"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:p.alphabetical,order:f.asc}],create:t=>({NewExpression:n=>{if(n.callee.type==="Identifier"&&n.callee.name==="Map"&&n.arguments.length&&n.arguments[0].type==="ArrayExpression"){let[{elements:s}]=n.arguments;if(s.length>1){let l=k(t.options.at(0),{type:p.alphabetical,"ignore-case":!1,order:f.asc}),r=s.reduce((e,a)=>(a===null||a.type==="SpreadElement"?e.push([]):e.at(-1).push(a),e),[[]]);for(let e of r){let a=e.map(i=>{let o;if(i.type==="ArrayExpression"){let[u]=i.elements;u?u.type==="Literal"?o=u.raw:o=t.sourceCode.text.slice(...u.range):o=`${u}`}else o=t.sourceCode.text.slice(...i.range);return{size:O(i.range),node:i,name:o}});P(a,(i,o)=>{j(A(i,o,l))&&t.report({messageId:"unexpectedMapElementsOrder",data:{left:v(i.name),right:v(o.name)},node:o.node,fix:u=>T(u,a,w(a,l),t.sourceCode)})})}}}}})}),je="eslint-plugin-perfectionist";let q=t=>{let n={[se]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"custom-groups":{value:{},type:{}},"newlines-between":"always","internal-pattern":["~/**"]}],[oe]:["error",{groups:["index-signature","static-property","private-property","property","constructor","static-method","private-method","method",["get-method","set-method"],"unknown"]}],[ae]:["error",{"partition-by-comment":!1}],[K]:["error",{"spread-last":!0}],[J]:["error"],[X]:["error"],[H]:["error"],[Q]:["error"],[Y]:["error"],[Z]:["error"],[F]:["error"],[ee]:["error"],[te]:["error"],[re]:["error"],[ne]:["error"],[le]:["error"]};return{rules:Object.fromEntries(Object.entries(n).map(([s,[l,r={}]])=>[`perfectionist/${s}`,[l,Object.assign(r,t)]])),plugins:["perfectionist"]}};const ke={rules:{[K]:ye,[X]:ge,[oe]:ve,[ne]:Ie,[re]:we,[se]:Se,[ee]:Ce,[te]:Ne,[le]:Oe,[Q]:he,[Y]:be,[Z]:xe,[ae]:Ae,[J]:fe,[F]:Ee,[H]:me},configs:{"recommended-alphabetical":q({type:p.alphabetical,order:f.asc,"ignore-case":!1}),"recommended-natural":q({type:p.natural,order:f.asc,"ignore-case":!1}),"recommended-line-length":q({type:p["line-length"],order:f.desc})},name:je};module.exports=ke;
1
+ "use strict";const q=require("node:path"),W=require("@typescript-eslint/utils"),D=require("minimatch"),de=require("natural-compare-lite"),ce=require("node:module");let k=W.ESLintUtils.RuleCreator(e=>`https://eslint-plugin-perfectionist.azat.io/rules/${e}`),h=(e,i)=>{for(let s=0,l=e.length;s<l;s++){let r=e[s];if(i.group===r||Array.isArray(r)&&typeof i.group=="string"&&r.includes(i.group))return s}return e.length},I=e=>{let[i,s]=e;return s-i},O=e=>e>0;var u=(e=>(e.alphabetical="alphabetical",e["line-length"]="line-length",e.natural="natural",e))(u||{}),g=(e=>(e.desc="desc",e.asc="asc",e))(g||{}),T=(e=>(e["values-first"]="values-first",e["types-first"]="types-first",e.mixed="mixed",e))(T||{});let G=e=>{let i,s=r=>{!i&&e.flat().includes(r)&&(i=r)};return{getGroup:()=>i??"unknown",setCustomGroups:(r,t)=>{if(r)for(let[a,n]of Object.entries(r))Array.isArray(n)&&n.some(o=>D.minimatch(t,o,{nocomment:!0}))&&s(a),typeof n=="string"&&D.minimatch(t,n,{nocomment:!0})&&s(a)},defineGroup:s}},S=(e,i,s)=>{var a,n;if((a=i.dependencies)!=null&&a.includes(e.name))return-1;if((n=e.dependencies)!=null&&n.includes(i.name))return 1;let l=s.order==="asc"?1:-1,r,t=o=>s["ignore-case"]?o.toLowerCase():o;return s.type===u.alphabetical?r=(o,p)=>t(o.name).localeCompare(t(p.name)):s.type===u.natural?r=(o,p)=>de(t(o.name),t(p.name)):r=(o,p)=>{let f=o.size,y=p.size,d=s["max-line-length"];if(d){let c=(m,x)=>m>d&&x.hasMultipleImportDeclarations;c(f,o)&&(f=o.name.length+10),c(y,p)&&(y=p.name.length+10)}return f-y},l*r(e,i)},v=(e,i)=>[...e].sort((s,l)=>S(s,l,i)),fe=(e,i)=>{let s=i.getTokenAfter(e,{filter:({value:l,type:r})=>!(r==="Punctuator"&&[",",";"].includes(l)),includeComments:!0});return((s==null?void 0:s.type)==="Block"||(s==null?void 0:s.type)==="Line")&&e.loc.end.line===s.loc.end.line?s:null},J=(e,i)=>Array.isArray(e)&&e.some(s=>D.minimatch(i.trim(),s,{nocomment:!0}))||typeof e=="string"&&D.minimatch(i.trim(),e,{nocomment:!0})||e===!0,V=(e,i)=>{let[s,l]=i.getTokensBefore(e,{filter:({value:r,type:t})=>!(t==="Punctuator"&&[",",";"].includes(r)),includeComments:!0,count:2});return((l==null?void 0:l.type)==="Block"||(l==null?void 0:l.type)==="Line")&&e.loc.start.line-l.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==l.loc.start.line?l:null},M=(e,i,s)=>{var n;let l=e.range.at(0),r=e.range.at(1),t=i.text.slice(l,r);if(W.ASTUtils.isParenthesized(e,i)){let o=i.getTokenBefore(e,W.ASTUtils.isOpeningParenToken),p=i.getTokenAfter(e,W.ASTUtils.isClosingParenToken);l=o.range.at(0),r=p.range.at(1)}let a=V(e,i);if(t.endsWith(";")||t.endsWith(",")){let o=i.getTokensAfter(e,{includeComments:!0,count:2});e.loc.start.line===((n=o.at(1))==null?void 0:n.loc.start.line)&&(r-=1)}return a&&!J((s==null?void 0:s.partitionComment)??!1,a.value)&&(l=a.range.at(0)),[l,r]},L=(e,i,s,l,r)=>{var n,o;let t=[],a=((n=i.at(0))==null?void 0:n.node.loc.start.line)===((o=i.at(-1))==null?void 0:o.node.loc.end.line);for(let p=0,f=i.length;p<f;p++){let{node:y}=i.at(p);t.push(e.replaceTextRange(M(y,l,r),l.text.slice(...M(s.at(p).node,l,r))));let d=fe(s.at(p).node,l);if(d&&!a){let m=[l.getTokenBefore(d).range.at(1),d.range.at(1)];t.push(e.replaceTextRange(m,""));let x=l.getTokenAfter(y);t.push(e.insertTextAfter((x==null?void 0:x.loc.end.line)===y.loc.end.line?x:y,l.text.slice(...m)))}}return t},j=(e={},i)=>Object.assign(i,e),P=(e,i)=>{if(e.length>1)for(let s=1;s<e.length;s++){let l=e.at(s-1),r=e.at(s);l&&r&&i(l,r,s-1)}};const X="sort-svelte-attributes",ge=k({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted Svelte attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedSvelteAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>q.extname(e.filename)!==".svelte"?{}:{SvelteStartTag:i=>{if(i.attributes.length>1){let s=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),l=i.attributes.reduce((r,t)=>{if(t.type==="SvelteSpreadAttribute")return r.push([]),r;let a,{getGroup:n,defineGroup:o,setCustomGroups:p}=G(s.groups);return t.key.type==="SvelteSpecialDirectiveKey"?a=e.sourceCode.text.slice(...t.key.range):typeof t.key.name=="string"?{name:a}=t.key:a=e.sourceCode.text.slice(...t.key.range),p(s["custom-groups"],a),t.type==="SvelteShorthandAttribute"&&(o("svelte-shorthand"),o("shorthand")),(!("value"in t)||Array.isArray(t.value)&&!t.value.at(0))&&o("shorthand"),t.loc.start.line!==t.loc.end.line&&o("multiline"),r.at(-1).push({size:I(t.range),node:t,group:n(),name:a}),r},[[]]);for(let r of l)P(r,(t,a)=>{let n=h(s.groups,t),o=h(s.groups,a);(n>o||n===o&&O(S(t,a,s)))&&e.report({messageId:"unexpectedSvelteAttributesOrder",data:{left:t.name,right:a.name},node:a.node,fix:p=>{let f={};for(let d of r){let c=h(s.groups,d);c in f?f[c]=v([...f[c],d],s):f[c]=[d]}let y=[];for(let d of Object.keys(f).sort((c,m)=>Number(c)-Number(m)))y.push(...v(f[d],s));return L(p,r,y,e.sourceCode)}})})}}}}),H="sort-astro-attributes",ye=k({name:H,meta:{type:"suggestion",docs:{description:"enforce sorted Astro attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedAstroAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>q.extname(e.filename)!==".astro"?{}:{JSXElement:i=>{let{attributes:s}=i.openingElement;if(s.length>1){let l=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),r=s.reduce((t,a)=>{if(a.type==="JSXSpreadAttribute")return t.push([]),t;let n=typeof a.name.name=="string"?a.name.name:e.sourceCode.text.slice(...a.name.range),{getGroup:o,defineGroup:p,setCustomGroups:f}=G(l.groups);return f(l["custom-groups"],n),a.type==="AstroShorthandAttribute"&&(p("astro-shorthand"),p("shorthand")),a.value===null&&p("shorthand"),a.loc.start.line!==a.loc.end.line&&p("multiline"),t.at(-1).push({size:I(a.range),node:a,group:o(),name:n}),t},[[]]);for(let t of r)P(t,(a,n)=>{let o=h(l.groups,a),p=h(l.groups,n);(o>p||o===p&&O(S(a,n,l)))&&e.report({messageId:"unexpectedAstroAttributesOrder",data:{left:a.name,right:n.name},node:n.node,fix:f=>{let y={};for(let c of t){let m=h(l.groups,c);m in y?y[m]=v([...y[m],c],l):y[m]=[c]}let d=[];for(let c of Object.keys(y).sort((m,x)=>Number(m)-Number(x)))d.push(...v(y[c],l));return L(f,t,d,e.sourceCode)}})})}}}});let A=e=>e.replaceAll(/\s\s+/g," ").trim();const Q="sort-array-includes",me=k({name:Q,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"spread-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({MemberExpression:i=>{if((i.object.type==="ArrayExpression"||i.object.type==="NewExpression")&&i.property.type==="Identifier"&&i.property.name==="includes"){let s=i.object.type==="ArrayExpression"?i.object.elements:i.object.arguments;if(s.length>1){let l=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,"spread-last":!1}),r=s.reduce((t,a)=>(a!==null&&t.at(0).push({name:a.type==="Literal"?`${a.value}`:e.sourceCode.text.slice(...a.range),size:I(a.range),type:a.type,node:a}),t),[[],[]]).flat();P(r,(t,a)=>{let n;l["spread-last"]&&t.node.type==="Literal"&&a.node.type==="SpreadElement"?n=!1:l["spread-last"]&&t.node.type==="SpreadElement"&&a.node.type==="Literal"?n=!0:n=O(S(t,a,l)),n&&e.report({messageId:"unexpectedArrayIncludesOrder",data:{left:A(t.name),right:A(a.name)},node:a.node,fix:o=>{let p=v(r,l);if(l["spread-last"])for(let f=0,y=p.length;f<y;f++)p.at(f).node.type==="SpreadElement"&&p.push(p.splice(f,1).at(0));return L(o,r,p,e.sourceCode)}})})}}}})}),Y="sort-vue-attributes",he=k({name:Y,meta:{type:"suggestion",docs:{description:"enforce sorted Vue attributes"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedVueAttributesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>{if(q.extname(e.filename)!==".vue")return{};if(!("defineTemplateBodyVisitor"in e.sourceCode.parserServices))return{};let{defineTemplateBodyVisitor:i}=e.sourceCode.parserServices;return i({VStartTag:s=>{if(s.attributes.length>1){let l=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,"custom-groups":{},groups:[]}),r=s.attributes.reduce((t,a)=>{if(a.key.type==="VDirectiveKey"&&a.key.name.rawName==="bind")return t.push([]),t;let n,{getGroup:o,defineGroup:p,setCustomGroups:f}=G(l.groups);return typeof a.key.name=="string"&&a.key.type!=="VDirectiveKey"?n=a.key.rawName:n=e.sourceCode.text.slice(...a.key.range),f(l["custom-groups"],n),a.value===null&&p("shorthand"),a.loc.start.line!==a.loc.end.line&&p("multiline"),t.at(-1).push({size:I(a.range),node:a,group:o(),name:n}),t},[[]]);for(let t of r)P(t,(a,n)=>{let o=h(l.groups,a),p=h(l.groups,n);(o>p||o===p&&O(S(a,n,l)))&&e.report({messageId:"unexpectedVueAttributesOrder",data:{left:a.name,right:n.name},node:n.node,fix:f=>{let y={};for(let c of t){let m=h(l.groups,c);m in y?y[m]=v([...y[m],c],l):y[m]=[c]}let d=[];for(let c of Object.keys(y).sort((m,x)=>Number(m)-Number(x)))d.push(...v(y[c],l));return L(f,t,d,e.sourceCode)}})})}}})}}),Z="sort-named-exports",be=k({name:Z,meta:{type:"suggestion",docs:{description:"enforce sorted named exports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"group-kind":{enum:[T.mixed,T["values-first"],T["types-first"]],default:T.mixed,type:"string"}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({ExportNamedDeclaration:i=>{if(i.specifiers.length>1){let s=j(e.options.at(0),{type:u.alphabetical,"ignore-case":!1,order:g.asc,"group-kind":T.mixed}),l=i.specifiers.map(a=>({size:I(a.range),name:a.local.name,node:a,group:a.exportKind})),r=s["group-kind"]!==T.mixed,t=s["group-kind"]===T["values-first"]?["value","type"]:["type","value"];P(l,(a,n)=>{let o=h(t,a),p=h(t,n);if(r&&o>p||(!r||o===p)&&O(S(a,n,s))){let f=r?t.map(y=>l.filter(d=>d.group===y)).map(y=>v(y,s)).flat():v(l,s);e.report({messageId:"unexpectedNamedExportsOrder",data:{left:a.name,right:n.name},node:n.node,fix:y=>L(y,l,f,e.sourceCode)})}})}}})}),F="sort-named-imports",xe=k({name:F,meta:{type:"suggestion",docs:{description:"enforce sorted named imports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-alias":{type:"boolean",default:!1},"group-kind":{enum:[T.mixed,T["values-first"],T["types-first"]],default:T.mixed,type:"string"}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({ImportDeclaration:i=>{let s=i.specifiers.filter(({type:l})=>l==="ImportSpecifier");if(s.length>1){let l=j(e.options.at(0),{type:u.alphabetical,"ignore-alias":!0,"ignore-case":!1,order:g.asc,"group-kind":T.mixed}),r=s.map(n=>{let o,{name:p}=n.local;return n.type==="ImportSpecifier"&&(l["ignore-alias"]&&({name:p}=n.imported),o=n.importKind),{size:I(n.range),node:n,name:p,group:o}}),t=l["group-kind"]!==T.mixed,a=l["group-kind"]===T["values-first"]?["value","type"]:["type","value"];P(r,(n,o)=>{let p=h(a,n),f=h(a,o);if(t&&p>f||(!t||p===f)&&O(S(n,o,l))){let y=t?a.map(d=>r.filter(c=>c.group===d)).map(d=>v(d,l)).flat():v(r,l);e.report({messageId:"unexpectedNamedImportsOrder",data:{left:n.name,right:o.name},node:o.node,fix:d=>L(d,r,y,e.sourceCode)})}})}}})});let z=(e,i,s)=>e.lines.slice(i.node.loc.end.line,s.node.loc.start.line-1).filter(r=>!r.trim().length).length;const ee="sort-object-types",Ee=k({name:ee,meta:{type:"suggestion",docs:{description:"enforce sorted object types"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"partition-by-new-line":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({TSTypeLiteral:i=>{if(i.members.length>1){let s=j(e.options.at(0),{"partition-by-new-line":!1,type:u.alphabetical,"ignore-case":!1,order:g.asc,"custom-groups":{},groups:[]}),l=i.members.reduce((r,t)=>{var C,b,N,E;let a,n=e.sourceCode.text.slice(t.range.at(0),t.range.at(1)),o=(C=r.at(-1))==null?void 0:C.at(-1),{getGroup:p,defineGroup:f,setCustomGroups:y}=G(s.groups),d=w=>w.replace(/(,|;)$/,"");if(t.type==="TSPropertySignature")t.key.type==="Identifier"?{name:a}=t.key:t.key.type==="Literal"?a=`${t.key.value}`:a=e.sourceCode.text.slice(t.range.at(0),(b=t.typeAnnotation)==null?void 0:b.range.at(0));else if(t.type==="TSIndexSignature"){let w=((N=t.typeAnnotation)==null?void 0:N.range.at(0))??t.range.at(1);a=d(e.sourceCode.text.slice(t.range.at(0),w))}else a=d(e.sourceCode.text.slice(t.range.at(0),t.range.at(1)));y(s["custom-groups"],a),t.loc.start.line!==t.loc.end.line&&f("multiline");let m=n.endsWith(";")||n.endsWith(",")?1:0,x={size:I(t.range)-m,node:t,name:a};return s["partition-by-new-line"]&&o&&z(e.sourceCode,o,x)&&r.push([]),(E=r.at(-1))==null||E.push({...x,group:p()}),r},[[]]);for(let r of l)P(r,(t,a)=>{let n=h(s.groups,t),o=h(s.groups,a);(n>o||n===o&&O(S(t,a,s)))&&e.report({messageId:"unexpectedObjectTypesOrder",data:{left:A(t.name),right:A(a.name)},node:a.node,fix:p=>{let f={};for(let d of r){let c=h(s.groups,d);c in f?f[c]=v([...f[c],d],s):f[c]=[d]}let y=[];for(let d of Object.keys(f).sort((c,m)=>Number(c)-Number(m)))y.push(...v(f[d],s));return L(p,r,y,e.sourceCode)}})})}}})}),te="sort-union-types",Ne=k({name:te,meta:{type:"suggestion",docs:{description:"enforce sorted union types"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"nullable-last":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({TSUnionType:i=>{let s=j(e.options.at(0),{type:u.alphabetical,"nullable-last":!1,"ignore-case":!1,order:g.asc}),l=i.types.map(r=>({group:r.type==="TSNullKeyword"||r.type==="TSUndefinedKeyword"?"nullable":"unknown",name:e.sourceCode.text.slice(...r.range),size:I(r.range),node:r}));P(l,(r,t)=>{let a=O(S(r,t,s));s["nullable-last"]&&(r.group==="nullable"&&t.group==="unknown"?a=!0:r.group==="unknown"&&t.group==="nullable"&&(a=!1)),a&&e.report({messageId:"unexpectedUnionTypesOrder",data:{left:A(r.name),right:A(t.name)},node:t.node,fix:n=>{let o=[];if(s["nullable-last"]){let p=[],f=l.filter(y=>y.group==="nullable"?(p.push(y),!1):!0);o=[...v(f,s),...v(p,s)]}else o=v(l,s);return L(n,l,o,e.sourceCode)}})})}})}),re="sort-interfaces",Ce=k({name:re,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{items:{type:"string"},type:"array"},groups:{type:"array",default:[]},"partition-by-new-line":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({TSInterfaceDeclaration:i=>{if(i.body.body.length>1){let s=j(e.options.at(0),{"partition-by-new-line":!1,type:u.alphabetical,"ignore-case":!1,order:g.asc,"ignore-pattern":[],"custom-groups":{},groups:[]});if(!s["ignore-pattern"].some(l=>D.minimatch(i.id.name,l,{nocomment:!0}))){let l=i.body.body.reduce((r,t)=>{var d,c,m,x;if(t.type==="TSCallSignatureDeclaration")return r.push([]),r;let a=(d=r.at(-1))==null?void 0:d.at(-1),n,{getGroup:o,defineGroup:p,setCustomGroups:f}=G(s.groups);if(t.type==="TSPropertySignature")if(t.key.type==="Identifier")({name:n}=t.key);else if(t.key.type==="Literal")n=`${t.key.value}`;else{let C=((c=t.typeAnnotation)==null?void 0:c.range.at(0))??t.range.at(1)-(t.optional?1:0);n=e.sourceCode.text.slice(t.range.at(0),C)}else if(t.type==="TSIndexSignature"){let C=((m=t.typeAnnotation)==null?void 0:m.range.at(0))??t.range.at(1);n=e.sourceCode.text.slice(t.range.at(0),C)}else{let C=((x=t.returnType)==null?void 0:x.range.at(0))??t.range.at(1);n=e.sourceCode.text.slice(t.range.at(0),C)}let y={size:I(t.range),node:t,name:n};return s["partition-by-new-line"]&&a&&z(e.sourceCode,a,y)&&r.push([]),f(s["custom-groups"],n),t.loc.start.line!==t.loc.end.line&&p("multiline"),r.at(-1).push({...y,group:o()}),r},[[]]);for(let r of l)P(r,(t,a)=>{let n=h(s.groups,t),o=h(s.groups,a);(n>o||n===o&&O(S(t,a,s)))&&e.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:A(t.name),right:A(a.name)},node:a.node,fix:p=>{let f={};for(let d of r){let c=h(s.groups,d);c in f?f[c]=v([...f[c],d],s):f[c]=[d]}let y=[];for(let d of Object.keys(f).sort((c,m)=>Number(c)-Number(m)))y.push(...v(f[d],s));return L(p,r,y,e.sourceCode)}})})}}}})}),se="sort-jsx-props",ve=k({name:se,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},groups:{type:"array"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>[".svelte",".astro",".vue"].includes(q.extname(e.filename))?{}:{JSXElement:i=>{if(i.openingElement.attributes.length>1){let s=j(e.options.at(0),{type:u.alphabetical,"ignore-case":!1,order:g.asc,"custom-groups":{},groups:[]}),l=i.openingElement.attributes.reduce((r,t)=>{if(t.type==="JSXSpreadAttribute")return r.push([]),r;let a=t.name.type==="JSXNamespacedName"?`${t.name.namespace.name}:${t.name.name.name}`:t.name.name,{getGroup:n,defineGroup:o,setCustomGroups:p}=G(s.groups);p(s["custom-groups"],a),t.value===null&&o("shorthand"),t.loc.start.line!==t.loc.end.line&&o("multiline");let f={size:I(t.range),group:n(),node:t,name:a};return r.at(-1).push(f),r},[[]]);for(let r of l)P(r,(t,a)=>{let n=h(s.groups,t),o=h(s.groups,a);(n>o||n===o&&O(S(t,a,s)))&&e.report({messageId:"unexpectedJSXPropsOrder",data:{left:t.name,right:a.name},node:a.node,fix:p=>{let f={};for(let d of r){let c=h(s.groups,d);c in f?f[c]=v([...f[c],d],s):f[c]=[d]}let y=[];for(let d of Object.keys(f).sort((c,m)=>Number(c)-Number(m)))y.push(...v(f[d],s));return L(p,r,y,e.sourceCode)}})})}}}}),ae="sort-exports",we=k({name:ae,meta:{type:"suggestion",docs:{description:"enforce sorted exports"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>{let i=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1}),s=[[]],l=r=>{r.type==="ExportAllDeclaration"&&r.exported===null?s.push([]):s.at(-1).push({size:I(r.range),name:r.source.value,node:r})};return{ExportAllDeclaration:l,ExportNamedDeclaration:r=>{r.source!==null&&l(r)},"Program:exit":()=>{for(let r of s)P(r,(t,a)=>{O(S(t,a,i))&&e.report({messageId:"unexpectedExportsOrder",data:{left:t.name,right:a.name},node:a.node,fix:n=>L(n,r,v(r,i),e.sourceCode)})})}}}}),oe="sort-imports",Se=k({name:oe,meta:{type:"suggestion",docs:{description:"enforce sorted imports"},fixable:"code",schema:[{id:"sort-imports",type:"object",properties:{"custom-groups":{type:"object",properties:{type:{type:"object"},value:{type:"object"}},additionalProperties:!1},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{items:{type:"string"},type:"array"},"newlines-between":{enum:["ignore","always","never"],default:"always",type:"string"},"max-line-length":{type:"integer",minimum:0,exclusiveMinimum:!0}},allOf:[{$ref:"#/definitions/max-line-length-requires-line-length-type"}],additionalProperties:!1,dependencies:{"max-line-length":["type"]},definitions:{"is-line-length":{properties:{type:{enum:[u["line-length"]],type:"string"}},required:["type"],type:"object"},"max-line-length-requires-line-length-type":{anyOf:[{not:{required:["max-line-length"],type:"object"},type:"object"},{$ref:"#/definitions/is-line-length"}]}}}],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:u.alphabetical,order:g.asc}],create:e=>{let i=j(e.options.at(0),{"newlines-between":"always","custom-groups":{type:{},value:{}},"internal-pattern":["~/**"],type:u.alphabetical,order:g.asc,"ignore-case":!1,groups:[]}),s=!1;for(let o of i.groups)if(Array.isArray(o))for(let p of o)p==="unknown"&&(s=!0);else o==="unknown"&&(s=!0);s||(i.groups=[...i.groups,"unknown"]);let l=[],r=o=>o.type==="ImportDeclaration"&&o.specifiers.length===0,t=o=>{let p=E=>[".less",".scss",".sass",".styl",".pcss",".css",".sss"].some(w=>E.endsWith(w)),f=E=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(E),y=E=>E.indexOf("..")===0,d=E=>E.indexOf("./")===0,{getGroup:c,defineGroup:m,setCustomGroups:x}=G(i.groups),C=E=>i["internal-pattern"].length&&i["internal-pattern"].some(w=>D.minimatch(E.source.value,w,{nocomment:!0})),b=E=>{let w=["bun","bun:ffi","bun:jsc","bun:sqlite","bun:test","bun:wrap","detect-libc","undici","ws"];return ce.builtinModules.includes(E.startsWith("node:")?E.split("node:")[1]:E)||w.includes(E)},N=E=>!(E.startsWith(".")||E.startsWith("/"));return o.importKind==="type"&&(o.type==="ImportDeclaration"&&(x(i["custom-groups"].type,o.source.value),f(o.source.value)&&m("index-type"),d(o.source.value)&&m("sibling-type"),y(o.source.value)&&m("parent-type"),C(o)&&m("internal-type"),b(o.source.value)&&m("builtin-type"),N(o.source.value)&&m("external-type")),m("type")),o.type==="ImportDeclaration"&&(x(i["custom-groups"].value,o.source.value),r(o)&&p(o.source.value)&&m("side-effect-style"),r(o)&&m("side-effect"),p(o.source.value)&&m("style"),f(o.source.value)&&m("index"),d(o.source.value)&&m("sibling"),y(o.source.value)&&m("parent"),C(o)&&m("internal"),b(o.source.value)&&m("builtin"),N(o.source.value)&&m("external")),c()},a=o=>o.specifiers.length>1,n=o=>{let p;o.type==="ImportDeclaration"?p=o.source.value:o.moduleReference.type==="TSExternalModuleReference"&&o.moduleReference.expression.type==="Literal"?p=`${o.moduleReference.expression.value}`:p=e.sourceCode.text.slice(...o.moduleReference.range),l.push({size:I(o.range),group:t(o),name:p,node:o,...i.type===u["line-length"]&&i["max-line-length"]&&{hasMultipleImportDeclarations:a(o)}})};return{TSImportEqualsDeclaration:n,ImportDeclaration:n,"Program:exit":()=>{var y;let o=(d,c)=>!!e.sourceCode.getTokensBetween(d.node,V(c.node,e.sourceCode)||c.node,{includeComments:!0}).length,p=(d,c)=>{let m=[],x={};for(let b of c){let N=h(i.groups,b);N in x?x[N]=v([...x[N],b],i):x[N]=[b]}let C=Object.keys(x).sort((b,N)=>Number(b)-Number(N)).reduce((b,N)=>[...b,...x[N]],[]);for(let b=0,N=C.length;b<N;b++){let E=C.at(b);if(m.push(d.replaceTextRange(M(c.at(b).node,e.sourceCode),e.sourceCode.text.slice(...M(E.node,e.sourceCode)))),i["newlines-between"]!=="ignore"){let w=C.at(b+1);if(w){let R=z(e.sourceCode,c.at(b),c.at(b+1));(i["newlines-between"]==="always"&&h(i.groups,E)===h(i.groups,w)&&R!==0||i["newlines-between"]==="never"&&R>0)&&m.push(d.removeRange([M(c.at(b).node,e.sourceCode).at(1),M(c.at(b+1).node,e.sourceCode).at(0)-1])),i["newlines-between"]==="always"&&h(i.groups,E)!==h(i.groups,w)&&R>1&&m.push(d.replaceTextRange([M(c.at(b).node,e.sourceCode).at(1),M(c.at(b+1).node,e.sourceCode).at(0)-1],`
2
+ `)),i["newlines-between"]==="always"&&h(i.groups,E)!==h(i.groups,w)&&R===0&&m.push(d.insertTextAfterRange(M(c.at(b).node,e.sourceCode),`
3
+ `))}}}return m},f=[[]];for(let d of l){let c=(y=f.at(-1))==null?void 0:y.at(-1);c&&o(c,d)?f.push([d]):f.at(-1).push(d)}for(let d of f)P(d,(c,m)=>{let x=h(i.groups,c),C=h(i.groups,m),b=z(e.sourceCode,c,m);!(r(c.node)&&r(m.node))&&!o(c,m)&&(x>C||x===C&&O(S(c,m,i)))&&e.report({messageId:"unexpectedImportsOrder",data:{left:c.name,right:m.name},node:m.node,fix:N=>p(N,d)}),i["newlines-between"]==="never"&&b>0&&e.report({messageId:"extraSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:N=>p(N,d)}),i["newlines-between"]==="always"&&(x<C&&b===0?e.report({messageId:"missedSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:N=>p(N,d)}):(b>1||x===C&&b>0)&&e.report({messageId:"extraSpacingBetweenImports",data:{left:c.name,right:m.name},node:m.node,fix:N=>p(N,d)}))})}}}}),ne="sort-objects",Ae=k({name:ne,meta:{type:"suggestion",docs:{description:"enforce sorted objects"},fixable:"code",schema:[{type:"object",properties:{"custom-groups":{type:"object"},"partition-by-comment":{type:["boolean","string","array"],default:!1},"partition-by-new-line":{type:"boolean",default:!1},"styled-components":{type:"boolean",default:!0},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{items:{type:"string"},type:"array"},groups:{type:"array"}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>{let i=s=>{let l=j(e.options.at(0),{"partition-by-new-line":!1,"partition-by-comment":!1,type:u.alphabetical,"styled-components":!0,"ignore-case":!1,"ignore-pattern":[],order:g.asc,"custom-groups":{},groups:[]}),r=s.parent.type==="VariableDeclarator"&&s.parent.id.type==="Identifier"?s.parent.id.name:null;if(!(l["ignore-pattern"].length&&typeof r=="string"?l["ignore-pattern"].some(a=>D.minimatch(r,a,{nocomment:!0})):!1)&&s.properties.length>1){let a=p=>p.type==="Identifier"&&p.name==="styled",n=p=>p!==void 0&&p.type==="CallExpression"&&(p.callee.type==="MemberExpression"&&a(p.callee.object)||p.callee.type==="CallExpression"&&a(p.callee.callee));if(!l["styled-components"]&&(n(s.parent)||s.parent.type==="ArrowFunctionExpression"&&n(s.parent.parent)))return;let o=p=>p.reduce((f,y)=>{var R;if(y.type==="SpreadElement"||y.type==="RestElement")return f.push([]),f;let d=V(y,e.sourceCode),c=(R=f.at(-1))==null?void 0:R.at(-1);l["partition-by-comment"]&&d&&J(l["partition-by-comment"],d.value)&&f.push([]);let m,x="ignore",C=[],{getGroup:b,setCustomGroups:N}=G(l.groups);y.key.type==="Identifier"?{name:m}=y.key:y.key.type==="Literal"?m=`${y.key.value}`:m=e.sourceCode.text.slice(...y.key.range);let E={size:I(y.range),node:y,name:m};l["partition-by-new-line"]&&c&&z(e.sourceCode,c,E)&&f.push([]),y.value.type==="AssignmentPattern"&&(_=>{_.right.type==="Identifier"&&C.push(_.right.name);let ue=$=>{let U=[];switch($.type){case"ArrowFunctionExpression":U.push($.body);break;case"ConditionalExpression":U.push($.consequent,$.alternate);break;case"LogicalExpression":case"BinaryExpression":U.push($.left,$.right);break;case"CallExpression":U.push(...$.arguments);break}U.forEach(B=>{B.type==="Identifier"&&C.push(B.name),(B.type==="BinaryExpression"||B.type==="ConditionalExpression")&&ue(B)})};switch(_.right.type){case"ArrowFunctionExpression":case"ConditionalExpression":case"LogicalExpression":case"BinaryExpression":case"CallExpression":ue(_.right);break}})(y.value),N(l["custom-groups"],m);let w={...E,group:b(),dependencies:C,position:x};return f.at(-1).push(w),f},[[]]);for(let p of o(s.properties))P(p,(f,y)=>{let d=h(l.groups,f),c=h(l.groups,y);if(d>c||d===c&&O(S(f,y,l))){let m=x=>{let C={};for(let N of p){let E=h(l.groups,N);E in C?C[E]=v([...C[E],N],l):C[E]=[N]}let b=[];for(let N of Object.keys(C).sort((E,w)=>Number(E)-Number(w)))b.push(...v(C[N],l));return L(x,p,b,e.sourceCode,{partitionComment:l["partition-by-comment"]})};e.report({messageId:"unexpectedObjectsOrder",data:{left:A(f.name),right:A(y.name)},node:y.node,fix:m})}})}};return{ObjectExpression:i,ObjectPattern:i}}}),le="sort-classes",ke=k({name:le,meta:{type:"suggestion",docs:{description:"enforce sorted classes"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},"ignore-case":{type:"boolean",default:!1},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},groups:{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({ClassBody:i=>{if(i.body.length>1){let s=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),l=i.body.map(r=>{var f;let t,{getGroup:a,defineGroup:n}=G(s.groups);r.type==="StaticBlock"?t="static":r.type==="TSIndexSignature"?t=e.sourceCode.text.slice(r.range.at(0),((f=r.typeAnnotation)==null?void 0:f.range.at(0))??r.range.at(1)):r.key.type==="Identifier"?{name:t}=r.key:t=e.sourceCode.text.slice(...r.key.range);let o=t.startsWith("_")||t.startsWith("#"),p="decorators"in r&&r.decorators.length>0;if(r.type==="MethodDefinition"){r.kind==="constructor"&&n("constructor");let y=r.accessibility==="private"||o,d=r.static;p&&(r.kind==="get"&&n("decorated-get-method"),r.kind==="set"&&n("decorated-set-method"),n("decorated-method")),y&&d&&n("static-private-method"),y&&n("private-method"),d&&n("static-method"),r.kind==="get"&&n("get-method"),r.kind==="set"&&n("set-method"),n("method")}else r.type==="TSIndexSignature"?n("index-signature"):r.type==="AccessorProperty"?p&&((r.accessibility==="private"||o)&&n("private-decorated-accessor-property"),n("decorated-accessor-property")):r.type==="PropertyDefinition"&&(p&&((r.accessibility==="private"||o)&&n("private-decorated-property"),n("decorated-property")),(r.accessibility==="private"||o)&&n("private-property"),r.static&&n("static-property"),n("property"));return{size:I(r.range),group:a(),node:r,name:t}});P(l,(r,t)=>{let a=h(s.groups,r),n=h(s.groups,t);r.name!==t.name&&(a>n||a===n&&O(S(r,t,s)))&&e.report({messageId:"unexpectedClassesOrder",data:{left:A(r.name),right:A(t.name)},node:t.node,fix:o=>{let p=[],f=l.reduce((d,c)=>{let m=h(s.groups,c);return m in d?d[m]=v([...d[m],c],s):d[m]=[c],d},{}),y=Object.keys(f).sort((d,c)=>Number(d)-Number(c)).reduce((d,c)=>[...d,...f[c]],[]);for(let d=0,c=y.length;d<c;d++)p.push(o.replaceTextRange(M(l.at(d).node,e.sourceCode),e.sourceCode.text.slice(...M(y.at(d).node,e.sourceCode))));return p}})})}}})}),ie="sort-enums",Ie=k({name:ie,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums"},fixable:"code",schema:[{type:"object",properties:{"partition-by-comment":{default:!1,type:["boolean","string","array"]},type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},"ignore-case":{type:"boolean",default:!1},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({TSEnumDeclaration:i=>{if(i.members.length>1&&i.members.every(({initializer:s})=>s)){let s=j(e.options.at(0),{type:u.alphabetical,order:g.asc,"ignore-case":!1,"partition-by-comment":!1}),l=s["partition-by-comment"],r=i.members.reduce((t,a)=>{let n=V(a,e.sourceCode);l&&n&&J(l,n.value)&&t.push([]);let p={name:a.id.type==="Literal"?`${a.id.value}`:`${e.sourceCode.text.slice(...a.id.range)}`,node:a,size:I(a.range)};return t.at(-1).push(p),t},[[]]);for(let t of r)P(t,(a,n)=>{O(S(a,n,s))&&e.report({messageId:"unexpectedEnumsOrder",data:{left:A(a.name),right:A(n.name)},node:n.node,fix:o=>L(o,t,v(t,s),e.sourceCode,{partitionComment:l})})})}}})}),pe="sort-maps",Oe=k({name:pe,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements"},fixable:"code",schema:[{type:"object",properties:{type:{enum:[u.alphabetical,u.natural,u["line-length"]],default:u.alphabetical,type:"string"},order:{enum:[g.asc,g.desc],default:g.asc,type:"string"},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:u.alphabetical,order:g.asc}],create:e=>({NewExpression:i=>{if(i.callee.type==="Identifier"&&i.callee.name==="Map"&&i.arguments.length&&i.arguments[0].type==="ArrayExpression"){let[{elements:s}]=i.arguments;if(s.length>1){let l=j(e.options.at(0),{type:u.alphabetical,"ignore-case":!1,order:g.asc}),r=s.reduce((t,a)=>(a===null||a.type==="SpreadElement"?t.push([]):t.at(-1).push(a),t),[[]]);for(let t of r){let a=t.map(n=>{let o;if(n.type==="ArrayExpression"){let[p]=n.elements;p?p.type==="Literal"?o=p.raw:o=e.sourceCode.text.slice(...p.range):o=`${p}`}else o=e.sourceCode.text.slice(...n.range);return{size:I(n.range),node:n,name:o}});P(a,(n,o)=>{O(S(n,o,l))&&e.report({messageId:"unexpectedMapElementsOrder",data:{left:A(n.name),right:A(o.name)},node:o.node,fix:p=>L(p,a,v(a,l),e.sourceCode)})})}}}}})}),je="eslint-plugin-perfectionist";let K=e=>{let i={[oe]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"custom-groups":{value:{},type:{}},"newlines-between":"always","internal-pattern":["~/**"]}],[le]:["error",{groups:["index-signature","static-property","private-property","property","constructor","static-method","private-method","method",["get-method","set-method"],"unknown"]}],[ne]:["error",{"partition-by-comment":!1}],[Q]:["error",{"spread-last":!0}],[X]:["error"],[H]:["error"],[Y]:["error"],[Z]:["error"],[F]:["error"],[ee]:["error"],[te]:["error"],[re]:["error"],[se]:["error"],[ae]:["error"],[ie]:["error"],[pe]:["error"]};return{rules:Object.fromEntries(Object.entries(i).map(([s,[l,r={}]])=>[`perfectionist/${s}`,[l,Object.assign(r,e)]])),plugins:["perfectionist"]}};const Pe={rules:{[Q]:me,[H]:ye,[le]:ke,[ie]:Ie,[ae]:we,[oe]:Se,[re]:Ce,[se]:ve,[pe]:Oe,[Z]:be,[F]:xe,[ee]:Ee,[ne]:Ae,[X]:ge,[te]:Ne,[Y]:he},configs:{"recommended-alphabetical":K({type:u.alphabetical,order:g.asc,"ignore-case":!1}),"recommended-natural":K({type:u.natural,order:g.asc,"ignore-case":!1}),"recommended-line-length":K({type:u["line-length"],order:g.desc})},name:je};module.exports=Pe;