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

eslint-plugin-perfectionist

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-perfectionist - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

6

dist/index.js

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

"use strict";var F=Object.defineProperty;var ee=(r,o,a)=>o in r?F(r,o,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[o]=a;var V=(r,o,a)=>(ee(r,typeof o!="symbol"?o+"":o,a),a);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),te=require("natural-compare-lite"),C=require("minimatch"),ae=require("is-core-module"),re=require("json5"),ne=require("path"),se=require("fs");let A=v.ESLintUtils.RuleCreator(r=>`https://eslint-plugin-perfectionist.azat.io/rules/${r}`),x=r=>r.replaceAll(/\s\s+/g," ").trim(),N=r=>{let[o,a]=r;return a-o};var i=(r=>(r.alphabetical="alphabetical",r["line-length"]="line-length",r.natural="natural",r))(i||{}),p=(r=>(r.desc="desc",r.asc="asc",r))(p||{});let O=(r,o,a)=>{let s=a.order==="asc"?1:-1,c,t=e=>a["ignore-case"]?e.toLowerCase():e;return a.type===i.alphabetical?c=(e,n)=>t(e.name).localeCompare(t(n.name)):a.type===i.natural?c=(e,n)=>te(t(e.name),t(n.name)):c=(e,n)=>e.size-n.size,s*c(r,o)>0},b=(r,o)=>[...r].sort((a,s)=>Number(O(a,s,o))||-1),oe=(r,o)=>{let a=o.getTokenAfter(r,{filter:({type:s,value:c})=>!(s===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(c)),includeComments:!0});return((a==null?void 0:a.type)===u.AST_TOKEN_TYPES.Block||(a==null?void 0:a.type)===u.AST_TOKEN_TYPES.Line)&&r.loc.end.line===a.loc.end.line?a:null},H=(r,o)=>{let[a,s]=o.getTokensBefore(r,{filter:({type:c,value:t})=>!(c===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(t)),includeComments:!0,count:2});return((s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===u.AST_TOKEN_TYPES.Line)&&r.loc.start.line-s.loc.end.line<=1&&(a==null?void 0:a.loc.end.line)!==s.loc.start.line?s:null},I=(r,o)=>{let a=r.range.at(0),s=r.range.at(1),c=o.text.slice(a,s);if(v.ASTUtils.isParenthesized(r,o)){let e=o.getTokenBefore(r,v.ASTUtils.isOpeningParenToken),n=o.getTokenAfter(r,v.ASTUtils.isClosingParenToken);a=e.range.at(0),s=n.range.at(1)}let t=H(r,o);return(c.endsWith(";")||c.endsWith(","))&&(s-=1),t&&(a=t.range.at(0)),[a,s]},D=(r,o,a,s)=>{let c=[];return o.forEach(({node:t},e)=>{c.push(r.replaceTextRange(I(t,s),s.text.slice(...I(a[e].node,s))));let n=oe(a[e].node,s);if(n){let d=[s.getTokenBefore(n).range.at(1),n.range.at(1)];c.push(r.replaceTextRange(d,""));let m=s.getTokenAfter(t);c.push(r.insertTextAfter((m==null?void 0:m.loc.end.line)===t.loc.end.line?m:t,s.text.slice(...d)))}}),c},P=(r={},o)=>Object.assign(o,r),w=(r,o)=>{if(r.length>1)for(let a=1;a<r.length;a++){let s=r.at(a-1),c=r.at(a);s&&c&&o(s,c,a-1)}};const L="sort-array-includes",le=A({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:[p.asc,p.desc],default:p.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:p.asc}],create:r=>({MemberExpression:o=>{if((o.object.type===u.AST_NODE_TYPES.ArrayExpression||o.object.type===u.AST_NODE_TYPES.NewExpression)&&o.property.type===u.AST_NODE_TYPES.Identifier&&o.property.name==="includes"){let a=o.object.type===u.AST_NODE_TYPES.ArrayExpression?o.object.elements:o.object.arguments;if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1,"spread-last":!1}),c=r.getSourceCode(),t=a.reduce((e,n)=>(n!==null&&e.at(0).push({name:n.type===u.AST_NODE_TYPES.Literal?n.raw:c.text.slice(...n.range),size:N(n.range),type:n.type,node:n}),e),[[],[]]).flat();w(t,(e,n)=>{let l;s["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&n.node.type===u.AST_NODE_TYPES.SpreadElement?l=!1:s["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&n.node.type===u.AST_NODE_TYPES.Literal?l=!0:l=O(e,n,s),l&&r.report({messageId:"unexpectedArrayIncludesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:d=>{let m=b(t,s);return s["spread-last"]&&m.forEach((E,_)=>{E.node.type===u.AST_NODE_TYPES.SpreadElement&&m.push(m.splice(_,1).at(0))}),D(d,t,m,c)}})})}}}})}),M="sort-named-exports",ie=A({name:M,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:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ExportNamedDeclaration:o=>{if(o.specifiers.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),s=r.getSourceCode(),c=o.specifiers.map(t=>({size:N(t.range),name:t.local.name,node:t}));w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedNamedExportsOrder",data:{left:t.name,right:e.name},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),$="sort-named-imports",pe=A({name:$,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:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ImportDeclaration:o=>{let a=o.specifiers.filter(({type:s})=>s===u.AST_NODE_TYPES.ImportSpecifier);if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=r.getSourceCode(),t=a.map(e=>({size:N(e.range),name:e.local.name,node:e}));w(t,(e,n)=>{O(e,n,s)&&r.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:n.name},node:n.node,fix:l=>D(l,t,b(t,s),c)})})}}})}),U="sort-object-types",ce=A({name:U,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:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedObjectTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSTypeLiteral:o=>{if(o.members.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),s=r.getSourceCode(),c=o.members.map(t=>{var m,E;let e,n=s.text.slice(t.range.at(0),t.range.at(1));if(t.type===u.AST_NODE_TYPES.TSPropertySignature)t.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=t.key:t.key.type===u.AST_NODE_TYPES.Literal?e=`${t.key.value}`:e=s.text.slice(t.range.at(0),(m=t.typeAnnotation)==null?void 0:m.range.at(0));else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let _=((E=t.typeAnnotation)==null?void 0:E.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),_)}else e=s.text.slice(t.range.at(0),t.range.at(1));let d=n.endsWith(";")||n.endsWith(",")?1:0;return{size:N(t.range)-d,node:t,name:e}});w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedObjectTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),B="sort-map-elements",de=A({name:B,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:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({NewExpression:o=>{if(o.callee.type===u.AST_NODE_TYPES.Identifier&&o.callee.name==="Map"&&o.arguments.length&&o.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let[{elements:a}]=o.arguments;if(a.length>1){let s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=r.getSourceCode();a.reduce((e,n)=>(n===null||n.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(n),e),[[]]).forEach(e=>{let n=e.map(l=>{let d;if(l.type===u.AST_NODE_TYPES.ArrayExpression){let[m]=l.elements;m?m.type===u.AST_NODE_TYPES.Literal?d=m.raw:d=c.text.slice(...m.range):d=`${m}`}else d=c.text.slice(...l.range);return{size:N(l.range),node:l,name:d}});w(n,(l,d)=>{O(l,d,s)&&r.report({messageId:"unexpectedMapElementsOrder",data:{left:x(l.name),right:x(d.name)},node:d.node,fix:m=>D(m,n,b(n,s),c)})})})}}}})}),z="sort-union-types",fe=A({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:[p.asc,p.desc],default:p.asc},"ignore-case":{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSUnionType:o=>{let a=r.getSourceCode(),s=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc}),c=o.types.map(t=>({name:a.text.slice(...t.range),size:N(t.range),node:t}));w(c,(t,e)=>{O(t,e,s)&&r.report({messageId:"unexpectedUnionTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,s),a)})})}})}),q="sort-interfaces",ue=A({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:[p.asc,p.desc],default:p.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:p.asc}],create:r=>({TSInterfaceDeclaration:o=>{if(o.body.body.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc,"ignore-pattern":[]});if(!a["ignore-pattern"].some(s=>C.minimatch(o.id.name,s))){let s=r.getSourceCode(),c=o.body.body.map(t=>{var n,l,d;let e;if(t.type===u.AST_NODE_TYPES.TSPropertySignature)if(t.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=t.key);else if(t.key.type===u.AST_NODE_TYPES.Literal)e=`${t.key.value}`;else{let m=((n=t.typeAnnotation)==null?void 0:n.range.at(0))??t.range.at(1)-(t.optional?1:0);e=s.text.slice(t.range.at(0),m)}else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let m=((l=t.typeAnnotation)==null?void 0:l.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),m)}else{let m=((d=t.returnType)==null?void 0:d.range.at(0))??t.range.at(1);e=s.text.slice(t.range.at(0),m)}return{size:N(t.range),node:t,name:e}});w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}}})});let Q=(r,o)=>r.reduce((a,s)=>{let c=o(s);return c in a||(a[c]=[]),a[c].push(s),a},{});const J="sort-jsx-props",ge=A({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:[p.asc,p.desc],default:p.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:p.asc}],create:r=>({JSXElement:o=>{if(o.openingElement.attributes.length>1){let a=P(r.options.at(0),{type:i.alphabetical,shorthand:"ignore",multiline:"ignore",callback:"ignore","always-on-top":[],"ignore-case":!1,order:p.asc}),s=r.getSourceCode();o.openingElement.attributes.reduce((t,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return t.push([]),t;let n="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&a["always-on-top"].includes(e.name.name)?n="exception":(a.shorthand!=="ignore"&&e.value===null&&(n=a.shorthand),a.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?n=a.callback:a.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(n=a.multiline));let l={name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:N(e.range),node:e,position:n};return t.at(-1).push(l),t},[[]]).forEach(t=>{w(t,(e,n)=>{let l;if(e.position==="exception"&&n.position==="exception")l=a["always-on-top"].indexOf(e.name)>a["always-on-top"].indexOf(n.name);else if(e.position===n.position)l=O(e,n,a);else{let d={exception:2,first:1,ignore:0,last:-1};l=d[e.position]<d[n.position]}l&&r.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:n.name},node:n.node,fix:d=>{let m=Q(t,({position:y})=>y),E=y=>y in m?m[y]:[],_=[E("exception").sort((y,f)=>a["always-on-top"].indexOf(y.name)-a["always-on-top"].indexOf(f.name)),b(E("first"),a),b(E("ignore"),a),b(E("last"),a)].flat();return D(d,t,_,s)}})})})}}})});class Z{static get(){return this._instance?this._instance:(this._instance=re.parse(se.readFileSync(ne.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}V(Z,"_instance");const X="sort-imports",me=A({name:X,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:[p.asc,p.desc],default:p.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:p.asc}],create:r=>{var n;let o=P(r.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:i.alphabetical,"read-tsconfig":!1,order:p.asc,"ignore-case":!1,groups:[]}),a=[];if(o["read-tsconfig"]){let l=Z.get();(n=l.compilerOptions)!=null&&n.paths&&Object.keys(l.compilerOptions.paths).forEach(d=>{a.push(d)})}let s=r.getSourceCode(),c=[],t=l=>{let d,m=g=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(g),E=g=>g.indexOf("..")===0,_=g=>g.indexOf("./")===0,y=g=>{!d&&o.groups.flat().includes(g)&&(d=g)},f=g=>o["internal-pattern"].length&&o["internal-pattern"].some(S=>C.minimatch(g.source.value,S))||a.some(S=>C.minimatch(g.source.value,S));return l.importKind==="type"&&(l.type===u.AST_NODE_TYPES.ImportDeclaration&&(f(l)?y("internal-type"):m(l.source.value)?y("index-type"):E(l.source.value)?y("parent-type"):_(l.source.value)&&y("sibling-type")),y("type")),!d&&l.type===u.AST_NODE_TYPES.ImportDeclaration&&(ae(l.source.value)?y("builtin"):f(l)?y("internal"):m(l.source.value)?y("index"):E(l.source.value)?y("parent"):_(l.source.value)?y("sibling"):y("external")),d??"unknown"},e=l=>{let d;l.type===u.AST_NODE_TYPES.ImportDeclaration?d=l.source.value:l.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&l.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?d=`${l.moduleReference.expression.value}`:d=s.text.slice(...l.moduleReference.range),c.push({size:N(l.range),group:t(l),name:d,node:l})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let l=y=>{for(let f=0,g=o.groups.length;f<g;f++){let S=o.groups[f];if(y.group===S||Array.isArray(S)&&S.includes(y.group))return f}return o.groups.length},d=(y,f)=>!!s.getTokensBetween(y.node,H(f.node,s)||f.node,{includeComments:!0}).length,m=(y,f)=>s.lines.slice(y.node.loc.end.line,f.node.loc.start.line-1).filter(S=>!S.trim().length).length,E=(y,f)=>{let g=[],S=f.reduce((T,h)=>{let Y=l(h);return Y in T?T[Y]=b([...T[Y],h],o):T[Y]=[h],T},{}),j=Object.keys(S).sort().reduce((T,h)=>[...T,...S[h]],[]);return j.forEach((T,h)=>{if(g.push(y.replaceTextRange(I(f.at(h).node,s),s.text.slice(...I(T.node,s)))),o["newlines-between"]!=="ignore"){let Y=j.at(h+1);if(Y){let k=m(f.at(h),f.at(h+1));(o["newlines-between"]==="always"&&l(T)===l(Y)&&k!==0||o["newlines-between"]==="never"&&k>0)&&g.push(y.removeRange([I(f.at(h).node,s).at(1),I(f.at(h+1).node,s).at(0)-1])),o["newlines-between"]==="always"&&k>1&&g.push(y.replaceTextRange([I(f.at(h).node,s).at(1),I(f.at(h+1).node,s).at(0)-1],`
`)),o["newlines-between"]==="always"&&l(T)!==l(Y)&&k===0&&g.push(y.insertTextAfterRange(I(f.at(h).node,s),`
`))}}}),g};c.reduce((y,f)=>{var S;let g=(S=y.at(-1))==null?void 0:S.at(-1);return g&&d(g,f)?y.push([f]):y.at(-1).push(f),y},[[]]).forEach(y=>{w(y,(f,g)=>{let S=l(f),j=l(g),T=m(f,g);!d(f,g)&&(S>j||S===j&&O(f,g,o))&&r.report({messageId:"unexpectedImportsOrder",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}),o["newlines-between"]==="never"&&T>0&&r.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}),o["newlines-between"]==="always"&&(S<j&&T===0?r.report({messageId:"missedSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}):(T>1||S===j&&T>0)&&r.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:g.name},node:g.node,fix:h=>E(h,y)}))})})}}}}),G="sort-classes",ye=A({name:G,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:[p.asc,p.desc],default:p.asc},groups:{type:"array",default:["property","constructor","method","unknown"]}},additionalProperties:!1}],messages:{unexpectedClassesOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({ClassBody:o=>{if(o.body.length>1){let a=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1,groups:["property","constructor","method","unknown"]}),s=r.getSourceCode(),c=o.body.map(e=>{var m;let n,l;e.type===u.AST_NODE_TYPES.StaticBlock?l="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?l=s.text.slice(e.range.at(0),((m=e.typeAnnotation)==null?void 0:m.range.at(0))??e.range.at(1)):e.key.type===u.AST_NODE_TYPES.Identifier?{name:l}=e.key:l=s.text.slice(...e.key.range);let d=E=>{!n&&a.groups.flat().includes(E)&&(n=E)};return e.type===u.AST_NODE_TYPES.MethodDefinition?(e.kind==="constructor"&&d("constructor"),e.static&&d("static-method"),e.accessibility==="private"&&d("private-method"),d("method")):e.type===u.AST_NODE_TYPES.PropertyDefinition&&(e.static&&d("static-property"),e.accessibility==="private"&&d("private-property"),d("property")),{size:N(e.range),group:n??"unknown",node:e,name:l}}),t=e=>{for(let n=0,l=a.groups.length;n<l;n++){let d=a.groups[n];if(e.group===d||Array.isArray(d)&&d.includes(e.group))return n}return a.groups.length};w(c,(e,n)=>{let l=t(e),d=t(n);(l>d||l===d&&O(e,n,a))&&r.report({messageId:"unexpectedClassesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:m=>{let E=[],_=c.reduce((f,g)=>{let S=t(g);return S in f?f[S]=b([...f[S],g],a):f[S]=[g],f},{});return Object.keys(_).sort().reduce((f,g)=>[...f,..._[g]],[]).forEach((f,g)=>{E.push(m.replaceTextRange(I(c.at(g).node,s),s.text.slice(...I(f.node,s))))}),E}})})}}})}),K="sort-objects",Ee=A({name:K,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:[p.asc,p.desc],default:p.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:p.asc}],create:r=>({ObjectExpression:o=>{if(o.properties.length>1){let a=P(r.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:p.asc,"always-on-top":[]}),s=r.getSourceCode();(t=>t.reduce((e,n)=>{if(n.type===u.AST_NODE_TYPES.SpreadElement)return e.push([]),e;let l,d="ignore";n.key.type===u.AST_NODE_TYPES.Identifier?{name:l}=n.key:n.key.type===u.AST_NODE_TYPES.Literal?l=`${n.key.value}`:l=s.text.slice(...n.key.range),n.key.type===u.AST_NODE_TYPES.Identifier&&a["always-on-top"].includes(n.key.name)&&(d="exception");let m={size:N(n.range),node:n,position:d,name:l};return e.at(-1).push(m),e},[[]]))(o.properties).forEach(t=>{w(t,(e,n)=>{let l;if(e.position==="exception"&&n.position==="exception")l=a["always-on-top"].indexOf(e.name)>a["always-on-top"].indexOf(n.name);else if(e.position===n.position)l=O(e,n,a);else{let d={exception:1,ignore:0};l=d[e.position]<d[n.position]}if(l){let d=m=>{let E=Q(t,({position:f})=>f),_=f=>f in E?E[f]:[],y=[_("exception").sort((f,g)=>a["always-on-top"].indexOf(f.name)-a["always-on-top"].indexOf(g.name)),b(_("ignore"),a)].flat();return D(m,t,y,s)};r.report({messageId:"unexpectedObjectsOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:d})}})})}}})}),W="sort-enums",Se=A({name:W,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:[p.asc,p.desc],default:p.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{right}}" to come before "{{left}}"'}},defaultOptions:[{type:i.alphabetical,order:p.asc}],create:r=>({TSEnumDeclaration:o=>{if(o.members.length>1&&o.members.some(({initializer:a})=>a)){let a=P(r.options.at(0),{type:i.alphabetical,order:p.asc,"ignore-case":!1}),s=r.getSourceCode(),c=o.members.map(t=>({name:t.id.type===u.AST_NODE_TYPES.Literal?`${t.id.value}`:`${s.text.slice(...t.id.range)}`,size:N(t.range),node:t}));w(c,(t,e)=>{O(t,e,a)&&r.report({messageId:"unexpectedEnumsOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>D(n,c,b(c,a),s)})})}}})}),he="eslint-plugin-perfectionist";let R=r=>{let o={[X]:["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}],[G]:["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}],[K]:["error",{"always-on-top":[]}],[$]:["error"],[M]:["error"],[U]:["error"],[B]:["error"],[z]:["error"],[q]:["error"],[W]:["error"]};return{rules:Object.fromEntries(Object.entries(o).map(([a,[s,c={}]])=>[`perfectionist/${a}`,[s,Object.assign(c,r)]])),plugins:["perfectionist"]}};const Te={rules:{[L]:le,[G]:ye,[W]:Se,[X]:me,[q]:ue,[J]:ge,[B]:de,[M]:ie,[$]:pe,[U]:ce,[K]:Ee,[z]:fe},configs:{"recommended-alphabetical":R({type:i.alphabetical,order:p.asc,"ignore-case":!1}),"recommended-natural":R({type:i.natural,order:p.asc,"ignore-case":!1}),"recommended-line-length":R({type:i["line-length"],order:p.desc})},name:he};module.exports=Te;
"use strict";var ee=Object.defineProperty;var te=(a,l,s)=>l in a?ee(a,l,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[l]=s;var V=(a,l,s)=>(te(a,typeof l!="symbol"?l+"":l,s),s);const u=require("@typescript-eslint/types"),v=require("@typescript-eslint/utils"),ae=require("natural-compare-lite"),C=require("minimatch"),H=require("is-core-module"),se=require("json5"),re=require("path"),ne=require("fs");let N=v.ESLintUtils.RuleCreator(a=>`https://eslint-plugin-perfectionist.azat.io/rules/${a}`),x=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)=>{let r=s.order==="asc"?1:-1,p,t=e=>s["ignore-case"]?e.toLowerCase():e;return s.type===i.alphabetical?p=(e,n)=>t(e.name).localeCompare(t(n.name)):s.type===i.natural?p=(e,n)=>ae(t(e.name),t(n.name)):p=(e,n)=>e.size-n.size,r*p(a,l)>0},_=(a,l)=>[...a].sort((s,r)=>Number(A(s,r,l))||-1),oe=(a,l)=>{let s=l.getTokenAfter(a,{filter:({type:r,value:p})=>!(r===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},Q=(a,l)=>{let[s,r]=l.getTokensBefore(a,{filter:({type:p,value:t})=>!(p===u.AST_TOKEN_TYPES.Punctuator&&[",",";"].includes(t)),includeComments:!0,count:2});return((r==null?void 0:r.type)===u.AST_TOKEN_TYPES.Block||(r==null?void 0:r.type)===u.AST_TOKEN_TYPES.Line)&&a.loc.start.line-r.loc.end.line<=1&&(s==null?void 0:s.loc.end.line)!==r.loc.start.line?r:null},D=(a,l)=>{let s=a.range.at(0),r=a.range.at(1),p=l.text.slice(s,r);if(v.ASTUtils.isParenthesized(a,l)){let e=l.getTokenBefore(a,v.ASTUtils.isOpeningParenToken),n=l.getTokenAfter(a,v.ASTUtils.isClosingParenToken);s=e.range.at(0),r=n.range.at(1)}let t=Q(a,l);return(p.endsWith(";")||p.endsWith(","))&&(r-=1),t&&(s=t.range.at(0)),[s,r]},Y=(a,l,s,r)=>{let p=[];return l.forEach(({node:t},e)=>{p.push(a.replaceTextRange(D(t,r),r.text.slice(...D(s[e].node,r))));let n=oe(s[e].node,r);if(n){let c=[r.getTokenBefore(n).range.at(1),n.range.at(1)];p.push(a.replaceTextRange(c,""));let g=r.getTokenAfter(t);p.push(a.insertTextAfter((g==null?void 0:g.loc.end.line)===t.loc.end.line?g:t,r.text.slice(...c)))}}),p},w=(a={},l)=>Object.assign(l,a),I=(a,l)=>{if(a.length>1)for(let s=1;s<a.length;s++){let r=a.at(s-1),p=a.at(s);r&&p&&l(r,p,s-1)}};const L="sort-array-includes",le=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 r=w(a.options.at(0),{type:i.alphabetical,order:d.asc,"ignore-case":!1,"spread-last":!1}),p=a.getSourceCode(),t=s.reduce((e,n)=>(n!==null&&e.at(0).push({name:n.type===u.AST_NODE_TYPES.Literal?n.raw:p.text.slice(...n.range),size:P(n.range),type:n.type,node:n}),e),[[],[]]).flat();I(t,(e,n)=>{let o;r["spread-last"]&&e.node.type===u.AST_NODE_TYPES.Literal&&n.node.type===u.AST_NODE_TYPES.SpreadElement?o=!1:r["spread-last"]&&e.node.type===u.AST_NODE_TYPES.SpreadElement&&n.node.type===u.AST_NODE_TYPES.Literal?o=!0:o=A(e,n,r),o&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:c=>{let g=_(t,r);return r["spread-last"]&&g.forEach((S,b)=>{S.node.type===u.AST_NODE_TYPES.SpreadElement&&g.push(g.splice(b,1).at(0))}),Y(c,t,g,p)}})})}}}})}),M="sort-named-exports",ie=N({name:M,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}),r=a.getSourceCode(),p=l.specifiers.map(t=>({size:P(t.range),name:t.local.name,node:t}));I(p,(t,e)=>{A(t,e,s)&&a.report({messageId:"unexpectedNamedExportsOrder",data:{left:t.name,right:e.name},node:e.node,fix:n=>Y(n,p,_(p,s),r)})})}}})}),$="sort-named-imports",pe=N({name:$,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:r})=>r===u.AST_NODE_TYPES.ImportSpecifier);if(s.length>1){let r=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=a.getSourceCode(),t=s.map(e=>({size:P(e.range),name:e.local.name,node:e}));I(t,(e,n)=>{A(e,n,r)&&a.report({messageId:"unexpectedNamedImportsOrder",data:{left:e.name,right:n.name},node:n.node,fix:o=>Y(o,t,_(t,r),p)})})}}})}),U="sort-object-types",ce=N({name:U,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}),r=a.getSourceCode(),p=l.members.map(t=>{var g,S;let e,n=r.text.slice(t.range.at(0),t.range.at(1));if(t.type===u.AST_NODE_TYPES.TSPropertySignature)t.key.type===u.AST_NODE_TYPES.Identifier?{name:e}=t.key:t.key.type===u.AST_NODE_TYPES.Literal?e=`${t.key.value}`:e=r.text.slice(t.range.at(0),(g=t.typeAnnotation)==null?void 0:g.range.at(0));else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let b=((S=t.typeAnnotation)==null?void 0:S.range.at(0))??t.range.at(1);e=r.text.slice(t.range.at(0),b)}else e=r.text.slice(t.range.at(0),t.range.at(1));let c=n.endsWith(";")||n.endsWith(",")?1:0;return{size:P(t.range)-c,node:t,name:e}});I(p,(t,e)=>{A(t,e,s)&&a.report({messageId:"unexpectedObjectTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>Y(n,p,_(p,s),r)})})}}})}),B="sort-map-elements",de=N({name:B,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 r=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=a.getSourceCode();s.reduce((e,n)=>(n===null||n.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(n),e),[[]]).forEach(e=>{let n=e.map(o=>{let c;if(o.type===u.AST_NODE_TYPES.ArrayExpression){let[g]=o.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(...o.range);return{size:P(o.range),node:o,name:c}});I(n,(o,c)=>{A(o,c,r)&&a.report({messageId:"unexpectedMapElementsOrder",data:{left:x(o.name),right:x(c.name)},node:c.node,fix:g=>Y(g,n,_(n,r),p)})})})}}}})}),z="sort-union-types",fe=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(),r=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc}),p=l.types.map(t=>({name:s.text.slice(...t.range),size:P(t.range),node:t}));I(p,(t,e)=>{A(t,e,r)&&a.report({messageId:"unexpectedUnionTypesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>Y(n,p,_(p,r),s)})})}})}),q="sort-interfaces",ue=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(r=>C.minimatch(l.id.name,r))){let r=a.getSourceCode(),p=l.body.body.map(t=>{var n,o,c;let e;if(t.type===u.AST_NODE_TYPES.TSPropertySignature)if(t.key.type===u.AST_NODE_TYPES.Identifier)({name:e}=t.key);else if(t.key.type===u.AST_NODE_TYPES.Literal)e=`${t.key.value}`;else{let g=((n=t.typeAnnotation)==null?void 0:n.range.at(0))??t.range.at(1)-(t.optional?1:0);e=r.text.slice(t.range.at(0),g)}else if(t.type===u.AST_NODE_TYPES.TSIndexSignature){let g=((o=t.typeAnnotation)==null?void 0:o.range.at(0))??t.range.at(1);e=r.text.slice(t.range.at(0),g)}else{let g=((c=t.returnType)==null?void 0:c.range.at(0))??t.range.at(1);e=r.text.slice(t.range.at(0),g)}return{size:P(t.range),node:t,name:e}});I(p,(t,e)=>{A(t,e,s)&&a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>Y(n,p,_(p,s),r)})})}}}})});let Z=(a,l)=>a.reduce((s,r)=>{let p=l(r);return p in s||(s[p]=[]),s[p].push(r),s},{});const J="sort-jsx-props",ge=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}),r=a.getSourceCode();l.openingElement.attributes.reduce((t,e)=>{if(e.type===u.AST_NODE_TYPES.JSXSpreadAttribute)return t.push([]),t;let n="ignore";e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&s["always-on-top"].includes(e.name.name)?n="exception":(s.shorthand!=="ignore"&&e.value===null&&(n=s.shorthand),s.callback!=="ignore"&&e.name.type===u.AST_NODE_TYPES.JSXIdentifier&&e.name.name.indexOf("on")===0&&e.value!==null?n=s.callback:s.multiline!=="ignore"&&e.loc.start.line!==e.loc.end.line&&(n=s.multiline));let o={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:n};return t.at(-1).push(o),t},[[]]).forEach(t=>{I(t,(e,n)=>{let o;if(e.position==="exception"&&n.position==="exception")o=s["always-on-top"].indexOf(e.name)>s["always-on-top"].indexOf(n.name);else if(e.position===n.position)o=A(e,n,s);else{let c={exception:2,first:1,ignore:0,last:-1};o=c[e.position]<c[n.position]}o&&a.report({messageId:"unexpectedJSXPropsOrder",data:{left:e.name,right:n.name},node:n.node,fix:c=>{let g=Z(t,({position:E})=>E),S=E=>E in g?g[E]:[],b=[S("exception").sort((E,f)=>s["always-on-top"].indexOf(E.name)-s["always-on-top"].indexOf(f.name)),_(S("first"),s),_(S("ignore"),s),_(S("last"),s)].flat();return Y(c,t,b,r)}})})})}}})});class F{static get(){return this._instance?this._instance:(this._instance=se.parse(ne.readFileSync(re.resolve(process.cwd(),"tsconfig.json"),"utf8")),this._instance)}}V(F,"_instance");const W="sort-imports",me=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 n;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 o=F.get();(n=o.compilerOptions)!=null&&n.paths&&Object.keys(o.compilerOptions.paths).forEach(c=>{s.push(c)})}let r=a.getSourceCode(),p=[],t=o=>{let c,g=y=>[".less",".scss",".sass",".pcss",".css",".sss"].some(O=>y.endsWith(O)),S=y=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(y),b=y=>y.indexOf("..")===0,E=y=>y.indexOf("./")===0,f=y=>{!c&&l.groups.flat().includes(y)&&(c=y)},m=y=>l["internal-pattern"].length&&l["internal-pattern"].some(O=>C.minimatch(y.source.value,O))||s.some(O=>C.minimatch(y.source.value,O));return o.importKind==="type"&&(o.type===u.AST_NODE_TYPES.ImportDeclaration&&(H(o.source.value)&&f("builtin-type"),m(o)&&f("internal-type"),S(o.source.value)&&f("index-type"),b(o.source.value)&&f("parent-type"),E(o.source.value)&&f("sibling-type")),f("type")),!c&&o.type===u.AST_NODE_TYPES.ImportDeclaration&&(H(o.source.value)&&f("builtin"),m(o)&&f("internal"),g(o.source.value)&&f("style"),o.specifiers.length===0&&f("side-effect"),S(o.source.value)&&f("index"),b(o.source.value)&&f("parent"),E(o.source.value)&&f("sibling"),f("external")),c??"unknown"},e=o=>{let c;o.type===u.AST_NODE_TYPES.ImportDeclaration?c=o.source.value:o.moduleReference.type===u.AST_NODE_TYPES.TSExternalModuleReference&&o.moduleReference.expression.type===u.AST_NODE_TYPES.Literal?c=`${o.moduleReference.expression.value}`:c=r.text.slice(...o.moduleReference.range),p.push({size:P(o.range),group:t(o),name:c,node:o})};return{TSImportEqualsDeclaration:e,ImportDeclaration:e,"Program:exit":()=>{let o=E=>{for(let f=0,m=l.groups.length;f<m;f++){let y=l.groups[f];if(E.group===y||Array.isArray(y)&&y.includes(E.group))return f}return l.groups.length},c=(E,f)=>!!r.getTokensBetween(E.node,Q(f.node,r)||f.node,{includeComments:!0}).length,g=(E,f)=>r.lines.slice(E.node.loc.end.line,f.node.loc.start.line-1).filter(y=>!y.trim().length).length,S=(E,f)=>{let m=[],y=f.reduce((T,h)=>{let j=o(h);return j in T?T[j]=_([...T[j],h],l):T[j]=[h],T},{}),O=Object.keys(y).sort().reduce((T,h)=>[...T,...y[h]],[]);return O.forEach((T,h)=>{if(m.push(E.replaceTextRange(D(f.at(h).node,r),r.text.slice(...D(T.node,r)))),l["newlines-between"]!=="ignore"){let j=O.at(h+1);if(j){let k=g(f.at(h),f.at(h+1));(l["newlines-between"]==="always"&&o(T)===o(j)&&k!==0||l["newlines-between"]==="never"&&k>0)&&m.push(E.removeRange([D(f.at(h).node,r).at(1),D(f.at(h+1).node,r).at(0)-1])),l["newlines-between"]==="always"&&k>1&&m.push(E.replaceTextRange([D(f.at(h).node,r).at(1),D(f.at(h+1).node,r).at(0)-1],`
`)),l["newlines-between"]==="always"&&o(T)!==o(j)&&k===0&&m.push(E.insertTextAfterRange(D(f.at(h).node,r),`
`))}}}),m};p.reduce((E,f)=>{var y;let m=(y=E.at(-1))==null?void 0:y.at(-1);return m&&c(m,f)?E.push([f]):E.at(-1).push(f),E},[[]]).forEach(E=>{I(E,(f,m)=>{let y=o(f),O=o(m),T=g(f,m);!c(f,m)&&(y>O||y===O&&A(f,m,l))&&a.report({messageId:"unexpectedImportsOrder",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,E)}),l["newlines-between"]==="never"&&T>0&&a.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,E)}),l["newlines-between"]==="always"&&(y<O&&T===0?a.report({messageId:"missedSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,E)}):(T>1||y===O&&T>0)&&a.report({messageId:"extraSpacingBetweenImports",data:{left:f.name,right:m.name},node:m.node,fix:h=>S(h,E)}))})})}}}}),X="sort-classes",ye=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"]}),r=a.getSourceCode(),p=l.body.map(e=>{var g;let n,o;e.type===u.AST_NODE_TYPES.StaticBlock?o="static":e.type===u.AST_NODE_TYPES.TSIndexSignature?o=r.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:o}=e.key:o=r.text.slice(...e.key.range);let c=S=>{!n&&s.groups.flat().includes(S)&&(n=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:n??"unknown",node:e,name:o}}),t=e=>{for(let n=0,o=s.groups.length;n<o;n++){let c=s.groups[n];if(e.group===c||Array.isArray(c)&&c.includes(e.group))return n}return s.groups.length};I(p,(e,n)=>{let o=t(e),c=t(n);(o>c||o===c&&A(e,n,s))&&a.report({messageId:"unexpectedClassesOrder",data:{left:x(e.name),right:x(n.name)},node:n.node,fix:g=>{let S=[],b=p.reduce((f,m)=>{let y=t(m);return y in f?f[y]=_([...f[y],m],s):f[y]=[m],f},{});return Object.keys(b).sort().reduce((f,m)=>[...f,...b[m]],[]).forEach((f,m)=>{S.push(g.replaceTextRange(D(p.at(m).node,r),r.text.slice(...D(f.node,r))))}),S}})})}}})}),G="sort-objects",Ee=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 r=w(a.options.at(0),{type:i.alphabetical,"ignore-case":!1,order:d.asc,"always-on-top":[]}),p=a.getSourceCode();(e=>e.reduce((n,o)=>{if(o.type===u.AST_NODE_TYPES.SpreadElement||o.type===u.AST_NODE_TYPES.RestElement)return n.push([]),n;let c,g="ignore";o.key.type===u.AST_NODE_TYPES.Identifier?{name:c}=o.key:o.key.type===u.AST_NODE_TYPES.Literal?c=`${o.key.value}`:c=p.text.slice(...o.key.range),o.key.type===u.AST_NODE_TYPES.Identifier&&r["always-on-top"].includes(o.key.name)&&(g="exception");let S={size:P(o.range),node:o,position:g,name:c};return n.at(-1).push(S),n},[[]]))(s.properties).forEach(e=>{I(e,(n,o)=>{let c;if(n.position==="exception"&&o.position==="exception")c=r["always-on-top"].indexOf(n.name)>r["always-on-top"].indexOf(o.name);else if(n.position===o.position)c=A(n,o,r);else{let g={exception:1,ignore:0};c=g[n.position]<g[o.position]}if(c){let g=S=>{let b=Z(e,({position:m})=>m),E=m=>m in b?b[m]:[],f=[E("exception").sort((m,y)=>r["always-on-top"].indexOf(m.name)-r["always-on-top"].indexOf(y.name)),_(E("ignore"),r)].flat();return Y(S,e,f,p)};a.report({messageId:"unexpectedObjectsOrder",data:{left:x(n.name),right:x(o.name)},node:o.node,fix:g})}})})}};return{ObjectExpression:l,ObjectPattern:l}}}),K="sort-enums",Se=N({name:K,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}),r=a.getSourceCode(),p=l.members.map(t=>({name:t.id.type===u.AST_NODE_TYPES.Literal?`${t.id.value}`:`${r.text.slice(...t.id.range)}`,size:P(t.range),node:t}));I(p,(t,e)=>{A(t,e,s)&&a.report({messageId:"unexpectedEnumsOrder",data:{left:x(t.name),right:x(e.name)},node:e.node,fix:n=>Y(n,p,_(p,s),r)})})}}})}),he="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":[]}],[$]:["error"],[M]:["error"],[U]:["error"],[B]:["error"],[z]:["error"],[q]:["error"],[K]:["error"]};return{rules:Object.fromEntries(Object.entries(l).map(([s,[r,p={}]])=>[`perfectionist/${s}`,[r,Object.assign(p,a)]])),plugins:["perfectionist"]}};const Te={rules:{[L]:le,[X]:ye,[K]:Se,[W]:me,[q]:ue,[J]:ge,[B]:de,[M]:ie,[$]:pe,[U]:ce,[G]:Ee,[z]:fe},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:he};module.exports=Te;
{
"name": "eslint-plugin-perfectionist",
"description": "ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://eslint-plugin-perfectionist.azat.io",

@@ -6,0 +6,0 @@ "repository": "https://github.com/azat-io/eslint-plugin-perfectionist",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc