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.1.1 to 1.1.2

2

dist/index.js

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

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