@dloizides/frontend-devtools 1.0.1 → 1.0.2

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 +71 -0
  8. package/dist/index.d.ts +71 -0
  9. package/dist/index.js +2029 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +2017 -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
package/src/index.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * `@dloizides/frontend-devtools` — shared RN-web dev tooling for the
3
- * dloizides.com SaaS frontends.
4
- *
5
- * Two product-agnostic, byte-for-byte-duplicated concerns extracted from
6
- * erevna-web / katalogos-web / kefi-web:
7
- *
8
- * 1. The custom ESLint rule pack (17 rules) — also available under the
9
- * `@dloizides/frontend-devtools/eslint` subpath. The app decides which
10
- * rules to enable + their options; the package owns the rule logic.
11
- *
12
- * 2. `initI18n(options)` — the parameterized i18next + react-i18next init
13
- * factory. The app owns its `locales/*.json` strings and the active
14
- * language; the package owns the `.use().init()` chain (incl. the
15
- * `import/no-named-as-default-member` disable that every app repeated).
16
- *
17
- * Never imports a product.
18
- */
19
-
20
- // i18n init factory
21
- export { initI18n } from './i18n/initI18n';
22
- export type { InitI18nOptions } from './i18n/initI18n';
23
-
24
- // ESLint custom rule pack (also at the `/eslint` subpath)
25
- export { plugin, rules, ruleNames, legacyPlugins } from './eslint';
26
- export type {
27
- CustomRule,
28
- FlatConfigPlugin,
29
- FlatConfig,
30
- SingleRulePlugin,
31
- } from './eslint';
@@ -1,278 +0,0 @@
1
- /**
2
- * Custom ESLint Plugin: Enforce Function Style & Ordering
3
- *
4
- * Two independent checks controlled by options:
5
- *
6
- * 1. **checkStyle** — Multi-statement functions must use `function` declarations,
7
- * not `const`-assigned arrow/function expressions. Single-expression arrows
8
- * are fine (concise one-liners). React components are exempt (enforced by
9
- * `react/function-component-definition`). Closures/callbacks are exempt.
10
- *
11
- * 2. **checkOrdering** — Module-level constants must appear before functions and
12
- * exports. Functions and exports may be freely interleaved.
13
- * Imports, type declarations, and re-exports are exempt.
14
- * This order is compatible with @typescript-eslint/no-use-before-define.
15
- */
16
-
17
- // ---------------------------------------------------------------------------
18
- // Helpers – JSX detection (borrowed from smart-max-lines for consistency)
19
- // ---------------------------------------------------------------------------
20
-
21
- function isJSX(node) {
22
- return node && (node.type === 'JSXElement' || node.type === 'JSXFragment');
23
- }
24
-
25
- function expressionReturnsJSX(node) {
26
- if (!node) return false;
27
- if (isJSX(node)) return true;
28
- if (node.type === 'ConditionalExpression')
29
- return expressionReturnsJSX(node.consequent) || expressionReturnsJSX(node.alternate);
30
- if (node.type === 'LogicalExpression')
31
- return expressionReturnsJSX(node.left) || expressionReturnsJSX(node.right);
32
- if (node.type === 'ParenthesizedExpression')
33
- return expressionReturnsJSX(node.expression);
34
- return false;
35
- }
36
-
37
- function blockReturnsJSX(body) {
38
- if (!Array.isArray(body)) return false;
39
- for (const stmt of body) {
40
- if (stmt.type === 'ReturnStatement' && expressionReturnsJSX(stmt.argument))
41
- return true;
42
- if (stmt.type === 'IfStatement') {
43
- const check = (branch) => {
44
- if (!branch) return false;
45
- if (branch.type === 'BlockStatement') return blockReturnsJSX(branch.body);
46
- return branch.type === 'ReturnStatement' && expressionReturnsJSX(branch.argument);
47
- };
48
- if (check(stmt.consequent) || check(stmt.alternate)) return true;
49
- }
50
- if (stmt.type === 'SwitchStatement') {
51
- for (const c of stmt.cases)
52
- if (blockReturnsJSX(c.consequent)) return true;
53
- }
54
- }
55
- return false;
56
- }
57
-
58
- function functionReturnsJSX(fnNode) {
59
- if (fnNode.type === 'ArrowFunctionExpression' && fnNode.body.type !== 'BlockStatement')
60
- return expressionReturnsJSX(fnNode.body);
61
- if (fnNode.body && fnNode.body.type === 'BlockStatement')
62
- return blockReturnsJSX(fnNode.body.body);
63
- return false;
64
- }
65
-
66
- // ---------------------------------------------------------------------------
67
- // Helpers – Statement classification for ordering
68
- // ---------------------------------------------------------------------------
69
-
70
- /** Exempt statement types that don't participate in ordering zones. */
71
- function isExemptStatement(stmt) {
72
- if (stmt.type === 'ImportDeclaration') return true;
73
- if (stmt.type === 'TSTypeAliasDeclaration') return true;
74
- if (stmt.type === 'TSInterfaceDeclaration') return true;
75
- if (stmt.type === 'TSEnumDeclaration') return true;
76
- if (stmt.type === 'ExportAllDeclaration') return true;
77
- // Type-only exports
78
- if (stmt.type === 'ExportNamedDeclaration' && stmt.exportKind === 'type') return true;
79
- // Re-exports (export { ... } from '...')
80
- if (stmt.type === 'ExportNamedDeclaration' && stmt.source) return true;
81
- // Empty export declarations (export {};)
82
- if (stmt.type === 'ExportNamedDeclaration' && !stmt.declaration && stmt.specifiers.length === 0)
83
- return true;
84
- return false;
85
- }
86
-
87
- /** Check if a VariableDeclaration's init is a function (arrow or function expression). */
88
- function hasFunctionInit(varDecl) {
89
- if (!varDecl.declarations || varDecl.declarations.length === 0) return false;
90
- const init = varDecl.declarations[0].init;
91
- if (!init) return false;
92
- return init.type === 'ArrowFunctionExpression' || init.type === 'FunctionExpression';
93
- }
94
-
95
- /**
96
- * Classify a top-level statement into a zone for ordering:
97
- * 1 = constant, 2 = function/export, 0 = exempt
98
- *
99
- * Expected file layout (compatible with no-use-before-define):
100
- * imports/types → constants → functions & exports (freely interleaved)
101
- */
102
- function classifyZone(stmt) {
103
- if (isExemptStatement(stmt)) return 0;
104
-
105
- // Exports → zone 2
106
- if (stmt.type === 'ExportNamedDeclaration' || stmt.type === 'ExportDefaultDeclaration')
107
- return 2;
108
-
109
- // Private function declarations → zone 2
110
- if (stmt.type === 'FunctionDeclaration') return 2;
111
-
112
- // Private variable declarations
113
- if (stmt.type === 'VariableDeclaration') {
114
- if (hasFunctionInit(stmt)) return 2; // function-valued → zone 2
115
- return 1; // plain constant → zone 1
116
- }
117
-
118
- // Everything else (expression statements, etc.) → exempt
119
- return 0;
120
- }
121
-
122
- /** Get a readable name from a statement for error messages. */
123
- function getStatementName(stmt) {
124
- if (stmt.type === 'ExportNamedDeclaration' && stmt.declaration) {
125
- const decl = stmt.declaration;
126
- if (decl.type === 'FunctionDeclaration' && decl.id) return decl.id.name;
127
- if (decl.type === 'VariableDeclaration' && decl.declarations[0]?.id)
128
- return decl.declarations[0].id.name;
129
- }
130
- if (stmt.type === 'ExportDefaultDeclaration') return 'default export';
131
- if (stmt.type === 'FunctionDeclaration' && stmt.id) return stmt.id.name;
132
- if (stmt.type === 'VariableDeclaration' && stmt.declarations[0]?.id)
133
- return stmt.declarations[0].id.name;
134
- return '(anonymous)';
135
- }
136
-
137
- // ---------------------------------------------------------------------------
138
- // Helpers – Top-level detection
139
- // ---------------------------------------------------------------------------
140
-
141
- /**
142
- * Check if a VariableDeclarator is at the module top level.
143
- * A declarator is top-level if its VariableDeclaration parent is directly
144
- * under Program, or under an ExportNamedDeclaration that is under Program.
145
- */
146
- function isTopLevel(node) {
147
- const varDecl = node.parent; // VariableDeclaration
148
- if (!varDecl) return false;
149
- const container = varDecl.parent;
150
- if (!container) return false;
151
- if (container.type === 'Program') return true;
152
- if (container.type === 'ExportNamedDeclaration' && container.parent?.type === 'Program')
153
- return true;
154
- return false;
155
- }
156
-
157
- // ---------------------------------------------------------------------------
158
- // Rule definition
159
- // ---------------------------------------------------------------------------
160
-
161
- const enforceFunctionStyleRule = {
162
- meta: {
163
- type: 'suggestion',
164
- docs: {
165
- description:
166
- 'Enforce function declarations for multi-statement functions and ' +
167
- 'correct ordering of exports, private functions, and constants.',
168
- category: 'Best Practices',
169
- recommended: true,
170
- },
171
- schema: [
172
- {
173
- type: 'object',
174
- properties: {
175
- checkStyle: {
176
- type: 'boolean',
177
- description: 'Flag const-assigned multi-statement functions (default true)',
178
- },
179
- checkOrdering: {
180
- type: 'boolean',
181
- description: 'Flag out-of-order module statements (default true)',
182
- },
183
- },
184
- additionalProperties: false,
185
- },
186
- ],
187
- messages: {
188
- useFunction:
189
- 'Use a function declaration (`function {{name}}`) instead of a ' +
190
- 'const-assigned arrow/function expression for multi-statement functions.',
191
- constantAfterCode:
192
- 'Module-level constant `{{name}}` should appear before functions and exports.',
193
- },
194
- },
195
-
196
- create(context) {
197
- const options = context.options[0] || {};
198
- const checkStyle = options.checkStyle !== false;
199
- const checkOrdering = options.checkOrdering !== false;
200
-
201
- return {
202
- // -----------------------------------------------------------------
203
- // Check 1: Declaration style
204
- // -----------------------------------------------------------------
205
- ...(checkStyle
206
- ? {
207
- VariableDeclarator(node) {
208
- // Only care about top-level const-assigned functions
209
- if (!isTopLevel(node)) return;
210
-
211
- const init = node.init;
212
- if (!init) return;
213
- if (init.type !== 'ArrowFunctionExpression' && init.type !== 'FunctionExpression')
214
- return;
215
-
216
- // Allow single-expression arrows (concise body, no block)
217
- if (init.type === 'ArrowFunctionExpression' && init.body.type !== 'BlockStatement')
218
- return;
219
-
220
- // Allow React components (JSX return) — enforced separately
221
- if (functionReturnsJSX(init)) return;
222
-
223
- // Allow PascalCase names — likely React components (enforced
224
- // as arrow functions by react/function-component-definition).
225
- // Components returning null won't be caught by JSX check above.
226
- const name = node.id?.name ?? '(anonymous)';
227
- if (/^[A-Z]/.test(name)) return;
228
-
229
- // IIFEs like `const x = (() => {...})()` are implicitly exempt
230
- // because their init is a CallExpression, filtered by the type
231
- // check above.
232
-
233
- context.report({
234
- node,
235
- messageId: 'useFunction',
236
- data: { name },
237
- });
238
- },
239
- }
240
- : {}),
241
-
242
- // -----------------------------------------------------------------
243
- // Check 2: Ordering
244
- // -----------------------------------------------------------------
245
- ...(checkOrdering
246
- ? {
247
- 'Program:exit'(programNode) {
248
- let maxZoneSeen = 0;
249
-
250
- for (const stmt of programNode.body) {
251
- const zone = classifyZone(stmt);
252
- if (zone === 0) continue; // exempt — ignore
253
-
254
- if (zone < maxZoneSeen) {
255
- const name = getStatementName(stmt);
256
- const messageId = 'constantAfterCode';
257
-
258
- context.report({
259
- node: stmt,
260
- messageId,
261
- data: { name },
262
- });
263
- }
264
-
265
- if (zone > maxZoneSeen) maxZoneSeen = zone;
266
- }
267
- },
268
- }
269
- : {}),
270
- };
271
- },
272
- };
273
-
274
- export default {
275
- rules: {
276
- 'enforce-function-style': enforceFunctionStyleRule,
277
- },
278
- };
@@ -1,323 +0,0 @@
1
- /**
2
- * Custom ESLint Plugin: Enforce Module Structure
3
- *
4
- * When a component/feature directory contains 4+ non-test source files,
5
- * this rule enforces a standard internal structure:
6
- *
7
- * hooks/ — Custom hooks (use*.ts)
8
- * components/ — Sub-components (non-index .tsx files)
9
- * utils/ — Pure helper functions (non-hook, non-component .ts files)
10
- * data/ — Static/mock data files (*Data.ts, *.data.ts)
11
- *
12
- * Files that may stay at the directory root:
13
- * index.tsx, index.ts, types.ts, constants.ts, schema.ts, columns.ts
14
- *
15
- * The rule also allows domain-specific subdirectories (e.g. filters/,
16
- * columnMenu/, pagination/) — files inside those are exempt because
17
- * they are already organized by concern.
18
- *
19
- * Special directory patterns exempt from sub-component checks:
20
- * sections/ — Feature page sections (.tsx files are the primary content)
21
- * forms/ — Form components (.tsx are the primary content)
22
- *
23
- * Threshold: only enforced when a directory has >= fileThreshold source
24
- * files (default 4). Simple components with 1-3 files are left alone.
25
- *
26
- * Examples:
27
- * BAD: DataGrid/useGridCallbacks.ts (hook at root, 8 siblings)
28
- * GOOD: DataGrid/hooks/useGridCallbacks.ts (hook in hooks/ subdir)
29
- *
30
- * BAD: sections/data.ts (data mixed with sections)
31
- * GOOD: data/gridData.ts (data in dedicated subdir)
32
- *
33
- * OK: sections/BasicGridSection.tsx (sections dir, .tsx exempt)
34
- * OK: TableNative/columnMenu/useColumnMenu.ts (domain subdir, exempt)
35
- * OK: Button/index.tsx (only 2 files, below threshold)
36
- */
37
-
38
- import { readdirSync } from 'fs';
39
- import { dirname, basename, sep, posix } from 'path';
40
-
41
- const FILE_THRESHOLD_DEFAULT = 4;
42
-
43
- /** Exact file names allowed to stay at the root of a module directory. */
44
- const ROOT_ALLOWED_BASENAMES = new Set([
45
- 'index.tsx',
46
- 'index.ts',
47
- 'types.ts',
48
- 'constants.ts',
49
- 'schema.ts',
50
- 'columns.ts',
51
- ]);
52
-
53
- /**
54
- * File name patterns that are allowed at root.
55
- * - *Types.ts: type definition files (same purpose as types.ts)
56
- * - Files containing a single const enum are required by
57
- * enum-file-isolation to be standalone — don't force them into utils/.
58
- * We detect these by common naming patterns for enum files.
59
- */
60
- const ROOT_ALLOWED_PATTERNS = [
61
- /^[a-zA-Z]+Types\.ts$/, // alertTypes.ts, buttonTypes.ts, etc.
62
- ];
63
-
64
- /**
65
- * Directory names where PascalCase .tsx files are the primary content
66
- * and should NOT be flagged as "move to components/".
67
- * Hooks, utils, and data files are still flagged in these directories.
68
- */
69
- const COMPONENT_EXEMPT_DIRS = new Set([
70
- 'sections',
71
- 'forms',
72
- 'Forms',
73
- ]);
74
-
75
- /**
76
- * Directory names that are collections of standalone files by design.
77
- * Files in these directories should not be reorganized into subdirs.
78
- * Example: shared/ contains type files and enums for multiple consumers.
79
- */
80
- const FLAT_EXEMPT_DIRS = new Set([
81
- // Common (shared with SyncfusionThemeStudio)
82
- 'shared',
83
- 'presets',
84
- 'defaults',
85
- 'injectors',
86
- 'types',
87
- 'actions',
88
- 'icons',
89
- 'errors',
90
- 'interceptors',
91
- 'events',
92
- 'routes',
93
- 'utils',
94
- 'components',
95
- 'form-fields',
96
- // BaseClient-specific
97
- 'enums',
98
- 'testIds',
99
- 'constants',
100
- 'slices',
101
- 'schemas',
102
- 'locales',
103
- 'mutators',
104
- 'customHooks',
105
- 'swagger',
106
- 'models',
107
- 'handlers',
108
- 'menuHandlers',
109
- 'userHandlers',
110
- ]);
111
-
112
- /**
113
- * Count non-test, non-directory source files in a directory (shallow).
114
- * Returns only .ts/.tsx files that are not tests or declarations.
115
- */
116
- function countSourceFiles(dirPath) {
117
- try {
118
- const entries = readdirSync(dirPath, { withFileTypes: true });
119
- return entries.filter((e) => {
120
- if (!e.isFile()) return false;
121
- const name = e.name;
122
- if (!name.endsWith('.ts') && !name.endsWith('.tsx')) return false;
123
- if (name.endsWith('.test.ts') || name.endsWith('.test.tsx')) return false;
124
- if (name.endsWith('.d.ts')) return false;
125
- return true;
126
- }).length;
127
- } catch {
128
- return 0;
129
- }
130
- }
131
-
132
- /**
133
- * Check whether the file is inside a non-root subdirectory of its
134
- * module directory (e.g. hooks/, components/, filters/, columnMenu/).
135
- * If so, it's already organized and should be exempt.
136
- */
137
- function isInsideSubdirectory(filePath, moduleRoot) {
138
- const rel = filePath
139
- .split(sep)
140
- .join(posix.sep)
141
- .slice(moduleRoot.split(sep).join(posix.sep).length + 1);
142
- // rel looks like "hooks/useX.ts" or "index.tsx"
143
- return rel.includes('/');
144
- }
145
-
146
- /**
147
- * Determine the "module root" — the nearest ancestor directory that
148
- * contains an index.ts or index.tsx file. This is the component or
149
- * page directory boundary.
150
- */
151
- function findModuleRoot(filePath) {
152
- let dir = dirname(filePath);
153
- const maxDepth = 10;
154
- for (let i = 0; i < maxDepth; i++) {
155
- try {
156
- const entries = readdirSync(dir);
157
- if (entries.includes('index.ts') || entries.includes('index.tsx'))
158
- return dir;
159
- } catch {
160
- return null;
161
- }
162
- const parent = dirname(dir);
163
- if (parent === dir) return null;
164
- dir = parent;
165
- }
166
- return null;
167
- }
168
-
169
- const enforceModuleStructureRule = {
170
- meta: {
171
- type: 'suggestion',
172
- docs: {
173
- description:
174
- 'Enforce standard module structure: hooks in hooks/, sub-components in components/, ' +
175
- 'utils in utils/, data in data/. Only applies when directory has 4+ source files.',
176
- category: 'Best Practices',
177
- recommended: true,
178
- },
179
- schema: [
180
- {
181
- type: 'object',
182
- properties: {
183
- fileThreshold: {
184
- type: 'integer',
185
- minimum: 2,
186
- description:
187
- 'Minimum number of non-test source files before structure is enforced',
188
- },
189
- },
190
- additionalProperties: false,
191
- },
192
- ],
193
- messages: {
194
- hookAtRoot:
195
- 'Hook "{{fileName}}" should be in a hooks/ subdirectory. ' +
196
- 'Move to {{suggestedPath}}.',
197
- componentAtRoot:
198
- 'Sub-component "{{fileName}}" should be in a components/ subdirectory. ' +
199
- 'Move to {{suggestedPath}}.',
200
- utilAtRoot:
201
- 'Utility file "{{fileName}}" should be in a utils/ subdirectory. ' +
202
- 'Move to {{suggestedPath}}.',
203
- dataInSections:
204
- 'Data file "{{fileName}}" should be in a data/ subdirectory, ' +
205
- 'not mixed with section components. Move to {{suggestedPath}}.',
206
- },
207
- },
208
-
209
- create(context) {
210
- const options = context.options[0] || {};
211
- const fileThreshold = options.fileThreshold ?? FILE_THRESHOLD_DEFAULT;
212
-
213
- return {
214
- Program() {
215
- const filePath = context.filename || context.getFilename();
216
- if (!filePath) return;
217
-
218
- // Only check .ts/.tsx files
219
- if (!filePath.endsWith('.ts') && !filePath.endsWith('.tsx')) return;
220
- if (filePath.endsWith('.d.ts')) return;
221
-
222
- const fileName = basename(filePath);
223
-
224
- // Skip test files — they follow their source files
225
- if (fileName.endsWith('.test.ts') || fileName.endsWith('.test.tsx'))
226
- return;
227
-
228
- // Skip root-allowed files (exact matches and patterns)
229
- if (ROOT_ALLOWED_BASENAMES.has(fileName)) return;
230
- if (ROOT_ALLOWED_PATTERNS.some((p) => p.test(fileName))) return;
231
-
232
- const dir = dirname(filePath);
233
- const dirName = basename(dir);
234
-
235
- // Skip files in flat-exempt directories (shared/, presets/, etc.)
236
- if (FLAT_EXEMPT_DIRS.has(dirName)) return;
237
-
238
- // Find the module root (directory with index.ts/tsx)
239
- const moduleRoot = findModuleRoot(filePath);
240
- if (!moduleRoot) return;
241
-
242
- // If the file is already inside a subdirectory of the module root,
243
- // it's organized — skip
244
- if (isInsideSubdirectory(filePath, moduleRoot)) return;
245
-
246
- // Count source files in the module root to check threshold
247
- const sourceFileCount = countSourceFiles(moduleRoot);
248
- if (sourceFileCount < fileThreshold) return;
249
-
250
- // --- Classify the file and report ---
251
-
252
- const isHook =
253
- /^use[A-Z]/.test(fileName) &&
254
- (fileName.endsWith('.ts') || fileName.endsWith('.tsx'));
255
-
256
- const isComponent =
257
- fileName.endsWith('.tsx') && /^[A-Z]/.test(fileName);
258
-
259
- const isDataFile =
260
- /[Dd]ata\.tsx?$/.test(fileName) ||
261
- /\.data\.tsx?$/.test(fileName);
262
-
263
- // Data files in sections/ directory → suggest data/ subdir
264
- if (isDataFile && dirName === 'sections') {
265
- context.report({
266
- loc: { line: 1, column: 0 },
267
- messageId: 'dataInSections',
268
- data: {
269
- fileName,
270
- suggestedPath: `data/${fileName}`,
271
- },
272
- });
273
- return;
274
- }
275
-
276
- if (isHook) {
277
- context.report({
278
- loc: { line: 1, column: 0 },
279
- messageId: 'hookAtRoot',
280
- data: {
281
- fileName,
282
- suggestedPath: `hooks/${fileName}`,
283
- },
284
- });
285
- return;
286
- }
287
-
288
- // In sections/ and forms/ dirs, .tsx files are the primary content
289
- // and should NOT be flagged as needing components/ subdir
290
- if (isComponent && !COMPONENT_EXEMPT_DIRS.has(dirName)) {
291
- context.report({
292
- loc: { line: 1, column: 0 },
293
- messageId: 'componentAtRoot',
294
- data: {
295
- fileName,
296
- suggestedPath: `components/${fileName}`,
297
- },
298
- });
299
- return;
300
- }
301
-
302
- // Remaining .ts files that aren't root-allowed → utils
303
- // Skip .tsx files in exempt dirs (they're section/form components)
304
- if (fileName.endsWith('.ts') && !isDataFile) {
305
- context.report({
306
- loc: { line: 1, column: 0 },
307
- messageId: 'utilAtRoot',
308
- data: {
309
- fileName,
310
- suggestedPath: `utils/${fileName}`,
311
- },
312
- });
313
- }
314
- },
315
- };
316
- },
317
- };
318
-
319
- export default {
320
- rules: {
321
- 'enforce-module-structure': enforceModuleStructureRule,
322
- },
323
- };