eslint-plugin-perfectionist 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-alphabetical"].rules};module.exports=r;
1
+ "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");require("is-core-module");require("minimatch");const r={plugins:{perfectionist:e},rules:e.configs["recommended-alphabetical"].rules};module.exports=r;
@@ -2,12 +2,14 @@ import e from "../index.mjs";
2
2
  import "@typescript-eslint/types";
3
3
  import "@typescript-eslint/utils";
4
4
  import "natural-compare-lite";
5
- const m = {
5
+ import "is-core-module";
6
+ import "minimatch";
7
+ const l = {
6
8
  plugins: {
7
9
  perfectionist: e
8
10
  },
9
11
  rules: e.configs["recommended-alphabetical"].rules
10
12
  };
11
13
  export {
12
- m as default
14
+ l as default
13
15
  };
@@ -1 +1 @@
1
- "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-line-length"].rules};module.exports=r;
1
+ "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");require("is-core-module");require("minimatch");const r={plugins:{perfectionist:e},rules:e.configs["recommended-line-length"].rules};module.exports=r;
@@ -2,12 +2,14 @@ import e from "../index.mjs";
2
2
  import "@typescript-eslint/types";
3
3
  import "@typescript-eslint/utils";
4
4
  import "natural-compare-lite";
5
- const m = {
5
+ import "is-core-module";
6
+ import "minimatch";
7
+ const p = {
6
8
  plugins: {
7
9
  perfectionist: e
8
10
  },
9
11
  rules: e.configs["recommended-line-length"].rules
10
12
  };
11
13
  export {
12
- m as default
14
+ p as default
13
15
  };
@@ -1 +1 @@
1
- "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");const r={plugins:{perfectionist:e},rules:e.configs["recommended-natural"].rules};module.exports=r;
1
+ "use strict";const e=require("../index.js");require("@typescript-eslint/types");require("@typescript-eslint/utils");require("natural-compare-lite");require("is-core-module");require("minimatch");const r={plugins:{perfectionist:e},rules:e.configs["recommended-natural"].rules};module.exports=r;
@@ -2,12 +2,14 @@ import r from "../index.mjs";
2
2
  import "@typescript-eslint/types";
3
3
  import "@typescript-eslint/utils";
4
4
  import "natural-compare-lite";
