eslint-plugin-perfectionist 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var te=Object.defineProperty;var ae=(t,l,s)=>l in t?te(t,l,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[l]=s;var H=(t,l,s)=>(ae(t,typeof l!="symbol"?l+"":l,s),s);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),re=require("natural-compare-lite"),C=require("minimatch"),Q=require("is-core-module"),se=require("json5"),ne=require("path"),oe=require("fs");let N=v.ESLintUtils.RuleCreator(t=>`https://eslint-plugin-perfectionist.azat.io/rules/${t}`),O=t=>t.replaceAll(/\s\s+/g," ").trim(),P=t=>{let[l,s]=t;return s-l};var i=(t=>(t.alphabetical="alphabetical",t["line-length"]="line-length",t.natural="natural",t))(i||{}),d=(t=>(t.desc="desc",t.asc="asc",t))(d||{});let A=(t,l,s)=>{var e,o;if((e=l.dependencies)!=null&&e.includes(t.name))return!1;if((o=t.dependencies)!=null&&o.includes(l.name))return!0;let n=s.order==="asc"?1:-1,p,r=a=>s["ignore-case"]?a.toLowerCase():a;return s.type===i.alphabetical?p=(a,c)=>r(a.name).localeCompare(r(c.name)):s.type===i.natural?p=(a,c)=>re(r(a.name),r(c.name)):p=(a,c)=>a.size-c.size,n*p(t,l)>0},b=(t,l)=>[...t].sort((s,n)=>Number(A(s,n,l))||-1),le=(t,l)=>{let s=l.getTokenAfter(t,{filter:({type:n,value:p})=>!(n===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(p)),includeComments:!0});return((s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Line)&&t.loc.end.line===s.loc.end.line?s:null},Z=(t,l)=>{let[s,n]=l.getTokensBefore(t,{filter:({type:p,value:r})=>!(p===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(r)),includeComments:!0,count:2});return((n==null?void 0:n.type)===u.AST_TOKEN_TYPES.Block||(n==null?void 0:n.type)===u.AST_TOKEN_TYPES.Line)&&t.loc.start.line-n.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==n.loc.start.line?n:null},I=(t,l)=>{var e;let s=t.range.at(0),n=t.range.at(1),p=l.text.slice(s,n);if(v.ASTUtils.isParenthesized(t,l)){let o=l.getTokenBefore(t,v.ASTUtils.isOpeningParenToken),a=l.getTokenAfter(t,v.ASTUtils.isClosingParenToken);s=o.range.at(0),n=a.range.at(1)}let r=Z(t,l);if(p.endsWith(";")||p.endsWith(",")){let o=l.getTokensAfter(t,{includeComments:!0,count:2});t.loc.start.line===((e=o.at(1))==null?void 0:e.loc.start.line)&&(n-=1)}return r&&(s=r.range.at(0)),[s,n]},Y=(t,l,s,n)=>{let p=[];return l.forEach(({node:r},e)=>{p.push(t.replaceTextRange(I(r,n),n.text.slice(...I(s[e].node,n))));let o=le(s[e].node,n);if(o){let c=[n.getTokenBefore(o).range.at(1),o.range.at(1)];p.push(t.replaceTextRange(c,""));let g=n.getTokenAfter(r);p.push(t.insertTextAfter((g==null?void 0:g.loc.end.line)===r.loc.end.line?g:r,n.text.slice(...c)))}}),p},w=(t={},l)=>Object.assign(l,t),D=(t,l)=>{if(t.length>1)for(let s=1;s<t.length;s++){let n=t.at(s-1),p=t.at(s);n&&p&&l(n,p,s-1)}};const L="sort-array-includes",ie=N({name:L,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"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:d.asc}],create:t=>({MemberExpression:l=>{if((l.object.type===u.AST_NODE_TYPES.ArrayExpression||l.object.type===u.AST_NODE_TYPES.NewExpression)&&l.property.type===u.AST_NODE_TYPES.Identifier&&l.property.name==="includes"){let s=l.object.type===u.AST_NODE_TYPES.ArrayExpression?l.object.elements:l.object.arguments;if(s.length>1){let n=w(t.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1,"spread-last":!1}),p=t.getSourceCode(),r=s.reduce((e,o)=>(o!==null&&e.at(0).push({name:o.type===u.AST_NODE_TYPES.Literal?o.raw:p.text.slice(...o.range),size:P(o.range),type:o.type,node:o}),e),[[],[]]).flat();D(r,(e,o)=>{let a;n["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&o.node.type===u.AST_NODE_TYPES.SpreadElement?a=!1:n["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&o.node.type===u.AST_NODE_TYPES.Literal?a=!0:a=A(e,o,n),a&&t.report({messageId:"unexpectedArrayIncludesOrder",data:{left:O(e.name),right:O(o.name)},node:o.node,fix:c=>{let g=b(r,n);return n["spread-last"]&&g.forEach((S,T)=>{S.node.type===u.AST_NODE_TYPES.SpreadElement&&g.push(g.splice(T,1).at(0))}),Y(c,r,g,p)}})})}}}})}),$="sort-named-exports",pe=N({name:$,meta:{type:"suggestion",docs:{description:"enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({ExportNamedDeclaration:l=>{if(l.specifiers.length>1){let s=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),n=t.getSourceCode(),p=l.specifiers.map(r=>({size:P(r.range),name:r.local.name,node:r}));D(p,(r,e)=>{A(r,e,s)&&t.report({messageId:"unexpectedNamedExportsOrder",data:{left:r.name,right:e.name},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),M="sort-named-imports",ce=N({name:M,meta:{type:"suggestion",docs:{description:"enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({ImportDeclaration:l=>{let s=l.specifiers.filter(({type:n})=>n===u.AST_NODE_TYPES.ImportSpecifier);if(s.length>1){let n=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=t.getSourceCode(),r=s.map(e=>({size:P(e.range),name:e.local.name,node:e}));D(r,(e,o)=>{A(e,o,n)&&t.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:o.name},node:o.node,fix:a=>Y(a,r,b(r,n),p)})})}}})}),B="sort-object-types",de=N({name:B,meta:{type:"suggestion",docs:{description:"enforce sorted object types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({TSTypeLiteral:l=>{if(l.members.length>1){let s=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),n=t.getSourceCode(),p=l.members.map(r=>{var S,T;let e,o=n.text.slice(r.range.at(0),r.range.at(1)),a=y=>y.replace(/(,|;)$/,"");if(r.type===u.AST_NODE_TYPES.TSPropertySignature)r.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=r.key:r.key.type===u.AST_NODE_TYPES.Literal?e=`${r.key.value}`:e=n.text.slice(r.range.at(0),(S=r.typeAnnotation)==null?void 0:S.range.at(0));else if(r.type===u.AST_NODE_TYPES.TSIndexSignature){let y=((T=r.typeAnnotation)==null?void 0:T.range.at(0))??r.range.at(1);e=a(n.text.slice(r.range.at(0),y))}else e=a(n.text.slice(r.range.at(0),r.range.at(1)));let g=o.endsWith(";")||o.endsWith(",")?1:0;return{size:P(r.range)-g,node:r,name:e}});D(p,(r,e)=>{A(r,e,s)&&t.report({messageId:"unexpectedObjectTypesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),U="sort-map-elements",fe=N({name:U,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({NewExpression:l=>{if(l.callee.type===u.AST_NODE_TYPES.Identifier&&l.callee.name==="Map"&&l.arguments.length&&l.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let[{elements:s}]=l.arguments;if(s.length>1){let n=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=t.getSourceCode();s.reduce((e,o)=>(o===null||o.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(o),e),[[]]).forEach(e=>{let o=e.map(a=>{let c;if(a.type===u.AST_NODE_TYPES.ArrayExpression){let[g]=a.elements;g?g.type===u.AST_NODE_TYPES.Literal?c=g.raw:c=p.text.slice(...g.range):c=`${g}`}else c=p.text.slice(...a.range);return{size:P(a.range),node:a,name:c}});D(o,(a,c)=>{A(a,c,n)&&t.report({messageId:"unexpectedMapElementsOrder",data:{left:O(a.name),right:O(c.name)},node:c.node,fix:g=>Y(g,o,b(o,n),p)})})})}}}})}),z="sort-union-types",ue=N({name:z,meta:{type:"suggestion",docs:{description:"enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({TSUnionType:l=>{let s=t.getSourceCode(),n=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=l.types.map(r=>({name:s.text.slice(...r.range),size:P(r.range),node:r}));D(p,(r,e)=>{A(r,e,n)&&t.report({messageId:"unexpectedUnionTypesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,n),s)})})}})}),q="sort-interfaces",ge=N({name:q,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({TSInterfaceDeclaration:l=>{if(l.body.body.length>1){let s=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc,"ignore-pattern":[]});if(!s["ignore-pattern"].some(n=>C.minimatch(l.id.name,n))){let n=t.getSourceCode(),p=l.body.body.map(r=>{var o,a,c;let e;if(r.type===u.AST_NODE_TYPES.TSPropertySignature)if(r.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=r.key);else if(r.key.type===u.AST_NODE_TYPES.Literal)e=`${r.key.value}`;else{let g=((o=r.typeAnnotation)==null?void 0:o.range.at(0))??r.range.at(1)-(r.optional?1:0);e=n.text.slice(r.range.at(0),g)}else if(r.type===u.AST_NODE_TYPES.TSIndexSignature){let g=((a=r.typeAnnotation)==null?void 0:a.range.at(0))??r.range.at(1);e=n.text.slice(r.range.at(0),g)}else{let g=((c=r.returnType)==null?void 0:c.range.at(0))??r.range.at(1);e=n.text.slice(r.range.at(0),g)}return{size:P(r.range),node:r,name:e}});D(p,(r,e)=>{A(r,e,s)&&t.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}}})});let F=(t,l)=>t.reduce((s,n)=>{let p=l(n);return p in s||(s[p]=[]),s[p].push(n),s},{});const J="sort-jsx-props",me=N({name:J,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"always-on-top":{type:"array",default:[]},"ignore-case":{type:"boolean",default:!1},shorthand:{enum:["first","last","ignore"]},callback:{enum:["first","last","ignore"]},multiline:{enum:["first","last","ignore"]}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({JSXElement:l=>{if(l.openingElement.attributes.length>1){let s=w(t.options.at(0),{type:i.alphabetical,shorthand:"ignore",multiline:"ignore",callback:"ignore","always-on-top":[],"ignore-case":!1,order:d.asc}),n=t.getSourceCode();l.openingElement.attributes.reduce((r,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return r.push([]),r;let o="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&s["always-on-top"].includes(e.name.name)?o="exception":(s.shorthand!=="ignore"&&e.value===null&&(o=s.shorthand),s.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?o=s.callback:s.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(o=s.multiline));let a={name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:P(e.range),node:e,position:o};return r.at(-1).push(a),r},[[]]).forEach(r=>{D(r,(e,o)=>{let a;if(e.position==="exception"&&o.position==="exception")a=s["always-on-top"].indexOf(e.name)>s["always-on-top"].indexOf(o.name);else if(e.position===o.position)a=A(e,o,s);else{let c={exception:2,first:1,ignore:0,last:-1};a=c[e.position]<c[o.position]}a&&t.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:o.name},node:o.node,fix:c=>{let g=F(r,({position:y})=>y),S=y=>y in g?g[y]:[],T=[S("exception").sort((y,f)=>s["always-on-top"].indexOf(y.name)-s["always-on-top"].indexOf(f.name)),b(S("first"),s),b(S("ignore"),s),b(S("last"),s)].flat();return Y(c,r,T,n)}})})})}}})});class ee{static get(){return this._instance?this._instance:(this._instance=se.parse(oe.readFileSync(ne.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}H(ee,"_instance");const W="sort-imports",ye=N({name:W,meta:{type:"suggestion",docs:{description:"enforce sorted imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{type:"array",default:["~/**"]},"newlines-between":{enum:["ignore","always","never"],default:"always"},"read-tsconfig":{type:"boolean",default:!1}},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:d.asc}],create:t=>{var o;let l=w(t.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:i.alphabetical,"read-tsconfig":!1,order:d.asc,"ignore-case":!1,groups:[]}),s=[];if(l["read-tsconfig"]){let a=ee.get();(o=a.compilerOptions)!=null&&o.paths&&Object.keys(a.compilerOptions.paths).forEach(c=>{s.push(c)})}let n=t.getSourceCode(),p=[],r=a=>{let c,g=E=>[".less",".scss",".sass",".styl",".pcss",".css",".sss"].some(x=>E.endsWith(x)),S=E=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(E),T=E=>E.indexOf("..")===0,y=E=>E.indexOf("./")===0,f=E=>{!c&&l.groups.flat().includes(E)&&(c=E)},m=E=>l["internal-pattern"].length&&l["internal-pattern"].some(x=>C.minimatch(E.source.value,x))||s.some(x=>C.minimatch(E.source.value,x));return a.importKind==="type"&&(a.type===u.AST_NODE_TYPES.ImportDeclaration&&(Q(a.source.value)&&f("builtin-type"),m(a)&&f("internal-type"),S(a.source.value)&&f("index-type"),T(a.source.value)&&f("parent-type"),y(a.source.value)&&f("sibling-type")),f("type")),!c&&a.type===u.AST_NODE_TYPES.ImportDeclaration&&(Q(a.source.value)&&f("builtin"),m(a)&&f("internal"),g(a.source.value)&&f("style"),a.specifiers.length===0&&f("side-effect"),S(a.source.value)&&f("index"),T(a.source.value)&&f("parent"),y(a.source.value)&&f("sibling"),f("external")),c??"unknown"},e=a=>{let c;a.type===u.AST_NODE_TYPES.ImportDeclaration?c=a.source.value:a.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&a.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?c=`${a.moduleReference.expression.value}`:c=n.text.slice(...a.moduleReference.range),p.push({size:P(a.range),group:r(a),name:c,node:a})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let a=y=>{for(let f=0,m=l.groups.length;f<m;f++){let E=l.groups[f];if(y.group===E||Array.isArray(E)&&E.includes(y.group))return f}return l.groups.length},c=(y,f)=>!!n.getTokensBetween(y.node,Z(f.node,n)||f.node,{includeComments:!0}).length,g=(y,f)=>n.lines.slice(y.node.loc.end.line,f.node.loc.start.line-1).filter(E=>!E.trim().length).length,S=(y,f)=>{let m=[],E=f.reduce((_,h)=>{let j=a(h);return j in _?_[j]=b([..._[j],h],l):_[j]=[h],_},{}),x=Object.keys(E).sort().reduce((_,h)=>[..._,...E[h]],[]);return x.forEach((_,h)=>{if(m.push(y.replaceTextRange(I(f.at(h).node,n),n.text.slice(...I(_.node,n)))),l["newlines-between"]!=="ignore"){let j=x.at(h+1);if(j){let k=g(f.at(h),f.at(h+1));(l["newlines-between"]==="always"&&a(_)===a(j)&&k!==0||l["newlines-between"]==="never"&&k>0)&&m.push(y.removeRange([I(f.at(h).node,n).at(1),I(f.at(h+1).node,n).at(0)-1])),l["newlines-between"]==="always"&&k>1&&m.push(y.replaceTextRange([I(f.at(h).node,n).at(1),I(f.at(h+1).node,n).at(0)-1],`
2
- `)),l["newlines-between"]==="always"&&a(_)!==a(j)&&k===0&&m.push(y.insertTextAfterRange(I(f.at(h).node,n),`
3
- `))}}}),m};p.reduce((y,f)=>{var E;let m=(E=y.at(-1))==null?void 0:E.at(-1);return m&&c(m,f)?y.push([f]):y.at(-1).push(f),y},[[]]).forEach(y=>{D(y,(f,m)=>{let E=a(f),x=a(m),_=g(f,m);!c(f,m)&&(E>x||E===x&&A(f,m,l))&&t.report({messageId:"unexpectedImportsOrder",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}),l["newlines-between"]==="never"&&_>0&&t.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}),l["newlines-between"]==="always"&&(E<x&&_===0?t.report({messageId:"missedSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}):(_>1||E===x&&_>0)&&t.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}))})})}}}}),X="sort-classes",Ee=N({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted classes",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[d.asc,d.desc],default:d.asc},groups:{type:"array",default:["property","constructor","method","unknown"]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({ClassBody:l=>{if(l.body.length>1){let s=w(t.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),n=t.getSourceCode(),p=l.body.map(e=>{var g;let o,a;e.type===u.AST_NODE_TYPES.StaticBlock?a="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?a=n.text.slice(e.range.at(0),((g=e.typeAnnotation)==null?void 0:g.range.at(0))??e.range.at(1)):e.key.type===u.AST_NODE_TYPES.Identifier?{name:a}=e.key:a=n.text.slice(...e.key.range);let c=S=>{!o&&s.groups.flat().includes(S)&&(o=S)};return e.type===u.AST_NODE_TYPES.MethodDefinition?(e.kind==="constructor"&&c("constructor"),e.static&&c("static-method"),e.accessibility==="private"&&c("private-method"),c("method")):e.type===u.AST_NODE_TYPES.PropertyDefinition&&(e.static&&c("static-property"),e.accessibility==="private"&&c("private-property"),c("property")),{size:P(e.range),group:o??"unknown",node:e,name:a}}),r=e=>{for(let o=0,a=s.groups.length;o<a;o++){let c=s.groups[o];if(e.group===c||Array.isArray(c)&&c.includes(e.group))return o}return s.groups.length};D(p,(e,o)=>{let a=r(e),c=r(o);(a>c||a===c&&A(e,o,s))&&t.report({messageId:"unexpectedClassesOrder",data:{left:O(e.name),right:O(o.name)},node:o.node,fix:g=>{let S=[],T=p.reduce((f,m)=>{let E=r(m);return E in f?f[E]=b([...f[E],m],s):f[E]=[m],f},{});return Object.keys(T).sort().reduce((f,m)=>[...f,...T[m]],[]).forEach((f,m)=>{S.push(g.replaceTextRange(I(p.at(m).node,n),n.text.slice(...I(f.node,n))))}),S}})})}}})}),G="sort-objects",Se=N({name:G,meta:{type:"suggestion",docs:{description:"enforce sorted objects",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},"always-on-top":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>{let l=s=>{if(s.properties.length>1){let n=w(t.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc,"always-on-top":[]}),p=t.getSourceCode();(e=>e.reduce((o,a)=>{if(a.type===u.AST_NODE_TYPES.SpreadElement||a.type===u.AST_NODE_TYPES.RestElement)return o.push([]),o;let c,g="ignore",S=[];if(a.key.type===u.AST_NODE_TYPES.Identifier?{name:c}=a.key:a.key.type===u.AST_NODE_TYPES.Literal?c=`${a.key.value}`:c=p.text.slice(...a.key.range),a.key.type===u.AST_NODE_TYPES.Identifier&&n["always-on-top"].includes(a.key.name)&&(g="exception"),a.value.type===u.AST_NODE_TYPES.AssignmentPattern){let y=(f,m)=>{f.right.type===u.AST_NODE_TYPES.Identifier&&S.push(f.right.name),!m&&f.left.type===u.AST_NODE_TYPES.Identifier&&S.push(f.left.name);let E=x=>{x.right.type===u.AST_NODE_TYPES.Identifier&&S.push(x.right.name),x.left.type===u.AST_NODE_TYPES.BinaryExpression&&y(x.left,!1)};f.right.type===u.AST_NODE_TYPES.BinaryExpression&&E(f.right)};y(a.value,!0)}let T={size:P(a.range),dependencies:S,node:a,position:g,name:c};return o.at(-1).push(T),o},[[]]))(s.properties).forEach(e=>{D(e,(o,a)=>{let c;if(o.position==="exception"&&a.position==="exception")c=n["always-on-top"].indexOf(o.name)>n["always-on-top"].indexOf(a.name);else if(o.position===a.position)c=A(o,a,n);else{let g={exception:1,ignore:0};c=g[o.position]<g[a.position]}if(c){let g=S=>{let T=F(e,({position:m})=>m),y=m=>m in T?T[m]:[],f=[y("exception").sort((m,E)=>n["always-on-top"].indexOf(m.name)-n["always-on-top"].indexOf(E.name)),b(y("ignore"),n)].flat();return Y(S,e,f,p)};t.report({messageId:"unexpectedObjectsOrder",data:{left:O(o.name),right:O(a.name)},node:a.node,fix:g})}})})}};return{ObjectExpression:l,ObjectPattern:l}}}),K="sort-exports",he=N({name:K,meta:{type:"suggestion",docs:{description:"enforce sorted exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>{let l=w(t.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1}),s=[[]],n=p=>{p.type===u.AST_NODE_TYPES.ExportAllDeclaration&&p.exported===null?s.push([]):s.at(-1).push({size:P(p.range),name:p.source.value,node:p})};return{ExportAllDeclaration:n,ExportNamedDeclaration:p=>{p.source!==null&&n(p)},"Program:exit":()=>{let p=t.getSourceCode();s.forEach(r=>{D(r,(e,o)=>{A(e,o,l)&&t.report({messageId:"unexpectedExportsOrder",data:{left:e.name,right:o.name},node:o.node,fix:a=>Y(a,r,b(r,l),p)})})})}}}}),V="sort-enums",Te=N({name:V,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[d.asc,d.desc],default:d.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:t=>({TSEnumDeclaration:l=>{if(l.members.length>1&&l.members.some(({initializer:s})=>s)){let s=w(t.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1}),n=t.getSourceCode(),p=l.members.map(r=>({name:r.id.type===u.AST_NODE_TYPES.Literal?`${r.id.value}`:`${n.text.slice(...r.id.range)}`,size:P(r.range),node:r}));D(p,(r,e)=>{A(r,e,s)&&t.report({messageId:"unexpectedEnumsOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),xe="eslint-plugin-perfectionist";let R=t=>{let l={[W]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"newlines-between":"always","internal-pattern":["~/**"],"read-tsconfig":!1}],[X]:["error",{groups:["static-property","private-property","property","constructor","static-method","private-method","method","unknown"]}],[J]:["error",{"always-on-top":[],shorthand:"ignore",multiline:"first",callback:"ignore"}],[L]:["error",{"spread-last":!0}],[G]:["error",{"always-on-top":[]}],[M]:["error"],[$]:["error"],[B]:["error"],[U]:["error"],[z]:["error"],[q]:["error"],[K]:["error"],[V]:["error"]};return{rules:Object.fromEntries(Object.entries(l).map(([s,[n,p={}]])=>[`perfectionist/${s}`,[n,Object.assign(p,t)]])),plugins:["perfectionist"]}};const _e={rules:{[L]:ie,[X]:Ee,[V]:Te,[K]:he,[W]:ye,[q]:ge,[J]:me,[U]:fe,[$]:pe,[M]:ce,[B]:de,[G]:Se,[z]:ue},configs:{"recommended-alphabetical":R({type:i.alphabetical,order:d.asc,"ignore-case":!1}),"recommended-natural":R({type:i.natural,order:d.asc,"ignore-case":!1}),"recommended-line-length":R({type:i["line-length"],order:d.desc})},name:xe};module.exports=_e;
1
+ "use strict";var te=Object.defineProperty;var ae=(a,l,s)=>l in a?te(a,l,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[l]=s;var H=(a,l,s)=>(ae(a,typeof l!="symbol"?l+"":l,s),s);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),re=require("natural-compare-lite"),C=require("minimatch"),Q=require("is-core-module"),se=require("json5"),ne=require("path"),oe=require("fs");let N=v.ESLintUtils.RuleCreator(a=>`https://eslint-plugin-perfectionist.azat.io/rules/${a}`),O=a=>a.replaceAll(/\s\s+/g," ").trim(),P=a=>{let[l,s]=a;return s-l};var i=(a=>(a.alphabetical="alphabetical",a["line-length"]="line-length",a.natural="natural",a))(i||{}),d=(a=>(a.desc="desc",a.asc="asc",a))(d||{});let A=(a,l,s)=>{var e,o;if((e=l.dependencies)!=null&&e.includes(a.name))return!1;if((o=a.dependencies)!=null&&o.includes(l.name))return!0;let n=s.order==="asc"?1:-1,p,r=t=>s["ignore-case"]?t.toLowerCase():t;return s.type===i.alphabetical?p=(t,c)=>r(t.name).localeCompare(r(c.name)):s.type===i.natural?p=(t,c)=>re(r(t.name),r(c.name)):p=(t,c)=>t.size-c.size,n*p(a,l)>0},b=(a,l)=>[...a].sort((s,n)=>Number(A(s,n,l))||-1),le=(a,l)=>{let s=l.getTokenAfter(a,{filter:({type:n,value:p})=>!(n===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(p)),includeComments:!0});return((s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Line)&&a.loc.end.line===s.loc.end.line?s:null},Z=(a,l)=>{let[s,n]=l.getTokensBefore(a,{filter:({type:p,value:r})=>!(p===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(r)),includeComments:!0,count:2});return((n==null?void 0:n.type)===u.AST_TOKEN_TYPES.Block||(n==null?void 0:n.type)===u.AST_TOKEN_TYPES.Line)&&a.loc.start.line-n.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==n.loc.start.line?n:null},I=(a,l)=>{var e;let s=a.range.at(0),n=a.range.at(1),p=l.text.slice(s,n);if(v.ASTUtils.isParenthesized(a,l)){let o=l.getTokenBefore(a,v.ASTUtils.isOpeningParenToken),t=l.getTokenAfter(a,v.ASTUtils.isClosingParenToken);s=o.range.at(0),n=t.range.at(1)}let r=Z(a,l);if(p.endsWith(";")||p.endsWith(",")){let o=l.getTokensAfter(a,{includeComments:!0,count:2});a.loc.start.line===((e=o.at(1))==null?void 0:e.loc.start.line)&&(n-=1)}return r&&(s=r.range.at(0)),[s,n]},Y=(a,l,s,n)=>{let p=[];return l.forEach(({node:r},e)=>{p.push(a.replaceTextRange(I(r,n),n.text.slice(...I(s[e].node,n))));let o=le(s[e].node,n);if(o){let c=[n.getTokenBefore(o).range.at(1),o.range.at(1)];p.push(a.replaceTextRange(c,""));let g=n.getTokenAfter(r);p.push(a.insertTextAfter((g==null?void 0:g.loc.end.line)===r.loc.end.line?g:r,n.text.slice(...c)))}}),p},w=(a={},l)=>Object.assign(l,a),D=(a,l)=>{if(a.length>1)for(let s=1;s<a.length;s++){let n=a.at(s-1),p=a.at(s);n&&p&&l(n,p,s-1)}};const L="sort-array-includes",ie=N({name:L,meta:{type:"suggestion",docs:{description:"enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"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:d.asc}],create:a=>({MemberExpression:l=>{if((l.object.type===u.AST_NODE_TYPES.ArrayExpression||l.object.type===u.AST_NODE_TYPES.NewExpression)&&l.property.type===u.AST_NODE_TYPES.Identifier&&l.property.name==="includes"){let s=l.object.type===u.AST_NODE_TYPES.ArrayExpression?l.object.elements:l.object.arguments;if(s.length>1){let n=w(a.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1,"spread-last":!1}),p=a.getSourceCode(),r=s.reduce((e,o)=>(o!==null&&e.at(0).push({name:o.type===u.AST_NODE_TYPES.Literal?o.raw:p.text.slice(...o.range),size:P(o.range),type:o.type,node:o}),e),[[],[]]).flat();D(r,(e,o)=>{let t;n["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&o.node.type===u.AST_NODE_TYPES.SpreadElement?t=!1:n["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&o.node.type===u.AST_NODE_TYPES.Literal?t=!0:t=A(e,o,n),t&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{left:O(e.name),right:O(o.name)},node:o.node,fix:c=>{let g=b(r,n);return n["spread-last"]&&g.forEach((S,T)=>{S.node.type===u.AST_NODE_TYPES.SpreadElement&&g.push(g.splice(T,1).at(0))}),Y(c,r,g,p)}})})}}}})}),$="sort-named-exports",pe=N({name:$,meta:{type:"suggestion",docs:{description:"enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({ExportNamedDeclaration:l=>{if(l.specifiers.length>1){let s=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),n=a.getSourceCode(),p=l.specifiers.map(r=>({size:P(r.range),name:r.local.name,node:r}));D(p,(r,e)=>{A(r,e,s)&&a.report({messageId:"unexpectedNamedExportsOrder",data:{left:r.name,right:e.name},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),M="sort-named-imports",ce=N({name:M,meta:{type:"suggestion",docs:{description:"enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({ImportDeclaration:l=>{let s=l.specifiers.filter(({type:n})=>n===u.AST_NODE_TYPES.ImportSpecifier);if(s.length>1){let n=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=a.getSourceCode(),r=s.map(e=>({size:P(e.range),name:e.local.name,node:e}));D(r,(e,o)=>{A(e,o,n)&&a.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:o.name},node:o.node,fix:t=>Y(t,r,b(r,n),p)})})}}})}),B="sort-object-types",de=N({name:B,meta:{type:"suggestion",docs:{description:"enforce sorted object types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({TSTypeLiteral:l=>{if(l.members.length>1){let s=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),n=a.getSourceCode(),p=l.members.map(r=>{var S,T;let e,o=n.text.slice(r.range.at(0),r.range.at(1)),t=y=>y.replace(/(,|;)$/,"");if(r.type===u.AST_NODE_TYPES.TSPropertySignature)r.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=r.key:r.key.type===u.AST_NODE_TYPES.Literal?e=`${r.key.value}`:e=n.text.slice(r.range.at(0),(S=r.typeAnnotation)==null?void 0:S.range.at(0));else if(r.type===u.AST_NODE_TYPES.TSIndexSignature){let y=((T=r.typeAnnotation)==null?void 0:T.range.at(0))??r.range.at(1);e=t(n.text.slice(r.range.at(0),y))}else e=t(n.text.slice(r.range.at(0),r.range.at(1)));let g=o.endsWith(";")||o.endsWith(",")?1:0;return{size:P(r.range)-g,node:r,name:e}});D(p,(r,e)=>{A(r,e,s)&&a.report({messageId:"unexpectedObjectTypesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),U="sort-map-elements",fe=N({name:U,meta:{type:"suggestion",docs:{description:"enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({NewExpression:l=>{if(l.callee.type===u.AST_NODE_TYPES.Identifier&&l.callee.name==="Map"&&l.arguments.length&&l.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let[{elements:s}]=l.arguments;if(s.length>1){let n=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=a.getSourceCode();s.reduce((e,o)=>(o===null||o.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(o),e),[[]]).forEach(e=>{let o=e.map(t=>{let c;if(t.type===u.AST_NODE_TYPES.ArrayExpression){let[g]=t.elements;g?g.type===u.AST_NODE_TYPES.Literal?c=g.raw:c=p.text.slice(...g.range):c=`${g}`}else c=p.text.slice(...t.range);return{size:P(t.range),node:t,name:c}});D(o,(t,c)=>{A(t,c,n)&&a.report({messageId:"unexpectedMapElementsOrder",data:{left:O(t.name),right:O(c.name)},node:c.node,fix:g=>Y(g,o,b(o,n),p)})})})}}}})}),z="sort-union-types",ue=N({name:z,meta:{type:"suggestion",docs:{description:"enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({TSUnionType:l=>{let s=a.getSourceCode(),n=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=l.types.map(r=>({name:s.text.slice(...r.range),size:P(r.range),node:r}));D(p,(r,e)=>{A(r,e,n)&&a.report({messageId:"unexpectedUnionTypesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,n),s)})})}})}),q="sort-interfaces",ge=N({name:q,meta:{type:"suggestion",docs:{description:"enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},"ignore-pattern":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({TSInterfaceDeclaration:l=>{if(l.body.body.length>1){let s=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc,"ignore-pattern":[]});if(!s["ignore-pattern"].some(n=>C.minimatch(l.id.name,n))){let n=a.getSourceCode(),p=l.body.body.map(r=>{var o,t,c;let e;if(r.type===u.AST_NODE_TYPES.TSPropertySignature)if(r.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=r.key);else if(r.key.type===u.AST_NODE_TYPES.Literal)e=`${r.key.value}`;else{let g=((o=r.typeAnnotation)==null?void 0:o.range.at(0))??r.range.at(1)-(r.optional?1:0);e=n.text.slice(r.range.at(0),g)}else if(r.type===u.AST_NODE_TYPES.TSIndexSignature){let g=((t=r.typeAnnotation)==null?void 0:t.range.at(0))??r.range.at(1);e=n.text.slice(r.range.at(0),g)}else{let g=((c=r.returnType)==null?void 0:c.range.at(0))??r.range.at(1);e=n.text.slice(r.range.at(0),g)}return{size:P(r.range),node:r,name:e}});D(p,(r,e)=>{A(r,e,s)&&a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}}})});let F=(a,l)=>a.reduce((s,n)=>{let p=l(n);return p in s||(s[p]=[]),s[p].push(n),s},{});const J="sort-jsx-props",me=N({name:J,meta:{type:"suggestion",docs:{description:"enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"always-on-top":{type:"array",default:[]},"ignore-case":{type:"boolean",default:!1},shorthand:{enum:["first","last","ignore"]},callback:{enum:["first","last","ignore"]},multiline:{enum:["first","last","ignore"]}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({JSXElement:l=>{if(l.openingElement.attributes.length>1){let s=w(a.options.at(0),{type:i.alphabetical,shorthand:"ignore",multiline:"ignore",callback:"ignore","always-on-top":[],"ignore-case":!1,order:d.asc}),n=a.getSourceCode();l.openingElement.attributes.reduce((r,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return r.push([]),r;let o="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&s["always-on-top"].includes(e.name.name)?o="exception":(s.shorthand!=="ignore"&&e.value===null&&(o=s.shorthand),s.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?o=s.callback:s.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(o=s.multiline));let t={name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:P(e.range),node:e,position:o};return r.at(-1).push(t),r},[[]]).forEach(r=>{D(r,(e,o)=>{let t;if(e.position==="exception"&&o.position==="exception")t=s["always-on-top"].indexOf(e.name)>s["always-on-top"].indexOf(o.name);else if(e.position===o.position)t=A(e,o,s);else{let c={exception:2,first:1,ignore:0,last:-1};t=c[e.position]<c[o.position]}t&&a.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:o.name},node:o.node,fix:c=>{let g=F(r,({position:y})=>y),S=y=>y in g?g[y]:[],T=[S("exception").sort((y,f)=>s["always-on-top"].indexOf(y.name)-s["always-on-top"].indexOf(f.name)),b(S("first"),s),b(S("ignore"),s),b(S("last"),s)].flat();return Y(c,r,T,n)}})})})}}})});class ee{static get(){return this._instance?this._instance:(this._instance=se.parse(oe.readFileSync(ne.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}H(ee,"_instance");const W="sort-imports",ye=N({name:W,meta:{type:"suggestion",docs:{description:"enforce sorted imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},groups:{type:"array",default:[]},"internal-pattern":{type:"array",default:["~/**"]},"newlines-between":{enum:["ignore","always","never"],default:"always"},"read-tsconfig":{type:"boolean",default:!1}},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:d.asc}],create:a=>{var o;let l=w(a.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:i.alphabetical,"read-tsconfig":!1,order:d.asc,"ignore-case":!1,groups:[]}),s=[];if(l["read-tsconfig"]){let t=ee.get();(o=t.compilerOptions)!=null&&o.paths&&Object.keys(t.compilerOptions.paths).forEach(c=>{s.push(c)})}let n=a.getSourceCode(),p=[],r=t=>{let c,g=E=>[".less",".scss",".sass",".styl",".pcss",".css",".sss"].some(x=>E.endsWith(x)),S=E=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(E),T=E=>E.indexOf("..")===0,y=E=>E.indexOf("./")===0,f=E=>{!c&&l.groups.flat().includes(E)&&(c=E)},m=E=>l["internal-pattern"].length&&l["internal-pattern"].some(x=>C.minimatch(E.source.value,x))||s.some(x=>C.minimatch(E.source.value,x));return t.importKind==="type"&&(t.type===u.AST_NODE_TYPES.ImportDeclaration&&(Q(t.source.value)&&f("builtin-type"),m(t)&&f("internal-type"),S(t.source.value)&&f("index-type"),T(t.source.value)&&f("parent-type"),y(t.source.value)&&f("sibling-type")),f("type")),!c&&t.type===u.AST_NODE_TYPES.ImportDeclaration&&(Q(t.source.value)&&f("builtin"),m(t)&&f("internal"),g(t.source.value)&&f("style"),t.specifiers.length===0&&f("side-effect"),S(t.source.value)&&f("index"),T(t.source.value)&&f("parent"),y(t.source.value)&&f("sibling"),f("external")),c??"unknown"},e=t=>{let c;t.type===u.AST_NODE_TYPES.ImportDeclaration?c=t.source.value:t.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&t.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?c=`${t.moduleReference.expression.value}`:c=n.text.slice(...t.moduleReference.range),p.push({size:P(t.range),group:r(t),name:c,node:t})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let t=y=>{for(let f=0,m=l.groups.length;f<m;f++){let E=l.groups[f];if(y.group===E||Array.isArray(E)&&E.includes(y.group))return f}return l.groups.length},c=(y,f)=>!!n.getTokensBetween(y.node,Z(f.node,n)||f.node,{includeComments:!0}).length,g=(y,f)=>n.lines.slice(y.node.loc.end.line,f.node.loc.start.line-1).filter(E=>!E.trim().length).length,S=(y,f)=>{let m=[],E=f.reduce((_,h)=>{let j=t(h);return j in _?_[j]=b([..._[j],h],l):_[j]=[h],_},{}),x=Object.keys(E).sort().reduce((_,h)=>[..._,...E[h]],[]);return x.forEach((_,h)=>{if(m.push(y.replaceTextRange(I(f.at(h).node,n),n.text.slice(...I(_.node,n)))),l["newlines-between"]!=="ignore"){let j=x.at(h+1);if(j){let k=g(f.at(h),f.at(h+1));(l["newlines-between"]==="always"&&t(_)===t(j)&&k!==0||l["newlines-between"]==="never"&&k>0)&&m.push(y.removeRange([I(f.at(h).node,n).at(1),I(f.at(h+1).node,n).at(0)-1])),l["newlines-between"]==="always"&&t(_)!==t(j)&&k>1&&m.push(y.replaceTextRange([I(f.at(h).node,n).at(1),I(f.at(h+1).node,n).at(0)-1],`
2
+ `)),l["newlines-between"]==="always"&&t(_)!==t(j)&&k===0&&m.push(y.insertTextAfterRange(I(f.at(h).node,n),`
3
+ `))}}}),m};p.reduce((y,f)=>{var E;let m=(E=y.at(-1))==null?void 0:E.at(-1);return m&&c(m,f)?y.push([f]):y.at(-1).push(f),y},[[]]).forEach(y=>{D(y,(f,m)=>{let E=t(f),x=t(m),_=g(f,m);!c(f,m)&&(E>x||E===x&&A(f,m,l))&&a.report({messageId:"unexpectedImportsOrder",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}),l["newlines-between"]==="never"&&_>0&&a.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}),l["newlines-between"]==="always"&&(E<x&&_===0?a.report({messageId:"missedSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}):(_>1||E===x&&_>0)&&a.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,y)}))})})}}}}),X="sort-classes",Ee=N({name:X,meta:{type:"suggestion",docs:{description:"enforce sorted classes",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[d.asc,d.desc],default:d.asc},groups:{type:"array",default:["property","constructor","method","unknown"]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({ClassBody:l=>{if(l.body.length>1){let s=w(a.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),n=a.getSourceCode(),p=l.body.map(e=>{var g;let o,t;e.type===u.AST_NODE_TYPES.StaticBlock?t="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?t=n.text.slice(e.range.at(0),((g=e.typeAnnotation)==null?void 0:g.range.at(0))??e.range.at(1)):e.key.type===u.AST_NODE_TYPES.Identifier?{name:t}=e.key:t=n.text.slice(...e.key.range);let c=S=>{!o&&s.groups.flat().includes(S)&&(o=S)};return e.type===u.AST_NODE_TYPES.MethodDefinition?(e.kind==="constructor"&&c("constructor"),e.static&&c("static-method"),e.accessibility==="private"&&c("private-method"),c("method")):e.type===u.AST_NODE_TYPES.PropertyDefinition&&(e.static&&c("static-property"),e.accessibility==="private"&&c("private-property"),c("property")),{size:P(e.range),group:o??"unknown",node:e,name:t}}),r=e=>{for(let o=0,t=s.groups.length;o<t;o++){let c=s.groups[o];if(e.group===c||Array.isArray(c)&&c.includes(e.group))return o}return s.groups.length};D(p,(e,o)=>{let t=r(e),c=r(o);(t>c||t===c&&A(e,o,s))&&a.report({messageId:"unexpectedClassesOrder",data:{left:O(e.name),right:O(o.name)},node:o.node,fix:g=>{let S=[],T=p.reduce((f,m)=>{let E=r(m);return E in f?f[E]=b([...f[E],m],s):f[E]=[m],f},{});return Object.keys(T).sort().reduce((f,m)=>[...f,...T[m]],[]).forEach((f,m)=>{S.push(g.replaceTextRange(I(p.at(m).node,n),n.text.slice(...I(f.node,n))))}),S}})})}}})}),G="sort-objects",Se=N({name:G,meta:{type:"suggestion",docs:{description:"enforce sorted objects",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1},"always-on-top":{type:"array",default:[]}},additionalProperties:!1}],messages:{unexpectedObjectsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>{let l=s=>{if(s.properties.length>1){let n=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc,"always-on-top":[]}),p=a.getSourceCode();(e=>e.reduce((o,t)=>{if(t.type===u.AST_NODE_TYPES.SpreadElement||t.type===u.AST_NODE_TYPES.RestElement)return o.push([]),o;let c,g="ignore",S=[];if(t.key.type===u.AST_NODE_TYPES.Identifier?{name:c}=t.key:t.key.type===u.AST_NODE_TYPES.Literal?c=`${t.key.value}`:c=p.text.slice(...t.key.range),t.key.type===u.AST_NODE_TYPES.Identifier&&n["always-on-top"].includes(t.key.name)&&(g="exception"),t.value.type===u.AST_NODE_TYPES.AssignmentPattern){let y=(f,m)=>{f.right.type===u.AST_NODE_TYPES.Identifier&&S.push(f.right.name),!m&&f.left.type===u.AST_NODE_TYPES.Identifier&&S.push(f.left.name);let E=x=>{x.right.type===u.AST_NODE_TYPES.Identifier&&S.push(x.right.name),x.left.type===u.AST_NODE_TYPES.BinaryExpression&&y(x.left,!1)};f.right.type===u.AST_NODE_TYPES.BinaryExpression&&E(f.right)};y(t.value,!0)}let T={size:P(t.range),dependencies:S,node:t,position:g,name:c};return o.at(-1).push(T),o},[[]]))(s.properties).forEach(e=>{D(e,(o,t)=>{let c;if(o.position==="exception"&&t.position==="exception")c=n["always-on-top"].indexOf(o.name)>n["always-on-top"].indexOf(t.name);else if(o.position===t.position)c=A(o,t,n);else{let g={exception:1,ignore:0};c=g[o.position]<g[t.position]}if(c){let g=S=>{let T=F(e,({position:m})=>m),y=m=>m in T?T[m]:[],f=[y("exception").sort((m,E)=>n["always-on-top"].indexOf(m.name)-n["always-on-top"].indexOf(E.name)),b(y("ignore"),n)].flat();return Y(S,e,f,p)};a.report({messageId:"unexpectedObjectsOrder",data:{left:O(o.name),right:O(t.name)},node:t.node,fix:g})}})})}};return{ObjectExpression:l,ObjectPattern:l}}}),K="sort-exports",he=N({name:K,meta:{type:"suggestion",docs:{description:"enforce sorted exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},order:{enum:[d.asc,d.desc],default:d.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>{let l=w(a.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1}),s=[[]],n=p=>{p.type===u.AST_NODE_TYPES.ExportAllDeclaration&&p.exported===null?s.push([]):s.at(-1).push({size:P(p.range),name:p.source.value,node:p})};return{ExportAllDeclaration:n,ExportNamedDeclaration:p=>{p.source!==null&&n(p)},"Program:exit":()=>{let p=a.getSourceCode();s.forEach(r=>{D(r,(e,o)=>{A(e,o,l)&&a.report({messageId:"unexpectedExportsOrder",data:{left:e.name,right:o.name},node:o.node,fix:t=>Y(t,r,b(r,l),p)})})})}}}}),V="sort-enums",Te=N({name:V,meta:{type:"suggestion",docs:{description:"enforce sorted TypeScript enums",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[i.alphabetical,i.natural,i["line-length"]],default:i.natural},"ignore-case":{type:"boolean",default:!1},order:{enum:[d.asc,d.desc],default:d.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:d.asc}],create:a=>({TSEnumDeclaration:l=>{if(l.members.length>1&&l.members.some(({initializer:s})=>s)){let s=w(a.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1}),n=a.getSourceCode(),p=l.members.map(r=>({name:r.id.type===u.AST_NODE_TYPES.Literal?`${r.id.value}`:`${n.text.slice(...r.id.range)}`,size:P(r.range),node:r}));D(p,(r,e)=>{A(r,e,s)&&a.report({messageId:"unexpectedEnumsOrder",data:{left:O(r.name),right:O(e.name)},node:e.node,fix:o=>Y(o,p,b(p,s),n)})})}}})}),xe="eslint-plugin-perfectionist";let R=a=>{let l={[W]:["error",{groups:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"newlines-between":"always","internal-pattern":["~/**"],"read-tsconfig":!1}],[X]:["error",{groups:["static-property","private-property","property","constructor","static-method","private-method","method","unknown"]}],[J]:["error",{"always-on-top":[],shorthand:"ignore",multiline:"first",callback:"ignore"}],[L]:["error",{"spread-last":!0}],[G]:["error",{"always-on-top":[]}],[M]:["error"],[$]:["error"],[B]:["error"],[U]:["error"],[z]:["error"],[q]:["error"],[K]:["error"],[V]:["error"]};return{rules:Object.fromEntries(Object.entries(l).map(([s,[n,p={}]])=>[`perfectionist/${s}`,[n,Object.assign(p,a)]])),plugins:["perfectionist"]}};const _e={rules:{[L]:ie,[X]:Ee,[V]:Te,[K]:he,[W]:ye,[q]:ge,[J]:me,[U]:fe,[$]:pe,[M]:ce,[B]:de,[G]:Se,[z]:ue},configs:{"recommended-alphabetical":R({type:i.alphabetical,order:d.asc,"ignore-case":!1}),"recommended-natural":R({type:i.natural,order:d.asc,"ignore-case":!1}),"recommended-line-length":R({type:i["line-length"],order:d.desc})},name:xe};module.exports=_e;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  var ae = Object.defineProperty;
2
- var re = (t, l, s) => l in t ? ae(t, l, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[l] = s;
3
- var Q = (t, l, s) => (re(t, typeof l != "symbol" ? l + "" : l, s), s);
2
+ var re = (a, l, s) => l in a ? ae(a, l, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[l] = s;
3
+ var Q = (a, l, s) => (re(a, typeof l != "symbol" ? l + "" : l, s), s);
4
4
  import { AST_TOKEN_TYPES as C, AST_NODE_TYPES as u } from "@typescript-eslint/types";
5
5
  import { ESLintUtils as se, ASTUtils as $ } from "@typescript-eslint/utils";
6
6
  import ne from "natural-compare-lite";
@@ -10,60 +10,60 @@ import oe from "json5";
10
10
  import le from "path";
11
11
  import ie from "fs";
12
12
  let A = se.RuleCreator(
13
- (t) => `https://eslint-plugin-perfectionist.azat.io/rules/${t}`
14
- ), I = (t) => t.replaceAll(/\s\s+/g, " ").trim(), N = (t) => {
15
- let [l, s] = t;
13
+ (a) => `https://eslint-plugin-perfectionist.azat.io/rules/${a}`
14
+ ), I = (a) => a.replaceAll(/\s\s+/g, " ").trim(), N = (a) => {
15
+ let [l, s] = a;
16
16
  return s - l;
17
17
  };
18
- var i = /* @__PURE__ */ ((t) => (t.alphabetical = "alphabetical", t["line-length"] = "line-length", t.natural = "natural", t))(i || {}), d = /* @__PURE__ */ ((t) => (t.desc = "desc", t.asc = "asc", t))(d || {});
19
- let j = (t, l, s) => {
18
+ var i = /* @__PURE__ */ ((a) => (a.alphabetical = "alphabetical", a["line-length"] = "line-length", a.natural = "natural", a))(i || {}), d = /* @__PURE__ */ ((a) => (a.desc = "desc", a.asc = "asc", a))(d || {});
19
+ let j = (a, l, s) => {
20
20
  var e, o;
21
- if ((e = l.dependencies) != null && e.includes(t.name))
21
+ if ((e = l.dependencies) != null && e.includes(a.name))
22
22
  return !1;
23
- if ((o = t.dependencies) != null && o.includes(l.name))
23
+ if ((o = a.dependencies) != null && o.includes(l.name))
24
24
  return !0;
25
- let n = s.order === "asc" ? 1 : -1, p, r = (a) => s["ignore-case"] ? a.toLowerCase() : a;
26
- return s.type === i.alphabetical ? p = (a, c) => r(a.name).localeCompare(r(c.name)) : s.type === i.natural ? p = (a, c) => ne(r(a.name), r(c.name)) : p = (a, c) => a.size - c.size, n * p(t, l) > 0;
27
- }, S = (t, l) => [...t].sort((s, n) => Number(j(s, n, l)) || -1), pe = (t, l) => {
28
- let s = l.getTokenAfter(t, {
25
+ let n = s.order === "asc" ? 1 : -1, p, r = (t) => s["ignore-case"] ? t.toLowerCase() : t;
26
+ return s.type === i.alphabetical ? p = (t, c) => r(t.name).localeCompare(r(c.name)) : s.type === i.natural ? p = (t, c) => ne(r(t.name), r(c.name)) : p = (t, c) => t.size - c.size, n * p(a, l) > 0;
27
+ }, S = (a, l) => [...a].sort((s, n) => Number(j(s, n, l)) || -1), pe = (a, l) => {
28
+ let s = l.getTokenAfter(a, {
29
29
  filter: ({ type: n, value: p }) => !(n === C.Punctuator && [",", ";"].includes(p)),
30
30
  includeComments: !0
31
31
  });
32
- return ((s == null ? void 0 : s.type) === C.Block || (s == null ? void 0 : s.type) === C.Line) && t.loc.end.line === s.loc.end.line ? s : null;
33
- }, F = (t, l) => {
34
- let [s, n] = l.getTokensBefore(t, {
32
+ return ((s == null ? void 0 : s.type) === C.Block || (s == null ? void 0 : s.type) === C.Line) && a.loc.end.line === s.loc.end.line ? s : null;
33
+ }, F = (a, l) => {
34
+ let [s, n] = l.getTokensBefore(a, {
35
35
  filter: ({ type: p, value: r }) => !(p === C.Punctuator && [",", ";"].includes(r)),
36
36
  includeComments: !0,
37
37
  count: 2
38
38
  });
39
- return ((n == null ? void 0 : n.type) === C.Block || (n == null ? void 0 : n.type) === C.Line) && t.loc.start.line - n.loc.end.line <= 1 && (s == null ? void 0 : s.loc.end.line) !== n.loc.start.line ? n : null;
40
- }, T = (t, l) => {
39
+ return ((n == null ? void 0 : n.type) === C.Block || (n == null ? void 0 : n.type) === C.Line) && a.loc.start.line - n.loc.end.line <= 1 && (s == null ? void 0 : s.loc.end.line) !== n.loc.start.line ? n : null;
40
+ }, T = (a, l) => {
41
41
  var e;
42
- let s = t.range.at(0), n = t.range.at(1), p = l.text.slice(s, n);
43
- if ($.isParenthesized(t, l)) {
42
+ let s = a.range.at(0), n = a.range.at(1), p = l.text.slice(s, n);
43
+ if ($.isParenthesized(a, l)) {
44
44
  let o = l.getTokenBefore(
45
- t,
45
+ a,
46
46
  $.isOpeningParenToken
47
- ), a = l.getTokenAfter(
48
- t,
47
+ ), t = l.getTokenAfter(
48
+ a,
49
49
  $.isClosingParenToken
50
50
  );
51
- s = o.range.at(0), n = a.range.at(1);
51
+ s = o.range.at(0), n = t.range.at(1);
52
52
  }
53
- let r = F(t, l);
53
+ let r = F(a, l);
54
54
  if (p.endsWith(";") || p.endsWith(",")) {
55
- let o = l.getTokensAfter(t, {
55
+ let o = l.getTokensAfter(a, {
56
56
  includeComments: !0,
57
57
  count: 2
58
58
  });
59
- t.loc.start.line === ((e = o.at(1)) == null ? void 0 : e.loc.start.line) && (n -= 1);
59
+ a.loc.start.line === ((e = o.at(1)) == null ? void 0 : e.loc.start.line) && (n -= 1);
60
60
  }
61
61
  return r && (s = r.range.at(0)), [s, n];
62
- }, v = (t, l, s, n) => {
62
+ }, v = (a, l, s, n) => {
63
63
  let p = [];
64
64
  return l.forEach(({ node: r }, e) => {
65
65
  p.push(
66
- t.replaceTextRange(
66
+ a.replaceTextRange(
67
67
  T(r, n),
68
68
  n.text.slice(...T(s[e].node, n))
69
69
  )
@@ -74,20 +74,20 @@ let j = (t, l, s) => {
74
74
  n.getTokenBefore(o).range.at(1),
75
75
  o.range.at(1)
76
76
  ];
77
- p.push(t.replaceTextRange(c, ""));
77
+ p.push(a.replaceTextRange(c, ""));
78
78
  let g = n.getTokenAfter(r);
79
79
  p.push(
80
- t.insertTextAfter(
80
+ a.insertTextAfter(
81
81
  (g == null ? void 0 : g.loc.end.line) === r.loc.end.line ? g : r,
82
82
  n.text.slice(...c)
83
83
  )
84
84
  );
85
85
  }
86
86
  }), p;
87
- }, k = (t = {}, l) => Object.assign(l, t), P = (t, l) => {
88
- if (t.length > 1)
89
- for (let s = 1; s < t.length; s++) {
90
- let n = t.at(s - 1), p = t.at(s);
87
+ }, k = (a = {}, l) => Object.assign(l, a), P = (a, l) => {
88
+ if (a.length > 1)
89
+ for (let s = 1; s < a.length; s++) {
90
+ let n = a.at(s - 1), p = a.at(s);
91
91
  n && p && l(n, p, s - 1);
92
92
  }
93
93
  };
@@ -138,17 +138,17 @@ const _ = "sort-array-includes", ce = A({
138
138
  order: d.asc
139
139
  }
140
140
  ],
141
- create: (t) => ({
141
+ create: (a) => ({
142
142
  MemberExpression: (l) => {
143
143
  if ((l.object.type === u.ArrayExpression || l.object.type === u.NewExpression) && l.property.type === u.Identifier && l.property.name === "includes") {
144
144
  let s = l.object.type === u.ArrayExpression ? l.object.elements : l.object.arguments;
145
145
  if (s.length > 1) {
146
- let n = k(t.options.at(0), {
146
+ let n = k(a.options.at(0), {
147
147
  type: i.alphabetical,
148
148
  order: d.asc,
149
149
  "ignore-case": !1,
150
150
  "spread-last": !1
151
- }), p = t.getSourceCode(), r = s.reduce(
151
+ }), p = a.getSourceCode(), r = s.reduce(
152
152
  (e, o) => (o !== null && e.at(0).push({
153
153
  name: o.type === u.Literal ? o.raw : p.text.slice(...o.range),
154
154
  size: N(o.range),
@@ -158,8 +158,8 @@ const _ = "sort-array-includes", ce = A({
158
158
  [[], []]
159
159
  ).flat();
160
160
  P(r, (e, o) => {
161
- let a;
162
- n["spread-last"] && e.node.type === u.Literal && o.node.type === u.SpreadElement ? a = !1 : n["spread-last"] && e.node.type === u.SpreadElement && o.node.type === u.Literal ? a = !0 : a = j(e, o, n), a && t.report({
161
+ let t;
162
+ n["spread-last"] && e.node.type === u.Literal && o.node.type === u.SpreadElement ? t = !1 : n["spread-last"] && e.node.type === u.SpreadElement && o.node.type === u.Literal ? t = !0 : t = j(e, o, n), t && a.report({
163
163
  messageId: "unexpectedArrayIncludesOrder",
164
164
  data: {
165
165
  left: I(e.name),
@@ -221,20 +221,20 @@ const _ = "sort-array-includes", ce = A({
221
221
  order: d.asc
222
222
  }
223
223
  ],
224
- create: (t) => ({
224
+ create: (a) => ({
225
225
  ExportNamedDeclaration: (l) => {
226
226
  if (l.specifiers.length > 1) {
227
- let s = k(t.options.at(0), {
227
+ let s = k(a.options.at(0), {
228
228
  type: i.alphabetical,
229
229
  "ignore-case": !1,
230
230
  order: d.asc
231
- }), n = t.getSourceCode(), p = l.specifiers.map((r) => ({
231
+ }), n = a.getSourceCode(), p = l.specifiers.map((r) => ({
232
232
  size: N(r.range),
233
233
  name: r.local.name,
234
234
  node: r
235
235
  }));
236
236
  P(p, (r, e) => {
237
- j(r, e, s) && t.report({
237
+ j(r, e, s) && a.report({
238
238
  messageId: "unexpectedNamedExportsOrder",
239
239
  data: {
240
240
  left: r.name,
@@ -290,30 +290,30 @@ const _ = "sort-array-includes", ce = A({
290
290
  order: d.asc
291
291
  }
292
292
  ],
293
- create: (t) => ({
293
+ create: (a) => ({
294
294
  ImportDeclaration: (l) => {
295
295
  let s = l.specifiers.filter(
296
296
  ({ type: n }) => n === u.ImportSpecifier
297
297
  );
298
298
  if (s.length > 1) {
299
- let n = k(t.options.at(0), {
299
+ let n = k(a.options.at(0), {
300
300
  type: i.alphabetical,
301
301
  "ignore-case": !1,
302
302
  order: d.asc
303
- }), p = t.getSourceCode(), r = s.map((e) => ({
303
+ }), p = a.getSourceCode(), r = s.map((e) => ({
304
304
  size: N(e.range),
305
305
  name: e.local.name,
306
306
  node: e
307
307
  }));
308
308
  P(r, (e, o) => {
309
- j(e, o, n) && t.report({
309
+ j(e, o, n) && a.report({
310
310
  messageId: "unexpectedNamedImportsOrder",
311
311
  data: {
312
312
  left: e.name,
313
313
  right: o.name
314
314
  },
315
315
  node: o.node,
316
- fix: (a) => v(a, r, S(r, n), p)
316
+ fix: (t) => v(t, r, S(r, n), p)
317
317
  });
318
318
  });
319
319
  }
@@ -362,16 +362,16 @@ const _ = "sort-array-includes", ce = A({
362
362
  order: d.asc
363
363
  }
364
364
  ],
365
- create: (t) => ({
365
+ create: (a) => ({
366
366
  TSTypeLiteral: (l) => {
367
367
  if (l.members.length > 1) {
368
- let s = k(t.options.at(0), {
368
+ let s = k(a.options.at(0), {
369
369
  type: i.alphabetical,
370
370
  "ignore-case": !1,
371
371
  order: d.asc
372
- }), n = t.getSourceCode(), p = l.members.map((r) => {
372
+ }), n = a.getSourceCode(), p = l.members.map((r) => {
373
373
  var x, E;
374
- let e, o = n.text.slice(r.range.at(0), r.range.at(1)), a = (y) => y.replace(/(,|;)$/, "");
374
+ let e, o = n.text.slice(r.range.at(0), r.range.at(1)), t = (y) => y.replace(/(,|;)$/, "");
375
375
  if (r.type === u.TSPropertySignature)
376
376
  r.key.type === u.Identifier ? { name: e } = r.key : r.key.type === u.Literal ? e = `${r.key.value}` : e = n.text.slice(
377
377
  r.range.at(0),
@@ -379,9 +379,9 @@ const _ = "sort-array-includes", ce = A({
379
379
  );
380
380
  else if (r.type === u.TSIndexSignature) {
381
381
  let y = ((E = r.typeAnnotation) == null ? void 0 : E.range.at(0)) ?? r.range.at(1);
382
- e = a(n.text.slice(r.range.at(0), y));
382
+ e = t(n.text.slice(r.range.at(0), y));
383
383
  } else
384
- e = a(
384
+ e = t(
385
385
  n.text.slice(r.range.at(0), r.range.at(1))
386
386
  );
387
387
  let g = o.endsWith(";") || o.endsWith(",") ? 1 : 0;
@@ -392,7 +392,7 @@ const _ = "sort-array-includes", ce = A({
392
392
  };
393
393
  });
394
394
  P(p, (r, e) => {
395
- j(r, e, s) && t.report({
395
+ j(r, e, s) && a.report({
396
396
  messageId: "unexpectedObjectTypesOrder",
397
397
  data: {
398
398
  left: I(r.name),
@@ -448,38 +448,38 @@ const _ = "sort-array-includes", ce = A({
448
448
  order: d.asc
449
449
  }
450
450
  ],
451
- create: (t) => ({
451
+ create: (a) => ({
452
452
  NewExpression: (l) => {
453
453
  if (l.callee.type === u.Identifier && l.callee.name === "Map" && l.arguments.length && l.arguments[0].type === u.ArrayExpression) {
454
454
  let [{ elements: s }] = l.arguments;
455
455
  if (s.length > 1) {
456
- let n = k(t.options.at(0), {
456
+ let n = k(a.options.at(0), {
457
457
  type: i.alphabetical,
458
458
  "ignore-case": !1,
459
459
  order: d.asc
460
- }), p = t.getSourceCode();
460
+ }), p = a.getSourceCode();
461
461
  s.reduce(
462
462
  (e, o) => (o === null || o.type === u.SpreadElement ? e.push([]) : e.at(-1).push(o), e),
463
463
  [[]]
464
464
  ).forEach((e) => {
465
- let o = e.map((a) => {
465
+ let o = e.map((t) => {
466
466
  let c;
467
- if (a.type === u.ArrayExpression) {
468
- let [g] = a.elements;
467
+ if (t.type === u.ArrayExpression) {
468
+ let [g] = t.elements;
469
469
  g ? g.type === u.Literal ? c = g.raw : c = p.text.slice(...g.range) : c = `${g}`;
470
470
  } else
471
- c = p.text.slice(...a.range);
471
+ c = p.text.slice(...t.range);
472
472
  return {
473
- size: N(a.range),
474
- node: a,
473
+ size: N(t.range),
474
+ node: t,
475
475
  name: c
476
476
  };
477
477
  });
478
- P(o, (a, c) => {
479
- j(a, c, n) && t.report({
478
+ P(o, (t, c) => {
479
+ j(t, c, n) && a.report({
480
480
  messageId: "unexpectedMapElementsOrder",
481
481
  data: {
482
- left: I(a.name),
482
+ left: I(t.name),
483
483
  right: I(c.name)
484
484
  },
485
485
  node: c.node,
@@ -534,9 +534,9 @@ const _ = "sort-array-includes", ce = A({
534
534
  order: d.asc
535
535
  }
536
536
  ],
537
- create: (t) => ({
537
+ create: (a) => ({
538
538
  TSUnionType: (l) => {
539
- let s = t.getSourceCode(), n = k(t.options.at(0), {
539
+ let s = a.getSourceCode(), n = k(a.options.at(0), {
540
540
  type: i.alphabetical,
541
541
  "ignore-case": !1,
542
542
  order: d.asc
@@ -546,7 +546,7 @@ const _ = "sort-array-includes", ce = A({
546
546
  node: r
547
547
  }));
548
548
  P(p, (r, e) => {
549
- j(r, e, n) && t.report({
549
+ j(r, e, n) && a.report({
550
550
  messageId: "unexpectedUnionTypesOrder",
551
551
  data: {
552
552
  left: I(r.name),
@@ -605,10 +605,10 @@ const _ = "sort-array-includes", ce = A({
605
605
  order: d.asc
606
606
  }
607
607
  ],
608
- create: (t) => ({
608
+ create: (a) => ({
609
609
  TSInterfaceDeclaration: (l) => {
610
610
  if (l.body.body.length > 1) {
611
- let s = k(t.options.at(0), {
611
+ let s = k(a.options.at(0), {
612
612
  type: i.alphabetical,
613
613
  "ignore-case": !1,
614
614
  order: d.asc,
@@ -617,8 +617,8 @@ const _ = "sort-array-includes", ce = A({
617
617
  if (!s["ignore-pattern"].some(
618
618
  (n) => B(l.id.name, n)
619
619
  )) {
620
- let n = t.getSourceCode(), p = l.body.body.map((r) => {
621
- var o, a, c;
620
+ let n = a.getSourceCode(), p = l.body.body.map((r) => {
621
+ var o, t, c;
622
622
  let e;
623
623
  if (r.type === u.TSPropertySignature)
624
624
  if (r.key.type === u.Identifier)
@@ -630,7 +630,7 @@ const _ = "sort-array-includes", ce = A({
630
630
  e = n.text.slice(r.range.at(0), g);
631
631
  }
632
632
  else if (r.type === u.TSIndexSignature) {
633
- let g = ((a = r.typeAnnotation) == null ? void 0 : a.range.at(0)) ?? r.range.at(1);
633
+ let g = ((t = r.typeAnnotation) == null ? void 0 : t.range.at(0)) ?? r.range.at(1);
634
634
  e = n.text.slice(r.range.at(0), g);
635
635
  } else {
636
636
  let g = ((c = r.returnType) == null ? void 0 : c.range.at(0)) ?? r.range.at(1);
@@ -643,7 +643,7 @@ const _ = "sort-array-includes", ce = A({
643
643
  };
644
644
  });
645
645
  P(p, (r, e) => {
646
- j(r, e, s) && t.report({
646
+ j(r, e, s) && a.report({
647
647
  messageId: "unexpectedInterfacePropertiesOrder",
648
648
  data: {
649
649
  left: I(r.name),
@@ -658,7 +658,7 @@ const _ = "sort-array-includes", ce = A({
658
658
  }
659
659
  })
660
660
  });
661
- let ee = (t, l) => t.reduce((s, n) => {
661
+ let ee = (a, l) => a.reduce((s, n) => {
662
662
  let p = l(n);
663
663
  return p in s || (s[p] = []), s[p].push(n), s;
664
664
  }, {});
@@ -733,10 +733,10 @@ const G = "sort-jsx-props", he = A({
733
733
  order: d.asc
734
734
  }
735
735
  ],
736
- create: (t) => ({
736
+ create: (a) => ({
737
737
  JSXElement: (l) => {
738
738
  if (l.openingElement.attributes.length > 1) {
739
- let s = k(t.options.at(0), {
739
+ let s = k(a.options.at(0), {
740
740
  type: i.alphabetical,
741
741
  shorthand: "ignore",
742
742
  multiline: "ignore",
@@ -744,29 +744,29 @@ const G = "sort-jsx-props", he = A({
744
744
  "always-on-top": [],
745
745
  "ignore-case": !1,
746
746
  order: d.asc
747
- }), n = t.getSourceCode();
747
+ }), n = a.getSourceCode();
748
748
  l.openingElement.attributes.reduce(
749
749
  (r, e) => {
750
750
  if (e.type === u.JSXSpreadAttribute)
751
751
  return r.push([]), r;
752
752
  let o = "ignore";
753
753
  e.name.type === u.JSXIdentifier && s["always-on-top"].includes(e.name.name) ? o = "exception" : (s.shorthand !== "ignore" && e.value === null && (o = s.shorthand), s.callback !== "ignore" && e.name.type === u.JSXIdentifier && e.name.name.indexOf("on") === 0 && e.value !== null ? o = s.callback : s.multiline !== "ignore" && e.loc.start.line !== e.loc.end.line && (o = s.multiline));
754
- let a = {
754
+ let t = {
755
755
  name: e.name.type === u.JSXNamespacedName ? `${e.name.namespace.name}:${e.name.name.name}` : e.name.name,
756
756
  size: N(e.range),
757
757
  node: e,
758
758
  position: o
759
759
  };
760
- return r.at(-1).push(a), r;
760
+ return r.at(-1).push(t), r;
761
761
  },
762
762
  [[]]
763
763
  ).forEach((r) => {
764
764
  P(r, (e, o) => {
765
- let a;
765
+ let t;
766
766
  if (e.position === "exception" && o.position === "exception")
767
- a = s["always-on-top"].indexOf(e.name) > s["always-on-top"].indexOf(o.name);
767
+ t = s["always-on-top"].indexOf(e.name) > s["always-on-top"].indexOf(o.name);
768
768
  else if (e.position === o.position)
769
- a = j(e, o, s);
769
+ t = j(e, o, s);
770
770
  else {
771
771
  let c = {
772
772
  exception: 2,
@@ -774,9 +774,9 @@ const G = "sort-jsx-props", he = A({
774
774
  ignore: 0,
775
775
  last: -1
776
776
  };
777
- a = c[e.position] < c[o.position];
777
+ t = c[e.position] < c[o.position];
778
778
  }
779
- a && t.report({
779
+ t && a.report({
780
780
  messageId: "unexpectedJSXPropsOrder",
781
781
  data: {
782
782
  left: e.name,
@@ -888,9 +888,9 @@ const K = "sort-imports", xe = A({
888
888
  order: d.asc
889
889
  }
890
890
  ],
891
- create: (t) => {
891
+ create: (a) => {
892
892
  var o;
893
- let l = k(t.options.at(0), {
893
+ let l = k(a.options.at(0), {
894
894
  "newlines-between": "always",
895
895
  "internal-pattern": ["~/**"],
896
896
  type: i.alphabetical,
@@ -900,12 +900,12 @@ const K = "sort-imports", xe = A({
900
900
  groups: []
901
901
  }), s = [];
902
902
  if (l["read-tsconfig"]) {
903
- let a = te.get();
904
- (o = a.compilerOptions) != null && o.paths && Object.keys(a.compilerOptions.paths).forEach((c) => {
903
+ let t = te.get();
904
+ (o = t.compilerOptions) != null && o.paths && Object.keys(t.compilerOptions.paths).forEach((c) => {
905
905
  s.push(c);
906
906
  });
907
907
  }
908
- let n = t.getSourceCode(), p = [], r = (a) => {
908
+ let n = a.getSourceCode(), p = [], r = (t) => {
909
909
  let c, g = (h) => [".less", ".scss", ".sass", ".styl", ".pcss", ".css", ".sss"].some(
910
910
  (w) => h.endsWith(w)
911
911
  ), x = (h) => [
@@ -921,21 +921,21 @@ const K = "sort-imports", xe = A({
921
921
  }, m = (h) => l["internal-pattern"].length && l["internal-pattern"].some(
922
922
  (w) => B(h.source.value, w)
923
923
  ) || s.some((w) => B(h.source.value, w));
924
- return a.importKind === "type" && (a.type === u.ImportDeclaration && (Z(a.source.value) && f("builtin-type"), m(a) && f("internal-type"), x(a.source.value) && f("index-type"), E(a.source.value) && f("parent-type"), y(a.source.value) && f("sibling-type")), f("type")), !c && a.type === u.ImportDeclaration && (Z(a.source.value) && f("builtin"), m(a) && f("internal"), g(a.source.value) && f("style"), a.specifiers.length === 0 && f("side-effect"), x(a.source.value) && f("index"), E(a.source.value) && f("parent"), y(a.source.value) && f("sibling"), f("external")), c ?? "unknown";
925
- }, e = (a) => {
924
+ return t.importKind === "type" && (t.type === u.ImportDeclaration && (Z(t.source.value) && f("builtin-type"), m(t) && f("internal-type"), x(t.source.value) && f("index-type"), E(t.source.value) && f("parent-type"), y(t.source.value) && f("sibling-type")), f("type")), !c && t.type === u.ImportDeclaration && (Z(t.source.value) && f("builtin"), m(t) && f("internal"), g(t.source.value) && f("style"), t.specifiers.length === 0 && f("side-effect"), x(t.source.value) && f("index"), E(t.source.value) && f("parent"), y(t.source.value) && f("sibling"), f("external")), c ?? "unknown";
925
+ }, e = (t) => {
926
926
  let c;
927
- a.type === u.ImportDeclaration ? c = a.source.value : a.moduleReference.type === u.TSExternalModuleReference && a.moduleReference.expression.type === u.Literal ? c = `${a.moduleReference.expression.value}` : c = n.text.slice(...a.moduleReference.range), p.push({
928
- size: N(a.range),
929
- group: r(a),
927
+ t.type === u.ImportDeclaration ? c = t.source.value : t.moduleReference.type === u.TSExternalModuleReference && t.moduleReference.expression.type === u.Literal ? c = `${t.moduleReference.expression.value}` : c = n.text.slice(...t.moduleReference.range), p.push({
928
+ size: N(t.range),
929
+ group: r(t),
930
930
  name: c,
931
- node: a
931
+ node: t
932
932
  });
933
933
  };
934
934
  return {
935
935
  TSImportEqualsDeclaration: e,
936
936
  ImportDeclaration: e,
937
937
  "Program:exit": () => {
938
- let a = (y) => {
938
+ let t = (y) => {
939
939
  for (let f = 0, m = l.groups.length; f < m; f++) {
940
940
  let h = l.groups[f];
941
941
  if (y.group === h || Array.isArray(h) && h.includes(y.group))
@@ -954,7 +954,7 @@ const K = "sort-imports", xe = A({
954
954
  ).filter((h) => !h.trim().length).length, x = (y, f) => {
955
955
  let m = [], h = f.reduce(
956
956
  (O, b) => {
957
- let R = a(b);
957
+ let R = t(b);
958
958
  return R in O ? O[R] = S(
959
959
  [...O[R], b],
960
960
  l
@@ -981,12 +981,12 @@ const K = "sort-imports", xe = A({
981
981
  f.at(b),
982
982
  f.at(b + 1)
983
983
  );
984
- (l["newlines-between"] === "always" && a(O) === a(R) && L !== 0 || l["newlines-between"] === "never" && L > 0) && m.push(
984
+ (l["newlines-between"] === "always" && t(O) === t(R) && L !== 0 || l["newlines-between"] === "never" && L > 0) && m.push(
985
985
  y.removeRange([
986
986
  T(f.at(b).node, n).at(1),
987
987
  T(f.at(b + 1).node, n).at(0) - 1
988
988
  ])
989
- ), l["newlines-between"] === "always" && L > 1 && m.push(
989
+ ), l["newlines-between"] === "always" && t(O) !== t(R) && L > 1 && m.push(
990
990
  y.replaceTextRange(
991
991
  [
992
992
  T(f.at(b).node, n).at(1),
@@ -997,7 +997,7 @@ const K = "sort-imports", xe = A({
997
997
  `
998
998
  `
999
999
  )
1000
- ), l["newlines-between"] === "always" && a(O) !== a(R) && L === 0 && m.push(
1000
+ ), l["newlines-between"] === "always" && t(O) !== t(R) && L === 0 && m.push(
1001
1001
  y.insertTextAfterRange(
1002
1002
  T(f.at(b).node, n),
1003
1003
  `
@@ -1017,8 +1017,8 @@ const K = "sort-imports", xe = A({
1017
1017
  [[]]
1018
1018
  ).forEach((y) => {
1019
1019
  P(y, (f, m) => {
1020
- let h = a(f), w = a(m), O = g(f, m);
1021
- !c(f, m) && (h > w || h === w && j(f, m, l)) && t.report({
1020
+ let h = t(f), w = t(m), O = g(f, m);
1021
+ !c(f, m) && (h > w || h === w && j(f, m, l)) && a.report({
1022
1022
  messageId: "unexpectedImportsOrder",
1023
1023
  data: {
1024
1024
  left: f.name,
@@ -1026,7 +1026,7 @@ const K = "sort-imports", xe = A({
1026
1026
  },
1027
1027
  node: m.node,
1028
1028
  fix: (b) => x(b, y)
1029
- }), l["newlines-between"] === "never" && O > 0 && t.report({
1029
+ }), l["newlines-between"] === "never" && O > 0 && a.report({
1030
1030
  messageId: "extraSpacingBetweenImports",
1031
1031
  data: {
1032
1032
  left: f.name,
@@ -1034,7 +1034,7 @@ const K = "sort-imports", xe = A({
1034
1034
  },
1035
1035
  node: m.node,
1036
1036
  fix: (b) => x(b, y)
1037
- }), l["newlines-between"] === "always" && (h < w && O === 0 ? t.report({
1037
+ }), l["newlines-between"] === "always" && (h < w && O === 0 ? a.report({
1038
1038
  messageId: "missedSpacingBetweenImports",
1039
1039
  data: {
1040
1040
  left: f.name,
@@ -1042,7 +1042,7 @@ const K = "sort-imports", xe = A({
1042
1042
  },
1043
1043
  node: m.node,
1044
1044
  fix: (b) => x(b, y)
1045
- }) : (O > 1 || h === w && O > 0) && t.report({
1045
+ }) : (O > 1 || h === w && O > 0) && a.report({
1046
1046
  messageId: "extraSpacingBetweenImports",
1047
1047
  data: {
1048
1048
  left: f.name,
@@ -1103,21 +1103,21 @@ const K = "sort-imports", xe = A({
1103
1103
  order: d.asc
1104
1104
  }
1105
1105
  ],
1106
- create: (t) => ({
1106
+ create: (a) => ({
1107
1107
  ClassBody: (l) => {
1108
1108
  if (l.body.length > 1) {
1109
- let s = k(t.options.at(0), {
1109
+ let s = k(a.options.at(0), {
1110
1110
  type: i.alphabetical,
1111
1111
  order: d.asc,
1112
1112
  "ignore-case": !1,
1113
1113
  groups: ["property", "constructor", "method", "unknown"]
1114
- }), n = t.getSourceCode(), p = l.body.map((e) => {
1114
+ }), n = a.getSourceCode(), p = l.body.map((e) => {
1115
1115
  var g;
1116
- let o, a;
1117
- e.type === u.StaticBlock ? a = "static" : e.type === u.TSIndexSignature ? a = n.text.slice(
1116
+ let o, t;
1117
+ e.type === u.StaticBlock ? t = "static" : e.type === u.TSIndexSignature ? t = n.text.slice(
1118
1118
  e.range.at(0),
1119
1119
  ((g = e.typeAnnotation) == null ? void 0 : g.range.at(0)) ?? e.range.at(1)
1120
- ) : e.key.type === u.Identifier ? { name: a } = e.key : a = n.text.slice(...e.key.range);
1120
+ ) : e.key.type === u.Identifier ? { name: t } = e.key : t = n.text.slice(...e.key.range);
1121
1121
  let c = (x) => {
1122
1122
  !o && s.groups.flat().includes(x) && (o = x);
1123
1123
  };
@@ -1125,10 +1125,10 @@ const K = "sort-imports", xe = A({
1125
1125
  size: N(e.range),
1126
1126
  group: o ?? "unknown",
1127
1127
  node: e,
1128
- name: a
1128
+ name: t
1129
1129
  };
1130
1130
  }), r = (e) => {
1131
- for (let o = 0, a = s.groups.length; o < a; o++) {
1131
+ for (let o = 0, t = s.groups.length; o < t; o++) {
1132
1132
  let c = s.groups[o];
1133
1133
  if (e.group === c || Array.isArray(c) && c.includes(e.group))
1134
1134
  return o;
@@ -1136,8 +1136,8 @@ const K = "sort-imports", xe = A({
1136
1136
  return s.groups.length;
1137
1137
  };
1138
1138
  P(p, (e, o) => {
1139
- let a = r(e), c = r(o);
1140
- (a > c || a === c && j(e, o, s)) && t.report({
1139
+ let t = r(e), c = r(o);
1140
+ (t > c || t === c && j(e, o, s)) && a.report({
1141
1141
  messageId: "unexpectedClassesOrder",
1142
1142
  data: {
1143
1143
  left: I(e.name),
@@ -1224,21 +1224,21 @@ const K = "sort-imports", xe = A({
1224
1224
  order: d.asc
1225
1225
  }
1226
1226
  ],
1227
- create: (t) => {
1227
+ create: (a) => {
1228
1228
  let l = (s) => {
1229
1229
  if (s.properties.length > 1) {
1230
- let n = k(t.options.at(0), {
1230
+ let n = k(a.options.at(0), {
1231
1231
  type: i.alphabetical,
1232
1232
  "ignore-case": !1,
1233
1233
  order: d.asc,
1234
1234
  "always-on-top": []
1235
- }), p = t.getSourceCode();
1235
+ }), p = a.getSourceCode();
1236
1236
  ((e) => e.reduce(
1237
- (o, a) => {
1238
- if (a.type === u.SpreadElement || a.type === u.RestElement)
1237
+ (o, t) => {
1238
+ if (t.type === u.SpreadElement || t.type === u.RestElement)
1239
1239
  return o.push([]), o;
1240
1240
  let c, g = "ignore", x = [];
1241
- if (a.key.type === u.Identifier ? { name: c } = a.key : a.key.type === u.Literal ? c = `${a.key.value}` : c = p.text.slice(...a.key.range), a.key.type === u.Identifier && n["always-on-top"].includes(a.key.name) && (g = "exception"), a.value.type === u.AssignmentPattern) {
1241
+ if (t.key.type === u.Identifier ? { name: c } = t.key : t.key.type === u.Literal ? c = `${t.key.value}` : c = p.text.slice(...t.key.range), t.key.type === u.Identifier && n["always-on-top"].includes(t.key.name) && (g = "exception"), t.value.type === u.AssignmentPattern) {
1242
1242
  let y = (f, m) => {
1243
1243
  f.right.type === u.Identifier && x.push(f.right.name), !m && f.left.type === u.Identifier && x.push(f.left.name);
1244
1244
  let h = (w) => {
@@ -1246,12 +1246,12 @@ const K = "sort-imports", xe = A({
1246
1246
  };
1247
1247
  f.right.type === u.BinaryExpression && h(f.right);
1248
1248
  };
1249
- y(a.value, !0);
1249
+ y(t.value, !0);
1250
1250
  }
1251
1251
  let E = {
1252
- size: N(a.range),
1252
+ size: N(t.range),
1253
1253
  dependencies: x,
1254
- node: a,
1254
+ node: t,
1255
1255
  position: g,
1256
1256
  name: c
1257
1257
  };
@@ -1259,18 +1259,18 @@ const K = "sort-imports", xe = A({
1259
1259
  },
1260
1260
  [[]]
1261
1261
  ))(s.properties).forEach((e) => {
1262
- P(e, (o, a) => {
1262
+ P(e, (o, t) => {
1263
1263
  let c;
1264
- if (o.position === "exception" && a.position === "exception")
1265
- c = n["always-on-top"].indexOf(o.name) > n["always-on-top"].indexOf(a.name);
1266
- else if (o.position === a.position)
1267
- c = j(o, a, n);
1264
+ if (o.position === "exception" && t.position === "exception")
1265
+ c = n["always-on-top"].indexOf(o.name) > n["always-on-top"].indexOf(t.name);
1266
+ else if (o.position === t.position)
1267
+ c = j(o, t, n);
1268
1268
  else {
1269
1269
  let g = {
1270
1270
  exception: 1,
1271
1271
  ignore: 0
1272
1272
  };
1273
- c = g[o.position] < g[a.position];
1273
+ c = g[o.position] < g[t.position];
1274
1274
  }
1275
1275
  if (c) {
1276
1276
  let g = (x) => {
@@ -1288,13 +1288,13 @@ const K = "sort-imports", xe = A({
1288
1288
  ].flat();
1289
1289
  return v(x, e, f, p);
1290
1290
  };
1291
- t.report({
1291
+ a.report({
1292
1292
  messageId: "unexpectedObjectsOrder",
1293
1293
  data: {
1294
1294
  left: I(o.name),
1295
- right: I(a.name)
1295
+ right: I(t.name)
1296
1296
  },
1297
- node: a.node,
1297
+ node: t.node,
1298
1298
  fix: g
1299
1299
  });
1300
1300
  }
@@ -1350,8 +1350,8 @@ const K = "sort-imports", xe = A({
1350
1350
  order: d.asc
1351
1351
  }
1352
1352
  ],
1353
- create: (t) => {
1354
- let l = k(t.options.at(0), {
1353
+ create: (a) => {
1354
+ let l = k(a.options.at(0), {
1355
1355
  type: i.alphabetical,
1356
1356
  order: d.asc,
1357
1357
  "ignore-case": !1
@@ -1368,17 +1368,17 @@ const K = "sort-imports", xe = A({
1368
1368
  p.source !== null && n(p);
1369
1369
  },
1370
1370
  "Program:exit": () => {
1371
- let p = t.getSourceCode();
1371
+ let p = a.getSourceCode();
1372
1372
  s.forEach((r) => {
1373
1373
  P(r, (e, o) => {
1374
- j(e, o, l) && t.report({
1374
+ j(e, o, l) && a.report({
1375
1375
  messageId: "unexpectedExportsOrder",
1376
1376
  data: {
1377
1377
  left: e.name,
1378
1378
  right: o.name
1379
1379
  },
1380
1380
  node: o.node,
1381
- fix: (a) => v(a, r, S(r, l), p)
1381
+ fix: (t) => v(t, r, S(r, l), p)
1382
1382
  });
1383
1383
  });
1384
1384
  });
@@ -1428,20 +1428,20 @@ const K = "sort-imports", xe = A({
1428
1428
  order: d.asc
1429
1429
  }
1430
1430
  ],
1431
- create: (t) => ({
1431
+ create: (a) => ({
1432
1432
  TSEnumDeclaration: (l) => {
1433
1433
  if (l.members.length > 1 && l.members.some(({ initializer: s }) => s)) {
1434
- let s = k(t.options.at(0), {
1434
+ let s = k(a.options.at(0), {
1435
1435
  type: i.alphabetical,
1436
1436
  order: d.asc,
1437
1437
  "ignore-case": !1
1438
- }), n = t.getSourceCode(), p = l.members.map((r) => ({
1438
+ }), n = a.getSourceCode(), p = l.members.map((r) => ({
1439
1439
  name: r.id.type === u.Literal ? `${r.id.value}` : `${n.text.slice(...r.id.range)}`,
1440
1440
  size: N(r.range),
1441
1441
  node: r
1442
1442
  }));
1443
1443
  P(p, (r, e) => {
1444
- j(r, e, s) && t.report({
1444
+ j(r, e, s) && a.report({
1445
1445
  messageId: "unexpectedEnumsOrder",
1446
1446
  data: {
1447
1447
  left: I(r.name),
@@ -1455,7 +1455,7 @@ const K = "sort-imports", xe = A({
1455
1455
  }
1456
1456
  })
1457
1457
  }), Ie = "eslint-plugin-perfectionist";
1458
- let M = (t) => {
1458
+ let M = (a) => {
1459
1459
  let l = {
1460
1460
  [K]: [
1461
1461
  "error",
@@ -1524,7 +1524,7 @@ let M = (t) => {
1524
1524
  rules: Object.fromEntries(
1525
1525
  Object.entries(l).map(([s, [n, p = {}]]) => [
1526
1526
  `perfectionist/${s}`,
1527
- [n, Object.assign(p, t)]
1527
+ [n, Object.assign(p, a)]
1528
1528
  ])
1529
1529
  ),
1530
1530
  plugins: ["perfectionist"]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-perfectionist",
3
3
  "description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "homepage": "https://eslint-plugin-perfectionist.azat.io",
6
6
  "repository": "https://github.com/azat-io/eslint-plugin-perfectionist",
7
7
  "author": "Azat S. <to@azat.io>",