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