eslint-plugin-absolute 0.2.7 → 0.2.8

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,160 +0,0 @@
1
- import { TSESLint, TSESTree } from "@typescript-eslint/utils";
2
-
3
- type Options = [];
4
- type MessageIds =
5
- | "firstMustEndWithSprings"
6
- | "firstMustHaveBase"
7
- | "secondMustMatch"
8
- | "pluralRequired";
9
-
10
- const SPRINGS_SUFFIX = "Springs";
11
-
12
- const checkUseSpring = (
13
- context: TSESLint.RuleContext<MessageIds, Options>,
14
- firstElem: TSESTree.Identifier,
15
- secondElem: TSESTree.Identifier
16
- ) => {
17
- const firstName = firstElem.name;
18
- const secondName = secondElem.name;
19
-
20
- if (!firstName.endsWith(SPRINGS_SUFFIX)) {
21
- context.report({
22
- messageId: "firstMustEndWithSprings",
23
- node: firstElem
24
- });
25
- return;
26
- }
27
-
28
- const base = firstName.slice(0, -SPRINGS_SUFFIX.length);
29
- if (!base) {
30
- context.report({
31
- messageId: "firstMustHaveBase",
32
- node: firstElem
33
- });
34
- return;
35
- }
36
-
37
- const expectedSecond = `${base}Api`;
38
- if (secondName !== expectedSecond) {
39
- context.report({
40
- data: { expected: expectedSecond },
41
- messageId: "secondMustMatch",
42
- node: secondElem
43
- });
44
- }
45
- };
46
-
47
- const checkUseSprings = (
48
- context: TSESLint.RuleContext<MessageIds, Options>,
49
- firstElem: TSESTree.Identifier,
50
- secondElem: TSESTree.Identifier
51
- ) => {
52
- const firstName = firstElem.name;
53
- const secondName = secondElem.name;
54
-
55
- if (!firstName.endsWith(SPRINGS_SUFFIX)) {
56
- context.report({
57
- messageId: "firstMustEndWithSprings",
58
- node: firstElem
59
- });
60
- return;
61
- }
62
-
63
- const basePlural = firstName.slice(0, -SPRINGS_SUFFIX.length);
64
- if (!basePlural) {
65
- context.report({
66
- messageId: "firstMustHaveBase",
67
- node: firstElem
68
- });
69
- return;
70
- }
71
-
72
- if (!basePlural.endsWith("s")) {
73
- context.report({
74
- messageId: "pluralRequired",
75
- node: firstElem
76
- });
77
- return;
78
- }
79
-
80
- const expectedSecond = `${basePlural}Api`;
81
- if (secondName !== expectedSecond) {
82
- context.report({
83
- data: { expected: expectedSecond },
84
- messageId: "secondMustMatch",
85
- node: secondElem
86
- });
87
- }
88
- };
89
-
90
- export const springNamingConvention: TSESLint.RuleModule<MessageIds, Options> =
91
- {
92
- create(context) {
93
- return {
94
- VariableDeclarator(node: TSESTree.VariableDeclarator) {
95
- const { init } = node;
96
-
97
- if (
98
- !init ||
99
- init.type !== "CallExpression" ||
100
- init.callee.type !== "Identifier"
101
- ) {
102
- return;
103
- }
104
-
105
- const hookName = init.callee.name;
106
- if (hookName !== "useSpring" && hookName !== "useSprings") {
107
- return;
108
- }
109
-
110
- if (node.id.type !== "ArrayPattern") {
111
- return;
112
- }
113
-
114
- const { elements } = node.id;
115
- if (elements.length < 2) {
116
- return;
117
- }
118
-
119
- const [firstElem, secondElem] = elements;
120
-
121
- if (
122
- !firstElem ||
123
- firstElem.type !== "Identifier" ||
124
- !secondElem ||
125
- secondElem.type !== "Identifier"
126
- ) {
127
- return;
128
- }
129
-
130
- if (hookName === "useSpring") {
131
- checkUseSpring(context, firstElem, secondElem);
132
- return;
133
- }
134
-
135
- if (hookName === "useSprings") {
136
- checkUseSprings(context, firstElem, secondElem);
137
- }
138
- }
139
- };
140
- },
141
- defaultOptions: [],
142
- meta: {
143
- docs: {
144
- description:
145
- "Enforce correct naming for useSpring and useSprings hook destructuring"
146
- },
147
- messages: {
148
- firstMustEndWithSprings:
149
- "The first variable must end with 'Springs'.",
150
- firstMustHaveBase:
151
- "The first variable must have a non-empty name before 'Springs'.",
152
- pluralRequired:
153
- "The first variable for useSprings should be plural (ending with 's') before 'Springs'.",
154
- secondMustMatch:
155
- "The second variable must be named '{{expected}}'."
156
- },
157
- schema: [],
158
- type: "problem"
159
- }
160
- };
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "forceConsistentCasingInFileNames": true,
5
- "incremental": true,
6
- "jsx": "react-jsx",
7
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
8
- "module": "ESNext",
9
- "moduleResolution": "bundler",
10
- "noUncheckedIndexedAccess": true,
11
- "skipLibCheck": true,
12
- "strict": true,
13
- "target": "ESNext",
14
- "tsBuildInfoFile": ".absolutejs/tsconfig.tsbuildinfo",
15
- "types": ["bun-types"]
16
- }
17
- }