@codyswann/lisa 1.50.1 → 1.50.3

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.
Files changed (27) hide show
  1. package/dist/configs/eslint/expo.d.ts.map +1 -1
  2. package/dist/configs/eslint/expo.js +6 -3
  3. package/dist/configs/eslint/expo.js.map +1 -1
  4. package/dist/configs/eslint/typescript.d.ts.map +1 -1
  5. package/dist/configs/eslint/typescript.js +5 -2
  6. package/dist/configs/eslint/typescript.js.map +1 -1
  7. package/eslint-plugin-code-organization/README.md +149 -0
  8. package/eslint-plugin-code-organization/__tests__/enforce-statement-order.test.js +473 -0
  9. package/eslint-plugin-code-organization/index.js +28 -0
  10. package/eslint-plugin-code-organization/package.json +10 -0
  11. package/eslint-plugin-code-organization/rules/enforce-statement-order.js +162 -0
  12. package/eslint-plugin-component-structure/README.md +234 -0
  13. package/eslint-plugin-component-structure/__tests__/plugin-index.test.js +89 -0
  14. package/eslint-plugin-component-structure/__tests__/require-memo-in-view.test.js +201 -0
  15. package/eslint-plugin-component-structure/__tests__/single-component-per-file.test.js +294 -0
  16. package/eslint-plugin-component-structure/index.js +37 -0
  17. package/eslint-plugin-component-structure/package.json +10 -0
  18. package/eslint-plugin-component-structure/rules/enforce-component-structure.js +235 -0
  19. package/eslint-plugin-component-structure/rules/no-return-in-view.js +96 -0
  20. package/eslint-plugin-component-structure/rules/require-memo-in-view.js +183 -0
  21. package/eslint-plugin-component-structure/rules/single-component-per-file.js +243 -0
  22. package/eslint-plugin-ui-standards/README.md +192 -0
  23. package/eslint-plugin-ui-standards/index.js +31 -0
  24. package/eslint-plugin-ui-standards/package.json +10 -0
  25. package/eslint-plugin-ui-standards/rules/no-classname-outside-ui.js +56 -0
  26. package/eslint-plugin-ui-standards/rules/no-direct-rn-imports.js +60 -0
  27. package/package.json +5 -5