5
- const i = {
5
+ import "is-core-module";
6
+ import "minimatch";
7
+ const n = {
6
8
  plugins: {
7
9
  perfectionist: r
8
10
  },
9
11
  rules: r.configs["recommended-natural"].rules
10
12
  };
11
13
  export {
12
- i as default
14
+ n as default
13
15
  };
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
- "use strict";const u=require("@typescript-eslint/types"),Y=require("@typescript-eslint/utils"),C=require("natural-compare-lite"),L="eslint-plugin-perfectionist",M="azat-io/eslint-plugin-perfectionist";let g=Y.ESLintUtils.RuleCreator(a=>`https://github.com/${M}/blob/main/docs/rules/${a}.md`),y=a=>{let[l,d]=a;return d-l};var s=(a=>(a.alphabetical="alphabetical",a.natural="natural",a["line-length"]="line-length",a))(s||{}),n=(a=>(a.asc="asc",a.desc="desc",a))(n||{});let m=(a,l,d)=>{let p=d.order==="asc"?1:-1,o;return d.type===s.alphabetical?o=(t,e)=>t.name.localeCompare(e.name):d.type===s.natural?o=(t,e)=>C(t.name,e.name):o=(t,e)=>t.size-e.size,p*o(a,l)>0},E=(a,l,d,p)=>{let o=[...d].sort((e,r)=>Number(m(e,r,p))||-1);p.spreadLast&&o.forEach((e,r)=>{e.node.type===u.AST_NODE_TYPES.SpreadElement&&o.push(o.splice(r,1).at(0))});let t=e=>[e.range.at(0),e.range.at(1)];return d.map(({node:e},r)=>a.replaceTextRange(t(e),l.slice(...t(o[r].node))))},h=(a={},l)=>Object.assign(l,a);const T="sort-array-includes",$=g({name:T,meta:{type:"suggestion",docs:{description:"Enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc},spreadLast:{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.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 d=h(a.options.at(0),{type:s.alphabetical,order:n.asc,spreadLast:!1}),p=l.object.type===u.AST_NODE_TYPES.ArrayExpression?l.object.elements:l.object.arguments;if(p.length>1){let o=a.getSourceCode().text,t=p.reduce((e,r)=>(r===null||e.at(0).push({name:r.type===u.AST_NODE_TYPES.Literal?r.raw:o.slice(...r.range),size:y(r.range),type:r.type,node:r}),e),[[],[]]).flat();for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e),c;d.spreadLast&&r.node.type===u.AST_NODE_TYPES.Literal&&i.node.type===u.AST_NODE_TYPES.SpreadElement?c=!1:d.spreadLast&&r.node.type===u.AST_NODE_TYPES.SpreadElement&&i.node.type===u.AST_NODE_TYPES.Literal?c=!0:c=m(r,i,d),c&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{first:r.name,second:i.name},node:i.node,fix:f=>{let b=a.getSourceCode(),{text:S}=b;return E(f,S,t,d)}})}}}}})}),_="sort-interfaces",R=g({name:_,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({TSInterfaceBody:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.body.length>1){let p=a.getSourceCode().text,o=l.body.map(t=>{var r,i,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 f;if((r=t.typeAnnotation)!=null&&r.range.at(0))f=t.typeAnnotation.range.at(0);else{let b=t.optional?1:0;f=t.range.at(1)-b}e=p.slice(t.range.at(0),f)}else t.type===u.AST_NODE_TYPES.TSIndexSignature?e=p.slice(t.range.at(0),((i=t.typeAnnotation)==null?void 0:i.range.at(0))??t.range.at(1)):e=p.slice(t.range.at(0),((c=t.returnType)==null?void 0:c.range.at(0))??t.range.at(1));return{size:y(t.range),node:t,name:e}});for(let t=1;t<o.length;t++){let e=o.at(t-1),r=o.at(t);if(m(e,r,d)){let i=l.body[t];a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{first:e.name,second:r.name},node:i,fix:c=>E(c,p,o,d)})}}}}})}),x="sort-jsx-props",U=g({name:x,meta:{type:"suggestion",docs:{description:"Enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({JSXElement:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});l.openingElement.attributes.reduce((o,t)=>(t.type==="JSXAttribute"?o.at(-1).push(t):o.push([]),o),[[]]).forEach(o=>{let t=o.map(e=>({name:e.name.type===u.AST_NODE_TYPES.JSXNamespacedName?`${e.name.namespace.name}:${e.name.name.name}`:e.name.name,size:y(e.range),node:e}));for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e);m(r,i,d)&&a.report({messageId:"unexpectedJSXPropsOrder",data:{first:r.name,second:i.name},node:i.node,fix:c=>{let f=a.getSourceCode().text;return E(c,f,t,d)}})}})}})}),N="sort-map-elements",k=g({name:N,meta:{type:"suggestion",docs:{description:"Enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({NewExpression:l=>{if(l.callee.type===u.AST_NODE_TYPES.Identifier&&l.callee.name==="Map"&&l.arguments[0].type===u.AST_NODE_TYPES.ArrayExpression){let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),[{elements:p}]=l.arguments,o=a.getSourceCode().text;p.length>1&&p.reduce((e,r)=>(r===null||r.type===u.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(r),e),[[]]).forEach(e=>{let r=e.map(i=>{let c;if(i.type===u.AST_NODE_TYPES.ArrayExpression){let[f]=i.elements;f?f.type===u.AST_NODE_TYPES.Literal?c=f.raw:c=o.slice(...f.range):c=`${f}`}else c=o.slice(...i.range);return{size:y(i.range),node:i,name:c}});for(let i=1;i<r.length;i++){let c=r.at(i-1),f=r.at(i);m(c,f,d)&&a.report({messageId:"unexpectedMapElementsOrder",data:{first:c.name,second:f.name},node:f.node,fix:b=>{let S=a.getSourceCode(),{text:I}=S;return E(b,I,r,d)}})}})}}})}),A="sort-named-exports",z=g({name:A,meta:{type:"suggestion",docs:{description:"Enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ExportNamedDeclaration:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.specifiers.length>1){let p=l.specifiers.map(o=>{let{range:t,local:{name:e}}=o;return{size:y(t),node:o,name:e}});for(let o=1;o<p.length;o++){let t=p.at(o-1),e=p.at(o);if(m(t,e,d)){let r=l.specifiers[o];a.report({messageId:"unexpectedNamedExportsOrder",data:{first:t.name,second:e.name},node:r,fix:i=>{let c=a.getSourceCode(),{text:f}=c;return E(i,f,p,d)}})}}}}})}),P="sort-named-imports",v=g({name:P,meta:{type:"suggestion",docs:{description:"Enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ImportDeclaration:l=>{let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc});if(l.specifiers.length>1){let p=l.specifiers.map(o=>{let{range:t,local:{name:e}}=o;return{size:y(t),node:o,name:e}});for(let o=1;o<p.length;o++){let t=p.at(o-1),e=p.at(o);if(m(t,e,d)){let r=l.specifiers[o];a.report({messageId:"unexpectedNamedImportsOrder",data:{first:t.name,second:e.name},node:r,fix:i=>{let c=a.getSourceCode(),{text:f}=c;return E(i,f,p,d)}})}}}}})}),D="sort-object-keys",J=g({name:D,meta:{type:"suggestion",docs:{description:"Enforce sorted object keys",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedObjectKeysOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({ObjectExpression:l=>{if(l.properties.length>1){let d=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),p=a.getSourceCode().text;(t=>t.reduce((e,r)=>{if(r.type===u.AST_NODE_TYPES.SpreadElement)return e.push([]),e;let i;r.key.type===u.AST_NODE_TYPES.Identifier?{name:i}=r.key:r.key.type===u.AST_NODE_TYPES.Literal?i=`${r.key.value}`:i=p.slice(...r.key.range);let c={size:y(r.range),node:r,name:i};return e.at(-1).push(c),e},[[]]))(l.properties).forEach(t=>{if(t.length>1)for(let e=1;e<t.length;e++){let r=t.at(e-1),i=t.at(e);m(r,i,d)&&a.report({messageId:"unexpectedObjectKeysOrder",data:{first:r.name,second:i.name},node:i.node,fix:c=>E(c,p,t,d)})}})}}})}),j="sort-union-types",X=g({name:j,meta:{type:"suggestion",docs:{description:"Enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[s.alphabetical,s.natural,s["line-length"]],default:s.natural},order:{enum:[n.asc,n.desc],default:n.asc}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:s.alphabetical,order:n.asc}],create:a=>({TSUnionType:l=>{let d=a.getSourceCode().text,p=h(a.options.at(0),{type:s.alphabetical,order:n.asc}),o=l.types.map(t=>{let{range:e}=t,r=d.slice(...e);return{size:y(e),node:t,name:r}});for(let t=1;t<o.length;t++){let e=o.at(t-1),r=o.at(t);if(m(e,r,p)){let i=l.types[t];a.report({messageId:"unexpectedUnionTypesOrder",data:{first:e.name,second:r.name},node:i,fix:c=>{let f=a.getSourceCode(),{text:b}=f;return E(c,b,o,p)}})}}}})});let O=a=>{let l={[T]:["error",{spreadLast:!0}],[_]:["error"],[x]:["error"],[N]:["error"],[A]:["error"],[P]:["error"],[D]:["error"],[j]:["error"]};return{plugins:["perfectionist"],rules:Object.fromEntries(Object.entries(l).map(([d,[p,o={}]])=>[d,[p,Object.assign(o,a)]]))}};const w={name:L,rules:{[T]:$,[_]:R,[x]:U,[N]:k,[A]:z,[P]:v,[D]:J,[j]:X},configs:{"recommended-alphabetical":O({type:s.alphabetical,order:n.asc}),"recommended-natural":O({type:s.natural,order:n.asc}),"recommended-line-length":O({type:s["line-length"],order:n.desc})}};module.exports=w;
1
+ "use strict";const m=require("@typescript-eslint/types"),U=require("@typescript-eslint/utils"),k=require("natural-compare-lite"),z=require("is-core-module"),B=require("minimatch");let h=U.ESLintUtils.RuleCreator(a=>`https://eslint-plugin-perfectionist.azat.io/rules/${a}`),S=a=>{let[o,s]=a;return s-o};var n=(a=>(a.alphabetical="alphabetical",a.natural="natural",a["line-length"]="line-length",a))(n||{}),i=(a=>(a.asc="asc",a.desc="desc",a))(i||{});let J=(a,o)=>{let s=o.getTokenBefore(a,{includeComments:!0});return(s==null?void 0:s.type)===m.AST_TOKEN_TYPES.Block||(s==null?void 0:s.type)===m.AST_TOKEN_TYPES.Line?s:null},_=(a,o)=>{let s=J(a,o);return[(s==null?void 0:s.range.at(0))??a.range.at(0),a.range.at(1)]},b=(a,o,s)=>{let l=s.order==="asc"?1:-1,p;return s.type===n.alphabetical?p=(t,e)=>t.name.localeCompare(e.name):s.type===n.natural?p=(t,e)=>k(t.name,e.name):p=(t,e)=>t.size-e.size,l*p(a,o)>0},O=(a,{options:o,source:s,nodes:l})=>{let p=[...l].sort((t,e)=>Number(b(t,e,o))||-1);return o.spreadLast&&p.forEach((t,e)=>{t.node.type===m.AST_NODE_TYPES.SpreadElement&&p.push(p.splice(e,1).at(0))}),l.map(({node:t},e)=>a.replaceTextRange(_(t,s),s.text.slice(..._(p[e].node,s))))},x=(a={},o)=>Object.assign(o,a),T=(a,o)=>{if(a.length>1)for(let s=1;s<a.length;s++){let l=a.at(s-1),p=a.at(s);l&&p&&o(l,p)}};const w="sort-array-includes",q=h({name:w,meta:{type:"suggestion",docs:{description:"Enforce sorted arrays before include method",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc},spreadLast:{type:"boolean",default:!1}},additionalProperties:!1}],messages:{unexpectedArrayIncludesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({MemberExpression:o=>{if((o.object.type===m.AST_NODE_TYPES.ArrayExpression||o.object.type===m.AST_NODE_TYPES.NewExpression)&&o.property.type===m.AST_NODE_TYPES.Identifier&&o.property.name==="includes"){let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc,spreadLast:!1}),l=o.object.type===m.AST_NODE_TYPES.ArrayExpression?o.object.elements:o.object.arguments;if(l.length>1){let p=a.getSourceCode(),t=l.reduce((e,r)=>(r===null||e.at(0).push({name:r.type===m.AST_NODE_TYPES.Literal?r.raw:p.text.slice(...r.range),size:S(r.range),type:r.type,node:r}),e),[[],[]]).flat();T(t,(e,r)=>{let u;s.spreadLast&&e.node.type===m.AST_NODE_TYPES.Literal&&r.node.type===m.AST_NODE_TYPES.SpreadElement?u=!1:s.spreadLast&&e.node.type===m.AST_NODE_TYPES.SpreadElement&&r.node.type===m.AST_NODE_TYPES.Literal?u=!0:u=b(e,r,s),u&&a.report({messageId:"unexpectedArrayIncludesOrder",data:{first:e.name,second:r.name},node:r.node,fix:d=>O(d,{options:s,source:p,nodes:t})})})}}}})}),I="sort-enums",K=h({name:I,meta:{type:"suggestion",docs:{description:"Enforce sorted TypeScript enums",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedEnumsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({TSEnumDeclaration:o=>{let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc});if(o.members.length>1){let l=a.getSourceCode(),p=o.members.map(t=>{let e;return t.id.type===m.AST_NODE_TYPES.Literal?e=`${t.id.value}`:e=`${l.text.slice(...t.id.range)}`,{size:S(t.range),node:t,name:e}});T(p,(t,e)=>{b(t,e,s)&&a.report({messageId:"unexpectedEnumsOrder",data:{first:t.name,second:e.name},node:e.node,fix:r=>O(r,{options:s,source:l,nodes:p})})})}}})}),D="sort-imports",X=h({name:D,meta:{type:"suggestion",docs:{description:"Enforce sorted imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc},groups:{type:"array",default:[]},"internal-pattern":{type:"array",default:["~/**"]},"newlines-between":{enum:["ignore","always","never"],default:"always"}},additionalProperties:!1}],messages:{unexpectedImportsOrder:'Expected "{{second}}" to come before "{{first}}"',missedSpacingBetweenImports:'Missed spacing between "{{first}}" and "{{second}}" imports',extraSpacingBetweenImports:'Extra spacing between "{{first}}" and "{{second}}" imports'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>{let o=x(a.options.at(0),{"newlines-between":"always","internal-pattern":["~/**"],type:n.alphabetical,order:i.asc,groups:["unknown"]}),s=a.getSourceCode(),l=[],p=e=>{let r,u=f=>["./index.d.js","./index.d.ts","./index.js","./index.ts","./index","./","."].includes(f),d=f=>/^\.\.$|^\.\.[/\\]/.test(f),c=f=>/^\.[/\\]/.test(f),g=f=>{!r&&o.groups.flat().includes(f)&&(r=f)},E=f=>o["internal-pattern"].length&&o["internal-pattern"].some(y=>B.minimatch(f.source.value,y));return e.importKind==="type"&&(e.type===m.AST_NODE_TYPES.ImportDeclaration&&(E(e)?g("internal-type"):u(e.source.value)?g("index-type"):d(e.source.value)?g("parent-type"):c(e.source.value)&&g("sibling-type")),g("type")),!r&&e.type===m.AST_NODE_TYPES.ImportDeclaration&&(z(e.source.value)?g("builtin"):E(e)?g("internal"):u(e.source.value)?g("index"):d(e.source.value)?g("parent"):c(e.source.value)?g("sibling"):g("external")),r??"unknown"},t=e=>{let r;e.type===m.AST_NODE_TYPES.ImportDeclaration?r=e.source.value:e.moduleReference.type===m.AST_NODE_TYPES.TSExternalModuleReference&&e.moduleReference.expression.type===m.AST_NODE_TYPES.Literal?r=`${e.moduleReference.expression.value}`:r=s.text.slice(...e.moduleReference.range),l.push({size:S(e.range),group:p(e),name:r,node:e})};return{TSImportEqualsDeclaration:t,ImportDeclaration:t,"Program:exit":()=>{let e=d=>{for(let c=0,g=o.groups.length;c<g;c++){let E=o.groups[c];if(d.group===E||Array.isArray(E)&&E.includes(d.group))return c}return o.groups.length},r=(d,c)=>s.lines.slice(d.node.loc.end.line,c.node.loc.start.line-1).filter(E=>!E.trim().length).length,u=d=>{let c=[],g=l.reduce((f,y)=>{let N=e(y);return N in f?f[N]=[...f[N],y].sort((A,C)=>Number(b(A,C,o))||-1):f[N]=[y],f},{}),E=Object.keys(g).sort().reduce((f,y)=>[...f,...g[y]],[]);return E.forEach((f,y)=>{if(c.push(d.replaceTextRange(_(l.at(y).node,s),s.text.slice(..._(f.node,s)))),o["newlines-between"]!=="ignore"){let N=E.at(y+1);if(N){let A=r(l.at(y),l.at(y+1));(o["newlines-between"]==="always"&&e(f)===e(N)&&A!==0||o["newlines-between"]==="never"&&A>0)&&c.push(d.removeRange([_(l.at(y).node,s).at(1),_(l.at(y+1).node,s).at(0)-1])),o["newlines-between"]==="always"&&A>1&&c.push(d.replaceTextRange([_(l.at(y).node,s).at(1),_(l.at(y+1).node,s).at(0)-1],`
2
+ `)),o["newlines-between"]==="always"&&e(f)!==e(N)&&A===0&&c.push(d.insertTextAfterRange(_(l.at(y).node,s),`
3
+ `))}}}),c};T(l,(d,c)=>{let g=e(d),E=e(c),f=r(d,c);(g>E||g===E&&b(d,c,o))&&a.report({messageId:"unexpectedImportsOrder",data:{first:d.name,second:c.name},node:c.node,fix:u}),o["newlines-between"]==="never"&&f>0&&a.report({messageId:"extraSpacingBetweenImports",data:{first:d.name,second:c.name},node:c.node,fix:u}),o["newlines-between"]==="always"&&(g<E&&f===0?a.report({messageId:"missedSpacingBetweenImports",data:{first:d.name,second:c.name},node:c.node,fix:u}):(f>1||g===E&&f>0)&&a.report({messageId:"extraSpacingBetweenImports",data:{first:d.name,second:c.name},node:c.node,fix:u}))})}}}}),Y="sort-interfaces",G=h({name:Y,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedInterfacePropertiesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({TSInterfaceBody:o=>{let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc});if(o.body.length>1){let l=a.getSourceCode(),p=o.body.map(t=>{var r,u,d;let e;if(t.type===m.AST_NODE_TYPES.TSPropertySignature)if(t.key.type===m.AST_NODE_TYPES.Identifier)({name:e}=t.key);else if(t.key.type===m.AST_NODE_TYPES.Literal)e=`${t.key.value}`;else{let c;if((r=t.typeAnnotation)!=null&&r.range.at(0))c=t.typeAnnotation.range.at(0);else{let g=t.optional?1:0;c=t.range.at(1)-g}e=l.text.slice(t.range.at(0),c)}else t.type===m.AST_NODE_TYPES.TSIndexSignature?e=l.text.slice(t.range.at(0),((u=t.typeAnnotation)==null?void 0:u.range.at(0))??t.range.at(1)):e=l.text.slice(t.range.at(0),((d=t.returnType)==null?void 0:d.range.at(0))??t.range.at(1));return{size:S(t.range),node:t,name:e}});T(p,(t,e)=>{b(t,e,s)&&a.report({messageId:"unexpectedInterfacePropertiesOrder",data:{first:t.name,second:e.name},node:e.node,fix:r=>O(r,{options:s,source:l,nodes:p})})})}}})}),j="sort-jsx-props",F=h({name:j,meta:{type:"suggestion",docs:{description:"Enforce sorted JSX props",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedJSXPropsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({JSXElement:o=>{let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc}),l=a.getSourceCode();o.openingElement.attributes.reduce((t,e)=>(e.type==="JSXAttribute"?t.at(-1).push(e):t.push([]),t),[[]]).forEach(t=>{let e=t.map(r=>({name:r.name.type===m.AST_NODE_TYPES.JSXNamespacedName?`${r.name.namespace.name}:${r.name.name.name}`:r.name.name,size:S(r.range),node:r}));T(e,(r,u)=>{b(r,u,s)&&a.report({messageId:"unexpectedJSXPropsOrder",data:{first:r.name,second:u.name},node:u.node,fix:d=>O(d,{options:s,source:l,nodes:e})})})})}})}),L="sort-map-elements",V=h({name:L,meta:{type:"suggestion",docs:{description:"Enforce sorted Map elements",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedMapElementsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({NewExpression:o=>{if(o.callee.type===m.AST_NODE_TYPES.Identifier&&o.callee.name==="Map"&&o.arguments[0].type===m.AST_NODE_TYPES.ArrayExpression){let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc}),[{elements:l}]=o.arguments,p=a.getSourceCode();l.length>1&&l.reduce((e,r)=>(r===null||r.type===m.AST_NODE_TYPES.SpreadElement?e.push([]):e.at(-1).push(r),e),[[]]).forEach(e=>{let r=e.map(u=>{let d;if(u.type===m.AST_NODE_TYPES.ArrayExpression){let[c]=u.elements;c?c.type===m.AST_NODE_TYPES.Literal?d=c.raw:d=p.text.slice(...c.range):d=`${c}`}else d=p.text.slice(...u.range);return{size:S(u.range),node:u,name:d}});T(r,(u,d)=>{b(u,d,s)&&a.report({messageId:"unexpectedMapElementsOrder",data:{first:u.name,second:d.name},node:d.node,fix:c=>O(c,{options:s,source:p,nodes:r})})})})}}})}),R="sort-named-exports",W=h({name:R,meta:{type:"suggestion",docs:{description:"Enforce sorted named exports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedNamedExportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({ExportNamedDeclaration:o=>{let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc});if(o.specifiers.length>1){let l=a.getSourceCode(),p=o.specifiers.map(t=>{let{range:e,local:{name:r}}=t;return{size:S(e),node:t,name:r}});T(p,(t,e)=>{b(t,e,s)&&a.report({messageId:"unexpectedNamedExportsOrder",data:{first:t.name,second:e.name},node:e.node,fix:r=>O(r,{options:s,source:l,nodes:p})})})}}})}),$="sort-named-imports",H=h({name:$,meta:{type:"suggestion",docs:{description:"Enforce sorted named imports",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedNamedImportsOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({ImportDeclaration:o=>{let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc});if(o.specifiers.length>1){let l=a.getSourceCode(),p=o.specifiers.map(t=>{let{range:e,local:{name:r}}=t;return{size:S(e),node:t,name:r}});T(p,(t,e)=>{b(t,e,s)&&a.report({messageId:"unexpectedNamedImportsOrder",data:{first:t.name,second:e.name},node:e.node,fix:r=>O(r,{options:s,source:l,nodes:p})})})}}})}),M="sort-object-keys",Q=h({name:M,meta:{type:"suggestion",docs:{description:"Enforce sorted object keys",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedObjectKeysOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({ObjectExpression:o=>{if(o.properties.length>1){let s=x(a.options.at(0),{type:n.alphabetical,order:i.asc}),l=a.getSourceCode();(t=>t.reduce((e,r)=>{if(r.type===m.AST_NODE_TYPES.SpreadElement)return e.push([]),e;let u;r.key.type===m.AST_NODE_TYPES.Identifier?{name:u}=r.key:r.key.type===m.AST_NODE_TYPES.Literal?u=`${r.key.value}`:u=l.text.slice(...r.key.range);let d={size:S(r.range),node:r,name:u};return e.at(-1).push(d),e},[[]]))(o.properties).forEach(t=>{T(t,(e,r)=>{b(e,r,s)&&a.report({messageId:"unexpectedObjectKeysOrder",data:{first:e.name,second:r.name},node:r.node,fix:u=>O(u,{options:s,source:l,nodes:t})})})})}}})}),v="sort-union-types",Z=h({name:v,meta:{type:"suggestion",docs:{description:"Enforce sorted union types",recommended:!1},fixable:"code",schema:[{type:"object",properties:{type:{enum:[n.alphabetical,n.natural,n["line-length"]],default:n.natural},order:{enum:[i.asc,i.desc],default:i.asc}},additionalProperties:!1}],messages:{unexpectedUnionTypesOrder:'Expected "{{second}}" to come before "{{first}}"'}},defaultOptions:[{type:n.alphabetical,order:i.asc}],create:a=>({TSUnionType:o=>{let s=a.getSourceCode(),l=x(a.options.at(0),{type:n.alphabetical,order:i.asc}),p=o.types.map(t=>({size:S(t.range),node:t,name:s.text.slice(...t.range)}));T(p,(t,e)=>{b(t,e,l)&&a.report({messageId:"unexpectedUnionTypesOrder",data:{first:t.name,second:e.name},node:e.node,fix:r=>O(r,{options:l,source:s,nodes:p})})})}})}),ee="eslint-plugin-perfectionist";let P=a=>{let o={[w]:["error",{spreadLast:!0}],[I]:["error"],[D]:["error",{order:["type",["builtin","external"],"internal-type","internal",["parent-type","sibling-type","index-type"],["parent","sibling","index"],"object","unknown"],"newlines-between":"always","internal-pattern":["~/**"]}],[Y]:["error"],[j]:["error"],[L]:["error"],[R]:["error"],[$]:["error"],[M]:["error"],[v]:["error"]};return{plugins:["perfectionist"],rules:Object.fromEntries(Object.entries(o).map(([s,[l,p={}]])=>[`perfectionist/${s}`,[l,Object.assign(p,a)]]))}};const te={name:ee,rules:{[w]:q,[I]:K,[D]:X,[Y]:G,[j]:F,[L]:V,[R]:W,[$]:H,[M]:Q,[v]:Z},configs:{"recommended-alphabetical":P({type:n.alphabetical,order:i.asc}),"recommended-natural":P({type:n.natural,order:i.asc}),"recommended-line-length":P({type:n["line-length"],order:i.desc})}};module.exports=te;