eslint-plugin-perfectionist 2.1.0 → 2.3.0

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