@@ -0,0 +1,473 @@
1
+ /**
2
+ * This file is managed by Lisa.
3
+ * Do not edit directly — changes will be overwritten on the next `lisa` run.
4
+ */
5
+
6
+ /* eslint-disable max-lines -- comprehensive test coverage requires extensive test cases */
7
+ /**
8
+ * Tests for enforce-statement-order ESLint rule
9
+ *
10
+ * Enforces the order: definitions → side effects → return
11
+ * 1. Definitions: const/let/var declarations, function declarations
12
+ * 2. Side effects: Expression statements that are function calls
13
+ * 3. Return statement
14
+ */
15
+ const { RuleTester } = require("eslint");
16
+
17
+ const rule = require("../rules/enforce-statement-order");
18
+
19
+ /** Message data constants for test assertions */
20
+ const DEFINITIONS = "Definitions";
21
+ const SIDE_EFFECTS = "Side effects";
22
+ const RETURN_STATEMENT = "Return statement";
23
+
24
+ const ruleTester = new RuleTester({
25
+ languageOptions: {
26
+ ecmaVersion: 2020,
27
+ sourceType: "module",
28
+ parserOptions: {
29
+ ecmaFeatures: {
30
+ jsx: true,
31
+ },
32
+ },
33
+ },
34
+ });
35
+
36
+ ruleTester.run("enforce-statement-order", rule, {
37
+ valid: [
38
+ // ===== BASIC PATTERNS =====
39
+
40
+ // Correct order: definitions → side effects → return
41
+ {
42
+ code: `
43
+ function example() {
44
+ const x = 1;
45
+ doSomething();
46
+ return x;
47
+ }
48
+ `,
49
+ },
50
+
51
+ // Definitions only (no side effects)
52
+ {
53
+ code: `
54
+ function example() {
55
+ const x = 1;
56
+ const y = 2;
57
+ return x + y;
58
+ }
59
+ `,
60
+ },
61
+
62
+ // Multiple side effects in correct position
63
+ {
64
+ code: `
65
+ function example() {
66
+ const x = 1;
67
+ doSomething();
68
+ doSomethingElse();
69
+ logger.info("done");
70
+ return x;
71
+ }
72
+ `,
73
+ },
74
+
75
+ // Function declaration followed by side effect
76
+ {
77
+ code: `
78
+ function example() {
79
+ const x = 1;
80
+ function helper() {}
81
+ doSomething();
82
+ return x;
83
+ }
84
+ `,
85
+ },
86
+
87
+ // No return statement (void function)
88
+ {
89
+ code: `
90
+ function example() {
91
+ const x = 1;
92
+ doSomething();
93
+ }
94
+ `,
95
+ },
96
+
97
+ // Only side effects (no definitions, no return)
98
+ {
99
+ code: `
100
+ function example() {
101
+ doSomething();
102
+ doSomethingElse();
103
+ }
104
+ `,
105
+ },
106
+
107
+ // ===== REACT PATTERNS =====
108
+
109
+ // React hook with correct order
110
+ {
111
+ code: `
112
+ const useExample = () => {
113
+ const [state, setState] = useState(null);
114
+ const data = useMemo(() => [], []);
115
+ const handleClick = useCallback(() => {}, []);
116
+
117
+ useEffect(() => {}, []);
118
+
119
+ return data;
120
+ };
121
+ `,
122
+ },
123
+
124
+ // React component with correct order
125
+ {
126
+ code: `
127
+ const MyComponent = () => {
128
+ const [state, setState] = useState(null);
129
+ const data = useMemo(() => [], []);
130
+
131
+ useEffect(() => {}, []);
132
+ logRender();
133
+
134
+ return <div>{data}</div>;
135
+ };
136
+ `,
137
+ },
138
+
139
+ // React component function declaration
140
+ {
141
+ code: `
142
+ function MyComponent() {
143
+ const [state, setState] = useState(null);
144
+ const handleClick = useCallback(() => {}, []);
145
+
146
+ useEffect(() => {}, []);
147
+
148
+ return <div />;
149
+ }
150
+ `,
151
+ },
152
+
153
+ // Early return pattern after side effects is valid
154
+ {
155
+ code: `
156
+ const MyComponent = () => {
157
+ const [loading, setLoading] = useState(true);
158
+
159
+ useEffect(() => {}, []);
160
+
161
+ if (loading) return null;
162
+
163
+ return <div />;
164
+ };
165
+ `,
166
+ },
167
+
168
+ // Early return with block statement after side effects
169
+ {
170
+ code: `
171
+ const MyComponent = () => {
172
+ const data = useMemo(() => [], []);
173
+
174
+ useEffect(() => {}, []);
175
+
176
+ if (!data) {
177
+ return null;
178
+ }
179
+
180
+ return <div />;
181
+ };
182
+ `,
183
+ },
184
+
185
+ // ===== ARROW FUNCTIONS =====
186
+
187
+ // Arrow function with correct order
188
+ {
189
+ code: `
190
+ const process = () => {
191
+ const config = getConfig();
192
+ initialize();
193
+ return config;
194
+ };
195
+ `,
196
+ },
197
+
198
+ // ===== EDGE CASES =====
199
+
200
+ // Empty function
201
+ {
202
+ code: `
203
+ function empty() {}
204
+ `,
205
+ },
206
+
207
+ // Only return
208
+ {
209
+ code: `
210
+ function getValue() {
211
+ return 42;
212
+ }
213
+ `,
214
+ },
215
+
216
+ // Nested functions are checked independently
217
+ {
218
+ code: `
219
+ function outer() {
220
+ const x = 1;
221
+ const inner = () => {
222
+ const y = 2;
223
+ doSomething();
224
+ return y;
225
+ };
226
+ doSomething();
227
+ return x;
228
+ }
229
+ `,
230
+ },
231
+ ],
232
+
233
+ invalid: [
234
+ // ===== BASIC VIOLATIONS =====
235
+
236
+ // Definition after side effect
237
+ {
238
+ code: `
239
+ function example() {
240
+ doSomething();
241
+ const x = 1;
242
+ return x;
243
+ }
244
+ `,
245
+ errors: [
246
+ {
247
+ messageId: "wrongOrder",
248
+ data: {
249
+ current: DEFINITIONS,
250
+ previous: SIDE_EFFECTS,
251
+ },
252
+ },
253
+ ],
254
+ },
255
+
256
+ // Side effect after return
257
+ {
258
+ code: `
259
+ function example() {
260
+ const x = 1;
261
+ return x;
262
+ doSomething();
263
+ }
264
+ `,
265
+ errors: [
266
+ {
267
+ messageId: "wrongOrder",
268
+ data: {
269
+ current: SIDE_EFFECTS,
270
+ previous: RETURN_STATEMENT,
271
+ },
272
+ },
273
+ ],
274
+ },
275
+
276
+ // Definition after return
277
+ {
278
+ code: `
279
+ function example() {
280
+ return 1;
281
+ const x = 2;
282
+ }
283
+ `,
284
+ errors: [
285
+ {
286
+ messageId: "wrongOrder",
287
+ data: {
288
+ current: DEFINITIONS,
289
+ previous: RETURN_STATEMENT,
290
+ },
291
+ },
292
+ ],
293
+ },
294
+
295
+ // Multiple violations
296
+ {
297
+ code: `
298
+ function example() {
299
+ doSomething();
300
+ const x = 1;
301
+ return x;
302
+ const y = 2;
303
+ }
304
+ `,
305
+ errors: [
306
+ {
307
+ messageId: "wrongOrder",
308
+ data: {
309
+ current: DEFINITIONS,
310
+ previous: SIDE_EFFECTS,
311
+ },
312
+ },
313
+ {
314
+ messageId: "wrongOrder",
315
+ data: {
316
+ current: DEFINITIONS,
317
+ previous: RETURN_STATEMENT,
318
+ },
319
+ },
320
+ ],
321
+ },
322
+
323
+ // ===== NON-REACT VIOLATIONS =====
324
+
325
+ // Plain function call before definition
326
+ {
327
+ code: `
328
+ function process() {
329
+ initialize();
330
+ const config = {};
331
+ return config;
332
+ }
333
+ `,
334
+ errors: [
335
+ {
336
+ messageId: "wrongOrder",
337
+ data: {
338
+ current: DEFINITIONS,
339
+ previous: SIDE_EFFECTS,
340
+ },
341
+ },
342
+ ],
343
+ },
344
+
345
+ // Logger call before definition
346
+ {
347
+ code: `
348
+ function getData() {
349
+ logger.info("fetching");
350
+ const data = fetch();
351
+ return data;
352
+ }
353
+ `,
354
+ errors: [
355
+ {
356
+ messageId: "wrongOrder",
357
+ data: {
358
+ current: DEFINITIONS,
359
+ previous: SIDE_EFFECTS,
360
+ },
361
+ },
362
+ ],
363
+ },
364
+
365
+ // Console.log before definition
366
+ {
367
+ code: `
368
+ function debug() {
369
+ console.log("starting");
370
+ const value = compute();
371
+ return value;
372
+ }
373
+ `,
374
+ errors: [
375
+ {
376
+ messageId: "wrongOrder",
377
+ data: {
378
+ current: DEFINITIONS,
379
+ previous: SIDE_EFFECTS,
380
+ },
381
+ },
382
+ ],
383
+ },
384
+
385
+ // ===== REACT VIOLATIONS =====
386
+
387
+ // Variable after useEffect
388
+ {
389
+ code: `
390
+ const useExample = () => {
391
+ useEffect(() => {}, []);
392
+ const data = useMemo(() => [], []);
393
+ return data;
394
+ };
395
+ `,
396
+ errors: [
397
+ {
398
+ messageId: "wrongOrder",
399
+ data: {
400
+ current: DEFINITIONS,
401
+ previous: SIDE_EFFECTS,
402
+ },
403
+ },
404
+ ],
405
+ },
406
+
407
+ // useCallback after useEffect
408
+ {
409
+ code: `
410
+ const MyComponent = () => {
411
+ const [state, setState] = useState(null);
412
+ useEffect(() => {}, []);
413
+ const handleClick = useCallback(() => {}, []);
414
+ return <div />;
415
+ };
416
+ `,
417
+ errors: [
418
+ {
419
+ messageId: "wrongOrder",
420
+ data: {
421
+ current: DEFINITIONS,
422
+ previous: SIDE_EFFECTS,
423
+ },
424
+ },
425
+ ],
426
+ },
427
+
428
+ // Function declaration after side effect
429
+ {
430
+ code: `
431
+ function MyComponent() {
432
+ useEffect(() => {}, []);
433
+ function handleClick() {}
434
+ return <div />;
435
+ }
436
+ `,
437
+ errors: [
438
+ {
439
+ messageId: "wrongOrder",
440
+ data: {
441
+ current: DEFINITIONS,
442
+ previous: SIDE_EFFECTS,
443
+ },
444
+ },
445
+ ],
446
+ },
447
+
448
+ // ===== ARROW FUNCTION VIOLATIONS =====
449
+
450
+ // Arrow function with side effect before definition
451
+ {
452
+ code: `
453
+ const process = () => {
454
+ initialize();
455
+ const config = getConfig();
456
+ return config;
457
+ };
458
+ `,
459
+ errors: [
460
+ {
461
+ messageId: "wrongOrder",
462
+ data: {
463
+ current: DEFINITIONS,
464
+ previous: SIDE_EFFECTS,
465
+ },
466
+ },
467
+ ],
468
+ },
469
+ ],
470
+ });
471
+
472
+ console.log("All enforce-statement-order tests passed!");
473
+ /* eslint-enable max-lines -- comprehensive test coverage requires extensive test cases */
@@ -0,0 +1,28 @@
1
+ /**
2
+ * This file is managed by Lisa.
3
+ * Do not edit directly — changes will be overwritten on the next `lisa` run.
4
+ */
5
+
6
+ /**
7
+ * ESLint plugin for code organization standards
8
+ *
9
+ * This plugin enforces code organization patterns for all functions
10
+ * in the frontend application. Supports ESLint 9 flat config format.
11
+ *
12
+ * Rules:
13
+ * - enforce-statement-order: Ensures statements follow the order (definitions -> side effects -> return)
14
+ * @module eslint-plugin-code-organization
15
+ */
16
+ const enforceStatementOrder = require("./rules/enforce-statement-order");
17
+
18
+ const plugin = {
19
+ meta: {
20
+ name: "eslint-plugin-code-organization",
21
+ version: "1.0.0",
22
+ },
23
+ rules: {
24
+ "enforce-statement-order": enforceStatementOrder,
25
+ },
26
+ };
27
+
28
+ module.exports = plugin;
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@codyswann/eslint-plugin-code-organization",
3
+ "version": "1.0.0",
4
+ "description": "ESLint plugin to enforce code organization standards",
5
+ "main": "index.js",
6
+ "publishConfig": { "access": "public" },
7
+ "peerDependencies": {
8
+ "eslint": ">=9.0.0"
9
+ }
10
+ }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * This file is managed by Lisa.
3
+ * Do not edit directly — changes will be overwritten on the next `lisa` run.
4
+ */
5
+
6
+ /**
7
+ * ESLint rule to enforce statement order in all functions
8
+ *
9
+ * Enforces the following order:
10
+ * 1. Definitions: Variable declarations (const/let/var) and function declarations
11
+ * 2. Side effects: Expression statements that are function calls
12
+ * 3. Return statement
13
+ *
14
+ * Applies to all functions: hooks, components, utilities, etc.
15
+ * @type {import('eslint').Rule.RuleModule}
16
+ */
17
+ module.exports = {
18
+ meta: {
19
+ type: "problem",
20
+ docs: {
21
+ description:
22
+ "Enforce statement order: definitions → side effects → return",
23
+ category: "Best Practices",
24
+ recommended: true,
25
+ },
26
+ fixable: null,
27
+ schema: [],
28
+ messages: {
29
+ wrongOrder:
30
+ "{{current}} should come before {{previous}}. Expected order: definitions → side effects → return statement",
31
+ },
32
+ },
33
+
34
+ create(context) {
35
+ const ORDER = {
36
+ DEFINITION: 1, // Variable declarations, function declarations
37
+ SIDE_EFFECT: 2, // Expression statements with function calls
38
+ RETURN: 3, // Return statement
39
+ };
40
+
41
+ const ORDER_NAMES = {
42
+ [ORDER.DEFINITION]: "Definitions",
43
+ [ORDER.SIDE_EFFECT]: "Side effects",
44
+ [ORDER.RETURN]: "Return statement",
45
+ };
46
+
47
+ /**
48
+ * Checks if an expression statement is a function call (side effect)
49
+ * @param {import('eslint').Rule.Node} statement - AST node
50
+ * @returns {boolean} True if this is a function call expression
51
+ */
52
+ function isFunctionCallExpression(statement) {
53
+ if (statement.type !== "ExpressionStatement") {
54
+ return false;
55
+ }
56
+
57
+ const expression = statement.expression;
58
+
59
+ // Direct call: doSomething() or object.method()
60
+ if (expression.type === "CallExpression") {
61
+ return true;
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * Determines the order category of a statement
69
+ * Guard clauses (if statements with early returns) are ignored and don't
70
+ * affect order validation - they can appear anywhere in the function.
71
+ * @param {import('eslint').Rule.Node} statement - AST node
72
+ * @returns {number|null} Order category value, or null to skip this statement
73
+ */
74
+ function getStatementOrder(statement) {
75
+ // Bare return statement (not in an if block)
76
+ if (statement.type === "ReturnStatement") {
77
+ return ORDER.RETURN;
78
+ }
79
+
80
+ // If statements are ignored - they may contain guard clauses (early returns)
81
+ // which are valid at any position in the function
82
+ if (statement.type === "IfStatement") {
83
+ return null;
84
+ }
85
+
86
+ // Variable declarations are definitions
87
+ if (statement.type === "VariableDeclaration") {
88
+ return ORDER.DEFINITION;
89
+ }
90
+
91
+ // Function declarations are definitions
92
+ if (statement.type === "FunctionDeclaration") {
93
+ return ORDER.DEFINITION;
94
+ }
95
+
96
+ // Expression statements with function calls are side effects
97
+ if (isFunctionCallExpression(statement)) {
98
+ return ORDER.SIDE_EFFECT;
99
+ }
100
+
101
+ // Default to null for other statements (they don't affect order)
102
+ return null;
103
+ }
104
+
105
+ /**
106
+ * Checks if a function body follows the correct statement order
107
+ * @param {import('eslint').Rule.Node} node - Function node
108
+ */
109
+ function checkBodyOrder(node) {
110
+ if (!node.body || node.body.type !== "BlockStatement") {
111
+ return;
112
+ }
113
+
114
+ const statements = node.body.body;
115
+ // eslint-disable-next-line functional/no-let -- ESLint plugin requires mutable tracking variable for order validation
116
+ let maxOrderSeen = 0;
117
+
118
+ statements.forEach(statement => {
119
+ const currentOrder = getStatementOrder(statement);
120
+
121
+ // Skip statements that don't affect order (e.g., if statements)
122
+ if (currentOrder === null) {
123
+ return;
124
+ }
125
+
126
+ if (currentOrder < maxOrderSeen) {
127
+ context.report({
128
+ node: statement,
129
+ messageId: "wrongOrder",
130
+ data: {
131
+ current: ORDER_NAMES[currentOrder],
132
+ previous: ORDER_NAMES[maxOrderSeen],
133
+ },
134
+ });
135
+ }
136
+
137
+ // Track the highest order we've seen so far
138
+ if (currentOrder > maxOrderSeen) {
139
+ maxOrderSeen = currentOrder;
140
+ }
141
+ });
142
+ }
143
+
144
+ return {
145
+ // Check all function declarations
146
+ FunctionDeclaration(node) {
147
+ checkBodyOrder(node);
148
+ },
149
+
150
+ // Check all arrow functions and function expressions assigned to variables
151
+ VariableDeclarator(node) {
152
+ if (
153
+ node.init &&
154
+ (node.init.type === "ArrowFunctionExpression" ||
155
+ node.init.type === "FunctionExpression")
156
+ ) {
157
+ checkBodyOrder(node.init);
158
+ }
159
+ },
160
+ };
161
+ },
162
+ };