Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-perfectionist

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-perfectionist - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

6

dist/index.js

@@ -1,3 +0,3 @@

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

@@ -62,3 +63,3 @@ "repository": "https://github.com/azat-io/eslint-plugin-perfectionist",

"dependencies": {
"@typescript-eslint/utils": "^6.10.0",
"@typescript-eslint/utils": "^6.12.0",
"minimatch": "^9.0.3",

@@ -65,0 +66,0 @@ "natural-compare-lite": "^1.4.0"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc