@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,127 +0,0 @@
1
- /**
2
- * Custom ESLint Plugin: Prefer Const Enum
3
- *
4
- * Flags type aliases where ALL union members are string literals (2+ members)
5
- * and suggests converting to const enum.
6
- *
7
- * Examples:
8
- * FLAGGED: type Mode = 'light' | 'dark';
9
- * FLAGGED: export type Status = 'active' | 'inactive' | 'pending';
10
- *
11
- * NOT FLAGGED:
12
- * type Result = Success | Error; // Union of type references
13
- * type Nullable<T> = T | null; // Contains null keyword
14
- * type Mixed = 'a' | number; // Contains non-string member
15
- * type Single = 'only'; // Single value, not a union
16
- * type Callback = () => void; // Function type
17
- */
18
-
19
- /**
20
- * Convert a string literal value to a PascalCase enum member name.
21
- *
22
- * 'light' -> 'Light'
23
- * 'modern-grid' -> 'ModernGrid'
24
- * 'UPPER_CASE' -> 'UpperCase'
25
- * '2xl' -> '_2xl'
26
- */
27
- function toPascalCase(value) {
28
- // Split on hyphens, underscores, spaces, and camelCase boundaries
29
- const words = value
30
- .replace(/([a-z])([A-Z])/g, '$1 $2')
31
- .split(/[-_\s]+/)
32
- .filter((w) => w.length > 0);
33
-
34
- const result = words
35
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
36
- .join('');
37
-
38
- // If starts with a digit, prefix with underscore
39
- if (/^\d/.test(result)) return `_${result}`;
40
-
41
- return result;
42
- }
43
-
44
- const preferConstEnumRule = {
45
- meta: {
46
- type: 'suggestion',
47
- docs: {
48
- description:
49
- 'Prefer const enum over string literal union types for better autocomplete, refactoring, and centralized definitions.',
50
- category: 'Best Practices',
51
- recommended: true,
52
- },
53
- hasSuggestions: true,
54
- schema: [],
55
- messages: {
56
- preferConstEnum:
57
- 'String literal union type "{{name}}" should be a const enum. Const enums provide autocomplete, refactoring support, and centralized definitions.',
58
- convertToConstEnum: 'Convert "{{name}}" to const enum',
59
- },
60
- },
61
-
62
- create(context) {
63
- return {
64
- TSTypeAliasDeclaration(node) {
65
- const { typeAnnotation } = node;
66
-
67
- // Must be a union type
68
- if (typeAnnotation.type !== 'TSUnionType') return;
69
-
70
- const { types } = typeAnnotation;
71
-
72
- // Must have 2+ members
73
- if (types.length < 2) return;
74
-
75
- // ALL members must be string literals
76
- const allStringLiterals = types.every(
77
- (member) =>
78
- member.type === 'TSLiteralType' &&
79
- member.literal.type === 'Literal' &&
80
- typeof member.literal.value === 'string',
81
- );
82
-
83
- if (!allStringLiterals) return;
84
-
85
- const typeName = node.id.name;
86
- const isExported =
87
- node.parent.type === 'ExportNamedDeclaration';
88
- const exportPrefix = isExported ? 'export ' : '';
89
-
90
- // Build the const enum suggestion
91
- const enumMembers = types
92
- .map((member) => {
93
- const value = member.literal.value;
94
- const memberName = toPascalCase(value);
95
- return ` ${memberName} = '${value}',`;
96
- })
97
- .join('\n');
98
-
99
- const replacement = `${exportPrefix}const enum ${typeName} {\n${enumMembers}\n}`;
100
-
101
- // The node to replace depends on whether it's exported
102
- const targetNode = isExported ? node.parent : node;
103
-
104
- context.report({
105
- node: node.id,
106
- messageId: 'preferConstEnum',
107
- data: { name: typeName },
108
- suggest: [
109
- {
110
- messageId: 'convertToConstEnum',
111
- data: { name: typeName },
112
- fix(fixer) {
113
- return fixer.replaceText(targetNode, replacement);
114
- },
115
- },
116
- ],
117
- });
118
- },
119
- };
120
- },
121
- };
122
-
123
- export default {
124
- rules: {
125
- 'prefer-const-enum': preferConstEnumRule,
126
- },
127
- };
@@ -1,372 +0,0 @@
1
- /**
2
- * Custom ESLint Plugin: Require Stable Hook Arguments
3
- *
4
- * Detects functions, objects, and arrays declared in React component scope
5
- * that are passed as arguments to custom hooks (use*) without being wrapped
6
- * in useCallback or useMemo. These unstable references cause infinite
7
- * re-render loops when the hook uses them in useEffect dependency arrays.
8
- *
9
- * Examples:
10
- * BAD: const t = (key) => i18nT(key);
11
- * useQuizForm(data, t); // t is new ref every render
12
- *
13
- * GOOD: const t = useCallback((key) => i18nT(key), [i18nT]);
14
- * useQuizForm(data, t); // t is stable
15
- *
16
- * BAD: const config = { theme: 'dark' };
17
- * useMyHook(config); // config is new ref every render
18
- *
19
- * GOOD: const config = useMemo(() => ({ theme: 'dark' }), []);
20
- * useMyHook(config); // config is stable
21
- */
22
-
23
- /**
24
- * Names of hooks/functions whose return values are considered stable
25
- * (don't need further wrapping in useCallback/useMemo).
26
- */
27
- const STABLE_INIT_CALLS = new Set([
28
- 'useCallback',
29
- 'useMemo',
30
- 'useRef',
31
- 'useState',
32
- 'useReducer',
33
- 'useContext',
34
- 'useId',
35
- 'useDeferredValue',
36
- 'useTransition',
37
- 'useSyncExternalStore',
38
- 'useActionState',
39
- 'useFormStatus',
40
- 'useOptimistic',
41
- 'StyleSheet.create',
42
- 'Object.freeze',
43
- ]);
44
-
45
- /**
46
- * Hooks that should NOT trigger this rule. Includes:
47
- * - React built-in hooks
48
- * - Well-known library hooks that safely handle unstable references
49
- * (they don't put callback arguments into useEffect dependency arrays)
50
- */
51
- const IGNORED_HOOKS = new Set([
52
- // React built-in
53
- 'useState',
54
- 'useEffect',
55
- 'useLayoutEffect',
56
- 'useCallback',
57
- 'useMemo',
58
- 'useRef',
59
- 'useReducer',
60
- 'useContext',
61
- 'useImperativeHandle',
62
- 'useDebugValue',
63
- 'useId',
64
- 'useDeferredValue',
65
- 'useTransition',
66
- 'useSyncExternalStore',
67
- 'useInsertionEffect',
68
- 'useActionState',
69
- 'useFormStatus',
70
- 'useOptimistic',
71
- 'use',
72
- // Redux - selector runs on every render by design
73
- 'useSelector',
74
- 'useDispatch',
75
- 'useStore',
76
- // React Query / TanStack Query - callbacks are not deps
77
- 'useQuery',
78
- 'useMutation',
79
- 'useInfiniteQuery',
80
- 'useQueryClient',
81
- 'useSuspenseQuery',
82
- 'useSuspenseInfiniteQuery',
83
- 'useQueries',
84
- 'usePrefetchQuery',
85
- 'useIsFetching',
86
- 'useIsMutating',
87
- // React Navigation / Expo Router
88
- 'useNavigation',
89
- 'useRoute',
90
- 'useRouter',
91
- 'usePathname',
92
- 'useSegments',
93
- 'useSearchParams',
94
- 'useLocalSearchParams',
95
- 'useGlobalSearchParams',
96
- 'useFocusEffect',
97
- 'useNavigationState',
98
- // i18next
99
- 'useTranslation',
100
- // Zustand - selector runs on every render
101
- 'useStoreWithEqualityFn',
102
- // React Spring / Animated
103
- 'useSpring',
104
- 'useSprings',
105
- 'useTrail',
106
- 'useChain',
107
- // Syncfusion
108
- 'useDynamicFormStyles',
109
- // React Hook Form - options object is safely handled
110
- 'useForm',
111
- 'useFormContext',
112
- 'useController',
113
- 'useWatch',
114
- 'useFieldArray',
115
- ]);
116
-
117
- /**
118
- * Check if a node is an unstable initializer (function, object, or array literal
119
- * NOT wrapped in useCallback/useMemo/other stable call).
120
- */
121
- function isUnstableInit(initNode) {
122
- if (!initNode) return null;
123
-
124
- // Arrow functions and function expressions are unstable
125
- if (
126
- initNode.type === 'ArrowFunctionExpression' ||
127
- initNode.type === 'FunctionExpression'
128
- )
129
- return 'function';
130
-
131
- // Object literals are unstable
132
- if (initNode.type === 'ObjectExpression') return 'object';
133
-
134
- // Array literals are unstable
135
- if (initNode.type === 'ArrayExpression') return 'array';
136
-
137
- return null;
138
- }
139
-
140
- /**
141
- * Check if a call expression is a stable initializer (useCallback, useMemo, etc.)
142
- */
143
- function isStableCall(initNode) {
144
- if (initNode.type !== 'CallExpression') return false;
145
-
146
- const callee = initNode.callee;
147
-
148
- // Direct call: useCallback(...), useMemo(...)
149
- if (callee.type === 'Identifier')
150
- return STABLE_INIT_CALLS.has(callee.name);
151
-
152
- // Member expression: StyleSheet.create(...), Object.freeze(...)
153
- if (
154
- callee.type === 'MemberExpression' &&
155
- callee.object.type === 'Identifier' &&
156
- callee.property.type === 'Identifier'
157
- )
158
- return STABLE_INIT_CALLS.has(`${callee.object.name}.${callee.property.name}`);
159
-
160
- return false;
161
- }
162
-
163
- /**
164
- * Get the callee name from a CallExpression node.
165
- */
166
- function getCalleeName(callNode) {
167
- const callee = callNode.callee;
168
- if (callee.type === 'Identifier') return callee.name;
169
- if (
170
- callee.type === 'MemberExpression' &&
171
- callee.object.type === 'Identifier' &&
172
- callee.property.type === 'Identifier'
173
- )
174
- return `${callee.object.name}.${callee.property.name}`;
175
-
176
- return null;
177
- }
178
-
179
- /**
180
- * Check if a function name looks like a custom hook (starts with "use" + uppercase).
181
- */
182
- function isCustomHookName(name, extraIgnored, patterns) {
183
- if (!name || name.length <= 3 || !name.startsWith('use')) return false;
184
- const charAfterUse = name[3];
185
- const isUpperCase = charAfterUse === charAfterUse.toUpperCase() && charAfterUse !== charAfterUse.toLowerCase();
186
- if (!isUpperCase) return false;
187
- if (IGNORED_HOOKS.has(name)) return false;
188
- if (extraIgnored && extraIgnored.has(name)) return false;
189
- if (patterns && patterns.some((re) => re.test(name))) return false;
190
- return true;
191
- }
192
-
193
- /**
194
- * Check if a node is inside a React component or custom hook (function scope
195
- * where this rule applies).
196
- */
197
- function isInsideComponentOrHook(node) {
198
- let current = node.parent;
199
- while (current) {
200
- const isFunction =
201
- current.type === 'FunctionDeclaration' ||
202
- current.type === 'FunctionExpression' ||
203
- current.type === 'ArrowFunctionExpression';
204
-
205
- if (isFunction) {
206
- // Check if it's a component (PascalCase) or hook (use* prefix)
207
- const name = getFunctionName(current);
208
- if (!name) return false;
209
- const isPascalCase = name[0] === name[0].toUpperCase() && name[0] !== name[0].toLowerCase();
210
- const isHook = name.length > 3 && name.startsWith('use');
211
- return isPascalCase || isHook;
212
- }
213
- current = current.parent;
214
- }
215
- return false;
216
- }
217
-
218
- /**
219
- * Get the name of a function node.
220
- */
221
- function getFunctionName(funcNode) {
222
- // function Foo() {}
223
- if (funcNode.id) return funcNode.id.name;
224
-
225
- // const Foo = () => {} or const Foo = function() {}
226
- if (
227
- funcNode.parent &&
228
- funcNode.parent.type === 'VariableDeclarator' &&
229
- funcNode.parent.id &&
230
- funcNode.parent.id.type === 'Identifier'
231
- )
232
- return funcNode.parent.id.name;
233
-
234
- return null;
235
- }
236
-
237
- const requireStableHookArgsRule = {
238
- meta: {
239
- type: 'problem',
240
- docs: {
241
- description:
242
- 'Disallow passing unstable functions/objects/arrays to custom hooks. Wrap in useCallback/useMemo to prevent infinite re-renders.',
243
- category: 'Possible Errors',
244
- recommended: true,
245
- },
246
- schema: [
247
- {
248
- type: 'object',
249
- properties: {
250
- ignoreHooks: {
251
- type: 'array',
252
- items: { type: 'string' },
253
- description: 'Additional hook names to ignore (e.g., ["useMyLibraryHook"])',
254
- },
255
- ignoreHookPatterns: {
256
- type: 'array',
257
- items: { type: 'string' },
258
- description: 'Regex patterns for hook names to ignore (e.g., ["^useIdentityService", "^useQuestionerWeb"])',
259
- },
260
- },
261
- additionalProperties: false,
262
- },
263
- ],
264
- messages: {
265
- unstableFunction:
266
- 'Unstable function "{{name}}" passed to hook "{{hook}}". Wrap in useCallback() to prevent infinite re-renders.',
267
- unstableObject:
268
- 'Unstable object "{{name}}" passed to hook "{{hook}}". Wrap in useMemo() to prevent infinite re-renders.',
269
- unstableArray:
270
- 'Unstable array "{{name}}" passed to hook "{{hook}}". Wrap in useMemo() to prevent infinite re-renders.',
271
- unstableInlineFunction:
272
- 'Inline function passed to hook "{{hook}}". Extract to a useCallback() variable to prevent infinite re-renders.',
273
- unstableInlineObject:
274
- 'Inline object passed to hook "{{hook}}". Extract to a useMemo() variable to prevent infinite re-renders.',
275
- unstableInlineArray:
276
- 'Inline array passed to hook "{{hook}}". Extract to a useMemo() variable to prevent infinite re-renders.',
277
- },
278
- },
279
-
280
- create(context) {
281
- const options = context.options[0] || {};
282
- const extraIgnored = options.ignoreHooks ? new Set(options.ignoreHooks) : null;
283
- const ignorePatterns = (options.ignoreHookPatterns || []).map((p) => new RegExp(p));
284
- // Track unstable variable declarations: name -> { type, node }
285
- const unstableVars = new Map();
286
-
287
- return {
288
- /**
289
- * Track variable declarations with unstable initializers.
290
- * e.g., const t = (key) => i18nT(key);
291
- */
292
- VariableDeclarator(node) {
293
- if (
294
- !node.id ||
295
- node.id.type !== 'Identifier' ||
296
- !node.init
297
- )
298
- return;
299
-
300
- // Skip if the init is a stable call (useCallback, useMemo, etc.)
301
- if (isStableCall(node.init)) return;
302
-
303
- const unstableType = isUnstableInit(node.init);
304
- if (!unstableType) return;
305
-
306
- // Only track if inside a component or hook
307
- if (!isInsideComponentOrHook(node)) return;
308
-
309
- unstableVars.set(node.id.name, {
310
- type: unstableType,
311
- node: node,
312
- });
313
- },
314
-
315
- /**
316
- * Check call expressions that look like custom hooks.
317
- * Flag any arguments that reference unstable variables or are inline literals.
318
- */
319
- CallExpression(node) {
320
- const hookName = getCalleeName(node);
321
- if (!isCustomHookName(hookName, extraIgnored, ignorePatterns)) return;
322
- if (!isInsideComponentOrHook(node)) return;
323
-
324
- for (const arg of node.arguments) {
325
- // Check identifier arguments against tracked unstable vars
326
- if (arg.type === 'Identifier') {
327
- const tracked = unstableVars.get(arg.name);
328
- if (!tracked) continue;
329
-
330
- const messageMap = {
331
- function: 'unstableFunction',
332
- object: 'unstableObject',
333
- array: 'unstableArray',
334
- };
335
-
336
- context.report({
337
- node: arg,
338
- messageId: messageMap[tracked.type],
339
- data: {
340
- name: arg.name,
341
- hook: hookName,
342
- },
343
- });
344
- continue;
345
- }
346
-
347
- // Check inline unstable arguments (arrow functions, objects, arrays)
348
- const inlineType = isUnstableInit(arg);
349
- if (inlineType) {
350
- const inlineMessageMap = {
351
- function: 'unstableInlineFunction',
352
- object: 'unstableInlineObject',
353
- array: 'unstableInlineArray',
354
- };
355
-
356
- context.report({
357
- node: arg,
358
- messageId: inlineMessageMap[inlineType],
359
- data: { hook: hookName },
360
- });
361
- }
362
- }
363
- },
364
- };
365
- },
366
- };
367
-
368
- export default {
369
- rules: {
370
- 'require-stable-hook-args': requireStableHookArgsRule,
371
- },
372
- };