@dloizides/frontend-devtools 1.0.1 → 1.0.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 (46) hide show
  1. package/dist/eslint/index.d.mts +77 -0
  2. package/dist/eslint/index.d.ts +77 -0
  3. package/dist/eslint/index.js +2000 -0
  4. package/dist/eslint/index.js.map +1 -0
  5. package/dist/eslint/index.mjs +1990 -0
  6. package/dist/eslint/index.mjs.map +1 -0
  7. package/dist/index.d.mts +69 -0
  8. package/dist/index.d.ts +69 -0
  9. package/dist/index.js +37 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +31 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +6 -1
  14. package/.eslintrc.js +0 -34
  15. package/jest.config.js +0 -24
  16. package/publish.ps1 +0 -107
  17. package/src/eslint/index.ts +0 -16
  18. package/src/eslint/legacy.ts +0 -44
  19. package/src/eslint/plugin.test.ts +0 -60
  20. package/src/eslint/plugin.ts +0 -87
  21. package/src/eslint/rules.behaviour.test.ts +0 -86
  22. package/src/eslint/rules.d.ts +0 -16
  23. package/src/eslint/types.ts +0 -27
  24. package/src/i18n/initI18n.test.ts +0 -101
  25. package/src/i18n/initI18n.ts +0 -109
  26. package/src/index.ts +0 -31
  27. package/src/rules/enforce-function-style.js +0 -278
  28. package/src/rules/enforce-module-structure.js +0 -323
  29. package/src/rules/enforce-route-preload.js +0 -288
  30. package/src/rules/enforce-test-colocation.js +0 -82
  31. package/src/rules/enum-file-isolation.js +0 -149
  32. package/src/rules/i18n-interpolation.js +0 -185
  33. package/src/rules/i18n-param-names.js +0 -119
  34. package/src/rules/no-barrel-companion-file.js +0 -142
  35. package/src/rules/no-duplicate-nav-prefix.js +0 -107
  36. package/src/rules/no-duplicate-shared-patterns.js +0 -166
  37. package/src/rules/no-generated-models-barrel-value-import.js +0 -70
  38. package/src/rules/no-null-check.js +0 -171
  39. package/src/rules/no-optional-undefined.js +0 -99
  40. package/src/rules/no-product-imports-in-shared.js +0 -164
  41. package/src/rules/prefer-const-enum.js +0 -127
  42. package/src/rules/require-stable-hook-args.js +0 -372
  43. package/src/rules/smart-max-lines.js +0 -344
  44. package/tsconfig.json +0 -25
  45. package/tsconfig.test.json +0 -11
  46. package/tsup.config.ts +0 -14
