eslint-plugin-perfectionist 0.1.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.
@@ -0,0 +1 @@
1
+ "use strict";const g=require("@typescript-eslint/types"),y=require("@typescript-eslint/utils"),I="eslint-plugin-perfectionist",_="azat-io/eslint-plugin-perfectionist";let b=y.ESLintUtils.RuleCreator(f=>`https://github.com/${_}/blob/main/docs/rules/${f}.md`);const T="sort-interfaces",A=b({name:T,meta:{type:"suggestion",docs:{description:"Enforce sorted interface properties",recommended:!1},messages:{unexpectedInterfacePropertiesOrder:'Expected "{{second}}" to come before "{{first}}"'},fixable:"code",schema:[]},defaultOptions:[],create:f=>({TSInterfaceBody:S=>{let x=S.body.map(t=>{let a="",l=0,n=e=>{l+=e},i=e=>{let[r,o]=e;return o-r},u=e=>{n(i(e.key.range))},p=e=>{let{length:r}="[]";n(e.parameters.reduce((o,{range:m})=>o+i(m),r))},c=e=>{if(e.optional){let{length:r}="?";n(r)}},d=e=>{var o;let r=(o=e.typeAnnotation)==null?void 0:o.range;r&&n(i(r))},s=e=>{if(e.type===g.AST_NODE_TYPES.Identifier)({name:a}=e);else if(e.type===g.AST_NODE_TYPES.TSIndexSignature){let r=e.parameters.at(0);r&&s(r)}};return t.type===g.AST_NODE_TYPES.TSPropertySignature?(s(t.key),u(t),c(t),d(t)):t.type===g.AST_NODE_TYPES.TSIndexSignature&&(s(t),p(t),d(t)),{name:a,size:l}});for(let t=1;t<x.length;t++){let a=t-1,l=t,n=x.at(a),i=x.at(l);if(n.size<i.size){let u=f.getSourceCode(),p=S.body[a],c=S.body[l];f.report({messageId:"unexpectedInterfacePropertiesOrder",data:{first:n.name,second:i.name},node:c,fix:d=>{let s=r=>[r.range.at(0),r.range.at(1)];return[d.replaceTextRange(s(p),u.text.slice(...s(c))),d.replaceTextRange(s(c),u.text.slice(...s(p)))]}})}}}})}),O={name:I,rules:{[T]:A}};module.exports=O;
@@ -0,0 +1,102 @@
1
+ import { AST_NODE_TYPES as u } from "@typescript-eslint/types";
2
+ import { ESLintUtils as y } from "@typescript-eslint/utils";
3
+ const T = "eslint-plugin-perfectionist", b = "azat-io/eslint-plugin-perfectionist";
4
+ let R = y.RuleCreator(
5
+ (f) => `https://github.com/${b}/blob/main/docs/rules/${f}.md`
6
+ );
7
+ const S = "sort-interfaces", h = R({
8
+ name: S,
9
+ meta: {
10
+ type: "suggestion",
11
+ docs: {
12
+ description: "Enforce sorted interface properties",
13
+ recommended: !1
14
+ },
15
+ messages: {
16
+ unexpectedInterfacePropertiesOrder: 'Expected "{{second}}" to come before "{{first}}"'
17
+ },
18
+ fixable: "code",
19
+ schema: []
20
+ },
21
+ defaultOptions: [],
22
+ create: (f) => ({
23
+ TSInterfaceBody: (m) => {
24
+ let x = m.body.map((t) => {
25
+ let i = "", l = 0, n = (e) => {
26
+ l += e;
27
+ }, o = (e) => {
28
+ let [r, a] = e;
29
+ return a - r;
30
+ }, p = (e) => {
31
+ n(o(e.key.range));
32
+ }, g = (e) => {
33
+ let { length: r } = "[]";
34
+ n(
35
+ e.parameters.reduce(
36
+ (a, { range: I }) => a + o(I),
37
+ r
38
+ )
39
+ );
40
+ }, c = (e) => {
41
+ if (e.optional) {
42
+ let { length: r } = "?";
43
+ n(r);
44
+ }
45
+ }, d = (e) => {
46
+ var a;
47
+ let r = (a = e.typeAnnotation) == null ? void 0 : a.range;
48
+ r && n(o(r));
49
+ }, s = (e) => {
50
+ if (e.type === u.Identifier)
51
+ ({ name: i } = e);
52
+ else if (e.type === u.TSIndexSignature) {
53
+ let r = e.parameters.at(0);
54
+ r && s(r);
55
+ }
56
+ };
57
+ return t.type === u.TSPropertySignature ? (s(t.key), p(t), c(t), d(t)) : t.type === u.TSIndexSignature && (s(t), g(t), d(t)), {
58
+ name: i,
59
+ size: l
60
+ };
61
+ });
62
+ for (let t = 1; t < x.length; t++) {
63
+ let i = t - 1, l = t, n = x.at(i), o = x.at(l);
64
+ if (n.size < o.size) {
65
+ let p = f.getSourceCode(), g = m.body[i], c = m.body[l];
66
+ f.report({
67
+ messageId: "unexpectedInterfacePropertiesOrder",
68
+ data: {
69
+ first: n.name,
70
+ second: o.name
71
+ },
72
+ node: c,
73
+ fix: (d) => {
74
+ let s = (r) => [
75
+ r.range.at(0),
76
+ r.range.at(1)
77
+ ];
78
+ return [
79
+ d.replaceTextRange(
80
+ s(g),
81
+ p.text.slice(...s(c))
82
+ ),
83
+ d.replaceTextRange(
84
+ s(c),
85
+ p.text.slice(...s(g))
86
+ )
87
+ ];
88
+ }
89
+ });
90
+ }
91
+ }
92
+ }
93
+ })
94
+ }), z = {
95
+ name: T,
96
+ rules: {
97
+ [S]: h
98
+ }
99
+ };
100
+ export {
101
+ z as default
102
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "eslint-plugin-perfectionist",
3
+ "description": "ESLint plugin for code formatting in perfectionist style",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "repository": "azat-io/eslint-plugin-perfectionist",
7
+ "author": "Azat S. <to@azat.io>",
8
+ "license": "MIT",
9
+ "keywords": [
10
+ "eslint",
11
+ "eslint-plugin",
12
+ "perfectionist"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "./dist"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "require": "./dist/index.cjs.js",
23
+ "import": "./dist/index.es.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "peerDependencies": {
28
+ "eslint": "^8.39.0"
29
+ },
30
+ "dependencies": {
31
+ "@typescript-eslint/types": "^5.59.2",
32
+ "@typescript-eslint/utils": "^5.59.2"
33
+ }
34
+ }
package/readme.md ADDED
@@ -0,0 +1,35 @@
1
+ # ESLint Plugin Perfectionist
2
+
3
+ <img src="https://user-images.githubusercontent.com/5698350/234571772-9e0cf164-d6bd-46fa-91d3-9c6f2a83932c.svg" alt="ESLint" align="right" width="120" height="120" />
4
+
5
+ ![Version](https://img.shields.io/npm/v/eslint-plugin-perfectionist.svg?color=brightgreen)
6
+
7
+ ESLint plugin for code formatting in perfectionist style.
8
+
9
+ ## Installation
10
+
11
+ You'll first need to install [ESLint](https://eslint.org):
12
+
13
+ ```sh
14
+ npm install --save-dev eslint
15
+ ```
16
+
17
+ Next, install `eslint-plugin-perfectionist`:
18
+
19
+ ```sh
20
+ npm install --save-dev eslint-plugin-perfectionist
21
+ ```
22
+
23
+ ## Rules
24
+
25
+ | Name | Description | 💼 | 🔧 |
26
+ | :-------------- | :---------------------------------- | :-- | :-- |
27
+ | sort-interfaces | Enforce sorted interface properties | 💼 | 🔧 |
28
+
29
+ ## See also
30
+
31
+ - [`@azat-io/eslint-config`](https://github.com/azat-io/eslint-config) - Collection of ESLint configs
32
+
33
+ ## License
34
+
35
+ MIT &copy; [Azat S.](https://azat.io)