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