@@ -1,344 +0,0 @@
1
- /**
2
- * Custom ESLint Plugin: Smart Max Lines Per Function
3
- *
4
- * Applies different line limits based on function type:
5
- * - React components (functions returning JSX): higher limit (default 200)
6
- * - Regular functions: stricter limit (default 50, warning at 30)
7
- */
8
-
9
- const COMPONENT_MAX_DEFAULT = 200;
10
- const FUNCTION_MAX_DEFAULT = 50;
11
- const FUNCTION_WARN_DEFAULT = 30;
12
-
13
- /**
14
- * Check if an AST node is a JSX element or fragment
15
- */
16
- function isJSX(node) {
17
- if (!node) {
18
- return false;
19
- }
20
- return (
21
- node.type === 'JSXElement' ||
22
- node.type === 'JSXFragment'
23
- );
24
- }
25
-
26
- /**
27
- * Check if an expression could resolve to JSX
28
- */
29
- function expressionReturnsJSX(node) {
30
- if (!node) {
31
- return false;
32
- }
33
-
34
- // Direct JSX
35
- if (isJSX(node)) {
36
- return true;
37
- }
38
-
39
- // Conditional expression: condition ? <A/> : <B/>
40
- if (node.type === 'ConditionalExpression') {
41
- return expressionReturnsJSX(node.consequent) || expressionReturnsJSX(node.alternate);
42
- }
43
-
44
- // Logical expressions: condition && <A/> or condition || <A/>
45
- if (node.type === 'LogicalExpression') {
46
- return expressionReturnsJSX(node.left) || expressionReturnsJSX(node.right);
47
- }
48
-
49
- // Parenthesized expression
50
- if (node.type === 'ParenthesizedExpression') {
51
- return expressionReturnsJSX(node.expression);
52
- }
53
-
54
- // Sequence expression (rare but possible)
55
- if (node.type === 'SequenceExpression') {
56
- const lastExpr = node.expressions[node.expressions.length - 1];
57
- return expressionReturnsJSX(lastExpr);
58
- }
59
-
60
- return false;
61
- }
62
-
63
- /**
64
- * Recursively check if a block contains a return statement with JSX
65
- */
66
- function blockReturnsJSX(blockBody) {
67
- if (!blockBody || !Array.isArray(blockBody)) {
68
- return false;
69
- }
70
-
71
- for (const statement of blockBody) {
72
- if (statementReturnsJSX(statement)) {
73
- return true;
74
- }
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Check if a statement returns JSX
82
- */
83
- function statementReturnsJSX(statement) {
84
- if (!statement) {
85
- return false;
86
- }
87
-
88
- switch (statement.type) {
89
- case 'ReturnStatement':
90
- return expressionReturnsJSX(statement.argument);
91
-
92
- case 'IfStatement':
93
- // Check consequent
94
- if (statement.consequent) {
95
- if (statement.consequent.type === 'BlockStatement') {
96
- if (blockReturnsJSX(statement.consequent.body)) {
97
- return true;
98
- }
99
- } else if (statementReturnsJSX(statement.consequent)) {
100
- return true;
101
- }
102
- }
103
- // Check alternate (else branch)
104
- if (statement.alternate) {
105
- if (statement.alternate.type === 'BlockStatement') {
106
- if (blockReturnsJSX(statement.alternate.body)) {
107
- return true;
108
- }
109
- } else if (statementReturnsJSX(statement.alternate)) {
110
- return true;
111
- }
112
- }
113
- return false;
114
-
115
- case 'SwitchStatement':
116
- for (const switchCase of statement.cases) {
117
- if (blockReturnsJSX(switchCase.consequent)) {
118
- return true;
119
- }
120
- }
121
- return false;
122
-
123
- case 'TryStatement':
124
- if (statement.block && blockReturnsJSX(statement.block.body)) {
125
- return true;
126
- }
127
- if (statement.handler && statement.handler.body && blockReturnsJSX(statement.handler.body.body)) {
128
- return true;
129
- }
130
- if (statement.finalizer && blockReturnsJSX(statement.finalizer.body)) {
131
- return true;
132
- }
133
- return false;
134
-
135
- case 'BlockStatement':
136
- return blockReturnsJSX(statement.body);
137
-
138
- default:
139
- return false;
140
- }
141
- }
142
-
143
- /**
144
- * Check if a function node is a React component (returns JSX)
145
- */
146
- function isReactComponent(node) {
147
- // Arrow function with implicit JSX return: () => <div/>
148
- if (node.type === 'ArrowFunctionExpression') {
149
- if (node.body.type !== 'BlockStatement') {
150
- return expressionReturnsJSX(node.body);
151
- }
152
- }
153
-
154
- // Function with block body - check for JSX returns
155
- const body = node.body;
156
- if (body && body.type === 'BlockStatement') {
157
- return blockReturnsJSX(body.body);
158
- }
159
-
160
- return false;
161
- }
162
-
163
- /**
164
- * Count effective lines in a function (optionally skipping blanks/comments)
165
- */
166
- function countLines(node, sourceCode, skipBlankLines, skipComments) {
167
- const startLine = node.loc.start.line;
168
- const endLine = node.loc.end.line;
169
-
170
- if (!skipBlankLines && !skipComments) {
171
- return endLine - startLine + 1;
172
- }
173
-
174
- const lines = sourceCode.lines.slice(startLine - 1, endLine);
175
- let count = 0;
176
-
177
- // Get all comments in the function
178
- const allComments = sourceCode.getAllComments();
179
- const functionComments = allComments.filter(
180
- (comment) => comment.loc.start.line >= startLine && comment.loc.end.line <= endLine
181
- );
182
-
183
- // Build a set of line numbers that are purely comment lines
184
- const commentOnlyLines = new Set();
185
- if (skipComments) {
186
- for (const comment of functionComments) {
187
- for (let line = comment.loc.start.line; line <= comment.loc.end.line; line++) {
188
- const lineContent = sourceCode.lines[line - 1];
189
- if (lineContent) {
190
- const trimmed = lineContent.trim();
191
- // Check if line is only a comment (starts with // or /* or * for multiline)
192
- const isOnlyComment =
193
- trimmed.startsWith('//') ||
194
- trimmed.startsWith('/*') ||
195
- trimmed.startsWith('*') ||
196
- trimmed.endsWith('*/') ||
197
- trimmed === '';
198
- if (isOnlyComment) {
199
- commentOnlyLines.add(line);
200
- }
201
- }
202
- }
203
- }
204
- }
205
-
206
- for (let i = 0; i < lines.length; i++) {
207
- const lineNumber = startLine + i;
208
- const lineContent = lines[i];
209
-
210
- // Skip blank lines
211
- if (skipBlankLines && lineContent.trim() === '') {
212
- continue;
213
- }
214
-
215
- // Skip comment-only lines
216
- if (skipComments && commentOnlyLines.has(lineNumber)) {
217
- continue;
218
- }
219
-
220
- count++;
221
- }
222
-
223
- return count;
224
- }
225
-
226
- /**
227
- * The ESLint rule definition
228
- */
229
- const smartMaxLinesRule = {
230
- meta: {
231
- type: 'suggestion',
232
- docs: {
233
- description:
234
- 'Enforce different line limits for React components vs regular functions',
235
- category: 'Best Practices',
236
- recommended: true,
237
- },
238
- schema: [
239
- {
240
- type: 'object',
241
- properties: {
242
- componentMax: {
243
- type: 'integer',
244
- minimum: 1,
245
- description: 'Maximum lines for React components',
246
- },
247
- functionMax: {
248
- type: 'integer',
249
- minimum: 1,
250
- description: 'Maximum lines for regular functions (error threshold)',
251
- },
252
- functionWarn: {
253
- type: 'integer',
254
- minimum: 1,
255
- description: 'Warning threshold for regular functions',
256
- },
257
- skipBlankLines: {
258
- type: 'boolean',
259
- description: 'Skip blank lines when counting',
260
- },
261
- skipComments: {
262
- type: 'boolean',
263
- description: 'Skip comment lines when counting',
264
- },
265
- },
266
- additionalProperties: false,
267
- },
268
- ],
269
- messages: {
270
- componentTooLong:
271
- 'React component has too many lines ({{count}}). Maximum allowed is {{max}}.',
272
- functionTooLong:
273
- 'Function has too many lines ({{count}}). Maximum allowed is {{max}}.',
274
- functionWarning:
275
- 'Function has {{count}} lines which exceeds recommended limit of {{warn}}. Consider refactoring.',
276
- },
277
- },
278
-
279
- create(context) {
280
- const options = context.options[0] || {};
281
- const componentMax = options.componentMax ?? COMPONENT_MAX_DEFAULT;
282
- const functionMax = options.functionMax ?? FUNCTION_MAX_DEFAULT;
283
- const functionWarn = options.functionWarn ?? FUNCTION_WARN_DEFAULT;
284
- const skipBlankLines = options.skipBlankLines ?? true;
285
- const skipComments = options.skipComments ?? true;
286
-
287
- const sourceCode = context.sourceCode || context.getSourceCode();
288
-
289
- function checkFunction(node) {
290
- const lineCount = countLines(node, sourceCode, skipBlankLines, skipComments);
291
- const isComponent = isReactComponent(node);
292
-
293
- if (isComponent) {
294
- // React component - apply componentMax limit
295
- if (lineCount > componentMax) {
296
- context.report({
297
- node,
298
- messageId: 'componentTooLong',
299
- data: {
300
- count: String(lineCount),
301
- max: String(componentMax),
302
- },
303
- });
304
- }
305
- } else {
306
- // Regular function - apply functionMax (error) and functionWarn (warning)
307
- if (lineCount > functionMax) {
308
- context.report({
309
- node,
310
- messageId: 'functionTooLong',
311
- data: {
312
- count: String(lineCount),
313
- max: String(functionMax),
314
- },
315
- });
316
- } else if (lineCount > functionWarn) {
317
- context.report({
318
- node,
319
- messageId: 'functionWarning',
320
- data: {
321
- count: String(lineCount),
322
- warn: String(functionWarn),
323
- },
324
- });
325
- }
326
- }
327
- }
328
-
329
- return {
330
- FunctionDeclaration: checkFunction,
331
- FunctionExpression: checkFunction,
332
- ArrowFunctionExpression: checkFunction,
333
- };
334
- },
335
- };
336
-
337
- /**
338
- * Export the plugin
339
- */
340
- export default {
341
- rules: {
342
- 'smart-max-lines': smartMaxLinesRule,
343
- },
344
- };
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "lib": ["ES2020", "DOM"],
7
- "declaration": true,
8
- "declarationMap": true,
9
- "strict": true,
10
- "noUnusedLocals": true,
11
- "noUnusedParameters": true,
12
- "noImplicitReturns": true,
13
- "noFallthroughCasesInSwitch": true,
14
- "noUncheckedIndexedAccess": true,
15
- "esModuleInterop": true,
16
- "skipLibCheck": true,
17
- "forceConsistentCasingInFileNames": true,
18
- "allowJs": false,
19
- "resolveJsonModule": true,
20
- "outDir": "./dist",
21
- "rootDir": "./src"
22
- },
23
- "include": ["src/**/*"],
24
- "exclude": ["node_modules", "dist", "**/*.test.ts"]
25
- }
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noUncheckedIndexedAccess": false,
5
- "allowJs": true,
6
- "checkJs": false,
7
- "isolatedModules": true,
8
- "rootDir": "."
9
- },
10
- "include": ["src/**/*"]
11
- }
package/tsup.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts', 'src/eslint/index.ts'],
5
- format: ['cjs', 'esm'],
6
- dts: true,
7
- splitting: false,
8
- sourcemap: true,
9
- clean: false,
10
- treeshake: true,
11
- minify: false,
12
- target: 'es2020',
13
- outDir: 'dist',
14
- });