@dloizides/frontend-devtools 1.0.2 → 1.1.0
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.
- package/CHANGELOG.md +40 -0
- package/README.md +40 -0
- package/dist/eslint/index.js +65 -6
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +65 -6
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1992
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1987
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import i18n from 'i18next';
|
|
2
2
|
import { initReactI18next } from 'react-i18next';
|
|
3
|
-
import fs, { existsSync, readdirSync } from 'fs';
|
|
4
|
-
import path, { basename, dirname, sep, posix, join } from 'path';
|
|
5
3
|
|
|
6
4
|
// src/i18n/initI18n.ts
|
|
7
5
|
var DEFAULT_FALLBACK_LNG = "en";
|
|
@@ -28,1990 +26,6 @@ function initI18n(options) {
|
|
|
28
26
|
return i18n;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
function isJSX(node) {
|
|
33
|
-
return node && (node.type === "JSXElement" || node.type === "JSXFragment");
|
|
34
|
-
}
|
|
35
|
-
function expressionReturnsJSX(node) {
|
|
36
|
-
if (!node) return false;
|
|
37
|
-
if (isJSX(node)) return true;
|
|
38
|
-
if (node.type === "ConditionalExpression")
|
|
39
|
-
return expressionReturnsJSX(node.consequent) || expressionReturnsJSX(node.alternate);
|
|
40
|
-
if (node.type === "LogicalExpression")
|
|
41
|
-
return expressionReturnsJSX(node.left) || expressionReturnsJSX(node.right);
|
|
42
|
-
if (node.type === "ParenthesizedExpression")
|
|
43
|
-
return expressionReturnsJSX(node.expression);
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
function blockReturnsJSX(body) {
|
|
47
|
-
if (!Array.isArray(body)) return false;
|
|
48
|
-
for (const stmt of body) {
|
|
49
|
-
if (stmt.type === "ReturnStatement" && expressionReturnsJSX(stmt.argument))
|
|
50
|
-
return true;
|
|
51
|
-
if (stmt.type === "IfStatement") {
|
|
52
|
-
const check = (branch) => {
|
|
53
|
-
if (!branch) return false;
|
|
54
|
-
if (branch.type === "BlockStatement") return blockReturnsJSX(branch.body);
|
|
55
|
-
return branch.type === "ReturnStatement" && expressionReturnsJSX(branch.argument);
|
|
56
|
-
};
|
|
57
|
-
if (check(stmt.consequent) || check(stmt.alternate)) return true;
|
|
58
|
-
}
|
|
59
|
-
if (stmt.type === "SwitchStatement") {
|
|
60
|
-
for (const c of stmt.cases)
|
|
61
|
-
if (blockReturnsJSX(c.consequent)) return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
function functionReturnsJSX(fnNode) {
|
|
67
|
-
if (fnNode.type === "ArrowFunctionExpression" && fnNode.body.type !== "BlockStatement")
|
|
68
|
-
return expressionReturnsJSX(fnNode.body);
|
|
69
|
-
if (fnNode.body && fnNode.body.type === "BlockStatement")
|
|
70
|
-
return blockReturnsJSX(fnNode.body.body);
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
function isExemptStatement(stmt) {
|
|
74
|
-
if (stmt.type === "ImportDeclaration") return true;
|
|
75
|
-
if (stmt.type === "TSTypeAliasDeclaration") return true;
|
|
76
|
-
if (stmt.type === "TSInterfaceDeclaration") return true;
|
|
77
|
-
if (stmt.type === "TSEnumDeclaration") return true;
|
|
78
|
-
if (stmt.type === "ExportAllDeclaration") return true;
|
|
79
|
-
if (stmt.type === "ExportNamedDeclaration" && stmt.exportKind === "type") return true;
|
|
80
|
-
if (stmt.type === "ExportNamedDeclaration" && stmt.source) return true;
|
|
81
|
-
if (stmt.type === "ExportNamedDeclaration" && !stmt.declaration && stmt.specifiers.length === 0)
|
|
82
|
-
return true;
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
function hasFunctionInit(varDecl) {
|
|
86
|
-
if (!varDecl.declarations || varDecl.declarations.length === 0) return false;
|
|
87
|
-
const init = varDecl.declarations[0].init;
|
|
88
|
-
if (!init) return false;
|
|
89
|
-
return init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression";
|
|
90
|
-
}
|
|
91
|
-
function classifyZone(stmt) {
|
|
92
|
-
if (isExemptStatement(stmt)) return 0;
|
|
93
|
-
if (stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration")
|
|
94
|
-
return 2;
|
|
95
|
-
if (stmt.type === "FunctionDeclaration") return 2;
|
|
96
|
-
if (stmt.type === "VariableDeclaration") {
|
|
97
|
-
if (hasFunctionInit(stmt)) return 2;
|
|
98
|
-
return 1;
|
|
99
|
-
}
|
|
100
|
-
return 0;
|
|
101
|
-
}
|
|
102
|
-
function getStatementName(stmt) {
|
|
103
|
-
if (stmt.type === "ExportNamedDeclaration" && stmt.declaration) {
|
|
104
|
-
const decl = stmt.declaration;
|
|
105
|
-
if (decl.type === "FunctionDeclaration" && decl.id) return decl.id.name;
|
|
106
|
-
if (decl.type === "VariableDeclaration" && decl.declarations[0]?.id)
|
|
107
|
-
return decl.declarations[0].id.name;
|
|
108
|
-
}
|
|
109
|
-
if (stmt.type === "ExportDefaultDeclaration") return "default export";
|
|
110
|
-
if (stmt.type === "FunctionDeclaration" && stmt.id) return stmt.id.name;
|
|
111
|
-
if (stmt.type === "VariableDeclaration" && stmt.declarations[0]?.id)
|
|
112
|
-
return stmt.declarations[0].id.name;
|
|
113
|
-
return "(anonymous)";
|
|
114
|
-
}
|
|
115
|
-
function isTopLevel(node) {
|
|
116
|
-
const varDecl = node.parent;
|
|
117
|
-
if (!varDecl) return false;
|
|
118
|
-
const container = varDecl.parent;
|
|
119
|
-
if (!container) return false;
|
|
120
|
-
if (container.type === "Program") return true;
|
|
121
|
-
if (container.type === "ExportNamedDeclaration" && container.parent?.type === "Program")
|
|
122
|
-
return true;
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
var enforceFunctionStyleRule = {
|
|
126
|
-
meta: {
|
|
127
|
-
type: "suggestion",
|
|
128
|
-
docs: {
|
|
129
|
-
description: "Enforce function declarations for multi-statement functions and correct ordering of exports, private functions, and constants.",
|
|
130
|
-
category: "Best Practices",
|
|
131
|
-
recommended: true
|
|
132
|
-
},
|
|
133
|
-
schema: [
|
|
134
|
-
{
|
|
135
|
-
type: "object",
|
|
136
|
-
properties: {
|
|
137
|
-
checkStyle: {
|
|
138
|
-
type: "boolean",
|
|
139
|
-
description: "Flag const-assigned multi-statement functions (default true)"
|
|
140
|
-
},
|
|
141
|
-
checkOrdering: {
|
|
142
|
-
type: "boolean",
|
|
143
|
-
description: "Flag out-of-order module statements (default true)"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
additionalProperties: false
|
|
147
|
-
}
|
|
148
|
-
],
|
|
149
|
-
messages: {
|
|
150
|
-
useFunction: "Use a function declaration (`function {{name}}`) instead of a const-assigned arrow/function expression for multi-statement functions.",
|
|
151
|
-
constantAfterCode: "Module-level constant `{{name}}` should appear before functions and exports."
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
create(context) {
|
|
155
|
-
const options = context.options[0] || {};
|
|
156
|
-
const checkStyle = options.checkStyle !== false;
|
|
157
|
-
const checkOrdering = options.checkOrdering !== false;
|
|
158
|
-
return {
|
|
159
|
-
// -----------------------------------------------------------------
|
|
160
|
-
// Check 1: Declaration style
|
|
161
|
-
// -----------------------------------------------------------------
|
|
162
|
-
...checkStyle ? {
|
|
163
|
-
VariableDeclarator(node) {
|
|
164
|
-
if (!isTopLevel(node)) return;
|
|
165
|
-
const init = node.init;
|
|
166
|
-
if (!init) return;
|
|
167
|
-
if (init.type !== "ArrowFunctionExpression" && init.type !== "FunctionExpression")
|
|
168
|
-
return;
|
|
169
|
-
if (init.type === "ArrowFunctionExpression" && init.body.type !== "BlockStatement")
|
|
170
|
-
return;
|
|
171
|
-
if (functionReturnsJSX(init)) return;
|
|
172
|
-
const name = node.id?.name ?? "(anonymous)";
|
|
173
|
-
if (/^[A-Z]/.test(name)) return;
|
|
174
|
-
context.report({
|
|
175
|
-
node,
|
|
176
|
-
messageId: "useFunction",
|
|
177
|
-
data: { name }
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
} : {},
|
|
181
|
-
// -----------------------------------------------------------------
|
|
182
|
-
// Check 2: Ordering
|
|
183
|
-
// -----------------------------------------------------------------
|
|
184
|
-
...checkOrdering ? {
|
|
185
|
-
"Program:exit"(programNode) {
|
|
186
|
-
let maxZoneSeen = 0;
|
|
187
|
-
for (const stmt of programNode.body) {
|
|
188
|
-
const zone = classifyZone(stmt);
|
|
189
|
-
if (zone === 0) continue;
|
|
190
|
-
if (zone < maxZoneSeen) {
|
|
191
|
-
const name = getStatementName(stmt);
|
|
192
|
-
const messageId = "constantAfterCode";
|
|
193
|
-
context.report({
|
|
194
|
-
node: stmt,
|
|
195
|
-
messageId,
|
|
196
|
-
data: { name }
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (zone > maxZoneSeen) maxZoneSeen = zone;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
} : {}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
var enforce_function_style_default = {
|
|
207
|
-
rules: {
|
|
208
|
-
"enforce-function-style": enforceFunctionStyleRule
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
var FILE_THRESHOLD_DEFAULT = 4;
|
|
212
|
-
var ROOT_ALLOWED_BASENAMES = /* @__PURE__ */ new Set([
|
|
213
|
-
"index.tsx",
|
|
214
|
-
"index.ts",
|
|
215
|
-
"types.ts",
|
|
216
|
-
"constants.ts",
|
|
217
|
-
"schema.ts",
|
|
218
|
-
"columns.ts"
|
|
219
|
-
]);
|
|
220
|
-
var ROOT_ALLOWED_PATTERNS = [
|
|
221
|
-
/^[a-zA-Z]+Types\.ts$/
|
|
222
|
-
// alertTypes.ts, buttonTypes.ts, etc.
|
|
223
|
-
];
|
|
224
|
-
var COMPONENT_EXEMPT_DIRS = /* @__PURE__ */ new Set([
|
|
225
|
-
"sections",
|
|
226
|
-
"forms",
|
|
227
|
-
"Forms"
|
|
228
|
-
]);
|
|
229
|
-
var FLAT_EXEMPT_DIRS = /* @__PURE__ */ new Set([
|
|
230
|
-
// Common (shared with SyncfusionThemeStudio)
|
|
231
|
-
"shared",
|
|
232
|
-
"presets",
|
|
233
|
-
"defaults",
|
|
234
|
-
"injectors",
|
|
235
|
-
"types",
|
|
236
|
-
"actions",
|
|
237
|
-
"icons",
|
|
238
|
-
"errors",
|
|
239
|
-
"interceptors",
|
|
240
|
-
"events",
|
|
241
|
-
"routes",
|
|
242
|
-
"utils",
|
|
243
|
-
"components",
|
|
244
|
-
"form-fields",
|
|
245
|
-
// BaseClient-specific
|
|
246
|
-
"enums",
|
|
247
|
-
"testIds",
|
|
248
|
-
"constants",
|
|
249
|
-
"slices",
|
|
250
|
-
"schemas",
|
|
251
|
-
"locales",
|
|
252
|
-
"mutators",
|
|
253
|
-
"customHooks",
|
|
254
|
-
"swagger",
|
|
255
|
-
"models",
|
|
256
|
-
"handlers",
|
|
257
|
-
"menuHandlers",
|
|
258
|
-
"userHandlers"
|
|
259
|
-
]);
|
|
260
|
-
function countSourceFiles(dirPath) {
|
|
261
|
-
try {
|
|
262
|
-
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
263
|
-
return entries.filter((e) => {
|
|
264
|
-
if (!e.isFile()) return false;
|
|
265
|
-
const name = e.name;
|
|
266
|
-
if (!name.endsWith(".ts") && !name.endsWith(".tsx")) return false;
|
|
267
|
-
if (name.endsWith(".test.ts") || name.endsWith(".test.tsx")) return false;
|
|
268
|
-
if (name.endsWith(".d.ts")) return false;
|
|
269
|
-
return true;
|
|
270
|
-
}).length;
|
|
271
|
-
} catch {
|
|
272
|
-
return 0;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function isInsideSubdirectory(filePath, moduleRoot) {
|
|
276
|
-
const rel = filePath.split(sep).join(posix.sep).slice(moduleRoot.split(sep).join(posix.sep).length + 1);
|
|
277
|
-
return rel.includes("/");
|
|
278
|
-
}
|
|
279
|
-
function findModuleRoot(filePath) {
|
|
280
|
-
let dir = dirname(filePath);
|
|
281
|
-
const maxDepth = 10;
|
|
282
|
-
for (let i = 0; i < maxDepth; i++) {
|
|
283
|
-
try {
|
|
284
|
-
const entries = readdirSync(dir);
|
|
285
|
-
if (entries.includes("index.ts") || entries.includes("index.tsx"))
|
|
286
|
-
return dir;
|
|
287
|
-
} catch {
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
const parent = dirname(dir);
|
|
291
|
-
if (parent === dir) return null;
|
|
292
|
-
dir = parent;
|
|
293
|
-
}
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
var enforceModuleStructureRule = {
|
|
297
|
-
meta: {
|
|
298
|
-
type: "suggestion",
|
|
299
|
-
docs: {
|
|
300
|
-
description: "Enforce standard module structure: hooks in hooks/, sub-components in components/, utils in utils/, data in data/. Only applies when directory has 4+ source files.",
|
|
301
|
-
category: "Best Practices",
|
|
302
|
-
recommended: true
|
|
303
|
-
},
|
|
304
|
-
schema: [
|
|
305
|
-
{
|
|
306
|
-
type: "object",
|
|
307
|
-
properties: {
|
|
308
|
-
fileThreshold: {
|
|
309
|
-
type: "integer",
|
|
310
|
-
minimum: 2,
|
|
311
|
-
description: "Minimum number of non-test source files before structure is enforced"
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
additionalProperties: false
|
|
315
|
-
}
|
|
316
|
-
],
|
|
317
|
-
messages: {
|
|
318
|
-
hookAtRoot: 'Hook "{{fileName}}" should be in a hooks/ subdirectory. Move to {{suggestedPath}}.',
|
|
319
|
-
componentAtRoot: 'Sub-component "{{fileName}}" should be in a components/ subdirectory. Move to {{suggestedPath}}.',
|
|
320
|
-
utilAtRoot: 'Utility file "{{fileName}}" should be in a utils/ subdirectory. Move to {{suggestedPath}}.',
|
|
321
|
-
dataInSections: 'Data file "{{fileName}}" should be in a data/ subdirectory, not mixed with section components. Move to {{suggestedPath}}.'
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
create(context) {
|
|
325
|
-
const options = context.options[0] || {};
|
|
326
|
-
const fileThreshold = options.fileThreshold ?? FILE_THRESHOLD_DEFAULT;
|
|
327
|
-
return {
|
|
328
|
-
Program() {
|
|
329
|
-
const filePath = context.filename || context.getFilename();
|
|
330
|
-
if (!filePath) return;
|
|
331
|
-
if (!filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) return;
|
|
332
|
-
if (filePath.endsWith(".d.ts")) return;
|
|
333
|
-
const fileName = basename(filePath);
|
|
334
|
-
if (fileName.endsWith(".test.ts") || fileName.endsWith(".test.tsx"))
|
|
335
|
-
return;
|
|
336
|
-
if (ROOT_ALLOWED_BASENAMES.has(fileName)) return;
|
|
337
|
-
if (ROOT_ALLOWED_PATTERNS.some((p) => p.test(fileName))) return;
|
|
338
|
-
const dir = dirname(filePath);
|
|
339
|
-
const dirName = basename(dir);
|
|
340
|
-
if (FLAT_EXEMPT_DIRS.has(dirName)) return;
|
|
341
|
-
const moduleRoot = findModuleRoot(filePath);
|
|
342
|
-
if (!moduleRoot) return;
|
|
343
|
-
if (isInsideSubdirectory(filePath, moduleRoot)) return;
|
|
344
|
-
const sourceFileCount = countSourceFiles(moduleRoot);
|
|
345
|
-
if (sourceFileCount < fileThreshold) return;
|
|
346
|
-
const isHook = /^use[A-Z]/.test(fileName) && (fileName.endsWith(".ts") || fileName.endsWith(".tsx"));
|
|
347
|
-
const isComponent = fileName.endsWith(".tsx") && /^[A-Z]/.test(fileName);
|
|
348
|
-
const isDataFile = /[Dd]ata\.tsx?$/.test(fileName) || /\.data\.tsx?$/.test(fileName);
|
|
349
|
-
if (isDataFile && dirName === "sections") {
|
|
350
|
-
context.report({
|
|
351
|
-
loc: { line: 1, column: 0 },
|
|
352
|
-
messageId: "dataInSections",
|
|
353
|
-
data: {
|
|
354
|
-
fileName,
|
|
355
|
-
suggestedPath: `data/${fileName}`
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (isHook) {
|
|
361
|
-
context.report({
|
|
362
|
-
loc: { line: 1, column: 0 },
|
|
363
|
-
messageId: "hookAtRoot",
|
|
364
|
-
data: {
|
|
365
|
-
fileName,
|
|
366
|
-
suggestedPath: `hooks/${fileName}`
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
if (isComponent && !COMPONENT_EXEMPT_DIRS.has(dirName)) {
|
|
372
|
-
context.report({
|
|
373
|
-
loc: { line: 1, column: 0 },
|
|
374
|
-
messageId: "componentAtRoot",
|
|
375
|
-
data: {
|
|
376
|
-
fileName,
|
|
377
|
-
suggestedPath: `components/${fileName}`
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if (fileName.endsWith(".ts") && !isDataFile) {
|
|
383
|
-
context.report({
|
|
384
|
-
loc: { line: 1, column: 0 },
|
|
385
|
-
messageId: "utilAtRoot",
|
|
386
|
-
data: {
|
|
387
|
-
fileName,
|
|
388
|
-
suggestedPath: `utils/${fileName}`
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
var enforce_module_structure_default = {
|
|
397
|
-
rules: {
|
|
398
|
-
"enforce-module-structure": enforceModuleStructureRule
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
function discoverRoutePages(baseDir, options) {
|
|
402
|
-
const {
|
|
403
|
-
excludeFiles = ["_layout.tsx"],
|
|
404
|
-
excludeDirs = ["__tests__"],
|
|
405
|
-
rootIndexIsRedirect = true
|
|
406
|
-
} = options;
|
|
407
|
-
const routePages = [];
|
|
408
|
-
function walk(dir, relativePrefix) {
|
|
409
|
-
let entries;
|
|
410
|
-
try {
|
|
411
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
412
|
-
} catch {
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
for (const entry of entries) {
|
|
416
|
-
const fullPath = path.join(dir, entry.name);
|
|
417
|
-
const relativePath = path.join(relativePrefix, entry.name);
|
|
418
|
-
if (entry.isDirectory()) {
|
|
419
|
-
if (excludeDirs.includes(entry.name)) continue;
|
|
420
|
-
walk(fullPath, relativePath);
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
if (!entry.name.endsWith(".tsx")) continue;
|
|
424
|
-
if (excludeFiles.includes(entry.name)) continue;
|
|
425
|
-
if (entry.name.startsWith("_")) continue;
|
|
426
|
-
const normalizedRelative = relativePath.replace(/\\/g, "/");
|
|
427
|
-
if (rootIndexIsRedirect && normalizedRelative === "index.tsx") continue;
|
|
428
|
-
const withoutExt = normalizedRelative.replace(/\.tsx$/, "");
|
|
429
|
-
routePages.push(withoutExt);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
walk(baseDir, "");
|
|
433
|
-
return routePages;
|
|
434
|
-
}
|
|
435
|
-
function resolveImportToProjectRelative(importPath, fileDir, projectRoot) {
|
|
436
|
-
const absoluteResolved = path.resolve(fileDir, importPath);
|
|
437
|
-
const projectRelative = path.relative(projectRoot, absoluteResolved);
|
|
438
|
-
return projectRelative.replace(/\\/g, "/");
|
|
439
|
-
}
|
|
440
|
-
var enforceRoutePreloadRule = {
|
|
441
|
-
meta: {
|
|
442
|
-
type: "problem",
|
|
443
|
-
docs: {
|
|
444
|
-
description: "Ensure every route page in the configured directory has a matching dynamic import() in the preloader file",
|
|
445
|
-
category: "Best Practices",
|
|
446
|
-
recommended: true
|
|
447
|
-
},
|
|
448
|
-
schema: [
|
|
449
|
-
{
|
|
450
|
-
type: "object",
|
|
451
|
-
properties: {
|
|
452
|
-
routeDir: {
|
|
453
|
-
type: "string",
|
|
454
|
-
description: "Directory to scan for route pages, relative to project root",
|
|
455
|
-
default: "app/(protected)"
|
|
456
|
-
},
|
|
457
|
-
excludeFiles: {
|
|
458
|
-
type: "array",
|
|
459
|
-
items: { type: "string" },
|
|
460
|
-
description: "Filename patterns to skip",
|
|
461
|
-
default: ["_layout.tsx"]
|
|
462
|
-
},
|
|
463
|
-
excludeDirs: {
|
|
464
|
-
type: "array",
|
|
465
|
-
items: { type: "string" },
|
|
466
|
-
description: "Directory names to skip",
|
|
467
|
-
default: ["__tests__"]
|
|
468
|
-
},
|
|
469
|
-
rootIndexIsRedirect: {
|
|
470
|
-
type: "boolean",
|
|
471
|
-
description: "Whether the root index.tsx in routeDir is just a redirect and should be skipped",
|
|
472
|
-
default: true
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
additionalProperties: false
|
|
476
|
-
}
|
|
477
|
-
],
|
|
478
|
-
messages: {
|
|
479
|
-
missingPreload: `Route page "{{routeFile}}" is not preloaded. Add: import('{{importPath}}').catch(() => undefined);`,
|
|
480
|
-
stalePreload: 'Preload import "{{importPath}}" does not match any route page in {{routeDir}}/. Remove it or add the corresponding route page.',
|
|
481
|
-
noImportsFound: "Preloader file has no dynamic import() expressions. Add imports for all route pages in {{routeDir}}/."
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
create(context) {
|
|
485
|
-
const options = context.options[0] ?? {};
|
|
486
|
-
const routeDir = options.routeDir ?? "app/(protected)";
|
|
487
|
-
const excludeFiles = options.excludeFiles ?? ["_layout.tsx"];
|
|
488
|
-
const excludeDirs = options.excludeDirs ?? ["__tests__"];
|
|
489
|
-
const rootIndexIsRedirect = options.rootIndexIsRedirect ?? true;
|
|
490
|
-
const cwd = context.cwd ?? context.getCwd?.() ?? process.cwd();
|
|
491
|
-
const projectRoot = cwd;
|
|
492
|
-
const filename = context.filename ?? context.getFilename?.();
|
|
493
|
-
const fileDir = path.dirname(filename);
|
|
494
|
-
const routeDirAbsolute = path.resolve(projectRoot, routeDir);
|
|
495
|
-
const routePages = discoverRoutePages(routeDirAbsolute, {
|
|
496
|
-
excludeFiles,
|
|
497
|
-
excludeDirs,
|
|
498
|
-
rootIndexIsRedirect
|
|
499
|
-
});
|
|
500
|
-
const expectedRouteSet = new Set(
|
|
501
|
-
routePages.map((rp) => `${routeDir}/${rp}`.replace(/\\/g, "/"))
|
|
502
|
-
);
|
|
503
|
-
const importExpressions = [];
|
|
504
|
-
return {
|
|
505
|
-
// Collect all dynamic import() expressions in the file
|
|
506
|
-
ImportExpression(node) {
|
|
507
|
-
if (node.source?.type !== "Literal") return;
|
|
508
|
-
const rawPath = node.source.value;
|
|
509
|
-
const resolvedPath = resolveImportToProjectRelative(
|
|
510
|
-
rawPath,
|
|
511
|
-
fileDir,
|
|
512
|
-
projectRoot
|
|
513
|
-
);
|
|
514
|
-
importExpressions.push({ resolvedPath, rawPath, node });
|
|
515
|
-
},
|
|
516
|
-
"Program:exit"(programNode) {
|
|
517
|
-
if (expectedRouteSet.size === 0) return;
|
|
518
|
-
if (importExpressions.length === 0) {
|
|
519
|
-
context.report({
|
|
520
|
-
node: programNode,
|
|
521
|
-
messageId: "noImportsFound",
|
|
522
|
-
data: { routeDir }
|
|
523
|
-
});
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const importedPaths = new Set(
|
|
527
|
-
importExpressions.map((i) => i.resolvedPath)
|
|
528
|
-
);
|
|
529
|
-
for (const routePath of expectedRouteSet) {
|
|
530
|
-
if (!importedPaths.has(routePath)) {
|
|
531
|
-
const routeAbsolute = path.resolve(projectRoot, `${routePath}.tsx`);
|
|
532
|
-
let relativePath = path.relative(fileDir, routeAbsolute);
|
|
533
|
-
relativePath = relativePath.replace(/\\/g, "/");
|
|
534
|
-
if (!relativePath.startsWith("."))
|
|
535
|
-
relativePath = `./${relativePath}`;
|
|
536
|
-
relativePath = relativePath.replace(/\.tsx$/, "");
|
|
537
|
-
context.report({
|
|
538
|
-
node: programNode,
|
|
539
|
-
messageId: "missingPreload",
|
|
540
|
-
data: {
|
|
541
|
-
routeFile: routePath,
|
|
542
|
-
importPath: relativePath
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
for (const { resolvedPath, rawPath, node } of importExpressions) {
|
|
548
|
-
const normalizedRouteDir = routeDir.replace(/\\/g, "/");
|
|
549
|
-
if (!resolvedPath.startsWith(normalizedRouteDir)) continue;
|
|
550
|
-
if (!expectedRouteSet.has(resolvedPath))
|
|
551
|
-
context.report({
|
|
552
|
-
node,
|
|
553
|
-
messageId: "stalePreload",
|
|
554
|
-
data: {
|
|
555
|
-
importPath: rawPath,
|
|
556
|
-
routeDir
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
var enforce_route_preload_default = {
|
|
565
|
-
rules: {
|
|
566
|
-
"enforce-route-preload": enforceRoutePreloadRule
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
var enforceTestColocationRule = {
|
|
570
|
-
meta: {
|
|
571
|
-
type: "suggestion",
|
|
572
|
-
docs: {
|
|
573
|
-
description: "Test files should be co-located next to their source file, not placed in a __tests__/ directory.",
|
|
574
|
-
category: "Best Practices",
|
|
575
|
-
recommended: true
|
|
576
|
-
},
|
|
577
|
-
schema: [],
|
|
578
|
-
messages: {
|
|
579
|
-
testInTestsDir: 'Test file "{{fileName}}" is inside a __tests__/ directory. Move it next to its source file for co-location. Suggested: {{suggestedPath}}'
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
create(context) {
|
|
583
|
-
return {
|
|
584
|
-
Program() {
|
|
585
|
-
const filePath = context.filename || context.getFilename();
|
|
586
|
-
if (!filePath) return;
|
|
587
|
-
const fileName = basename(filePath);
|
|
588
|
-
if (!fileName.endsWith(".test.ts") && !fileName.endsWith(".test.tsx"))
|
|
589
|
-
return;
|
|
590
|
-
const normalized = filePath.split(sep).join(posix.sep);
|
|
591
|
-
if (!normalized.includes("/__tests__/")) return;
|
|
592
|
-
const dir = dirname(filePath);
|
|
593
|
-
const parentDir = dirname(dir);
|
|
594
|
-
const parentDirName = basename(parentDir);
|
|
595
|
-
context.report({
|
|
596
|
-
loc: { line: 1, column: 0 },
|
|
597
|
-
messageId: "testInTestsDir",
|
|
598
|
-
data: {
|
|
599
|
-
fileName,
|
|
600
|
-
suggestedPath: `${parentDirName}/${fileName}`
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
var enforce_test_colocation_default = {
|
|
608
|
-
rules: {
|
|
609
|
-
"enforce-test-colocation": enforceTestColocationRule
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
// src/rules/enum-file-isolation.js
|
|
614
|
-
var enumFileIsolationRule = {
|
|
615
|
-
meta: {
|
|
616
|
-
type: "suggestion",
|
|
617
|
-
docs: {
|
|
618
|
-
description: "Exported enums should live in dedicated files. Only related helpers may share the file.",
|
|
619
|
-
category: "Best Practices",
|
|
620
|
-
recommended: true
|
|
621
|
-
},
|
|
622
|
-
schema: [],
|
|
623
|
-
messages: {
|
|
624
|
-
multipleEnums: "File contains multiple exported enums ({{enumNames}}). Each enum should have its own dedicated file.",
|
|
625
|
-
unrelatedExports: 'Exported enum "{{enumName}}" is in a file with unrelated exports. Move the enum to a dedicated file (e.g., {{suggestedFile}}) or move unrelated exports elsewhere.'
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
create(context) {
|
|
629
|
-
const exportedEnums = [];
|
|
630
|
-
const otherExportNodes = [];
|
|
631
|
-
function collectExportedEnum(node) {
|
|
632
|
-
if (node.type === "ExportNamedDeclaration" && node.declaration && node.declaration.type === "TSEnumDeclaration") {
|
|
633
|
-
exportedEnums.push({
|
|
634
|
-
name: node.declaration.id.name,
|
|
635
|
-
node: node.declaration.id
|
|
636
|
-
});
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
function collectOtherExport(node) {
|
|
642
|
-
if (node.type !== "ExportNamedDeclaration") return;
|
|
643
|
-
if (node.declaration && node.declaration.type === "TSEnumDeclaration")
|
|
644
|
-
return;
|
|
645
|
-
otherExportNodes.push(node);
|
|
646
|
-
}
|
|
647
|
-
function referencesEnum(sourceText, enumName) {
|
|
648
|
-
const regex = new RegExp(`\\b${enumName}\\b`);
|
|
649
|
-
return regex.test(sourceText);
|
|
650
|
-
}
|
|
651
|
-
return {
|
|
652
|
-
ExportNamedDeclaration(node) {
|
|
653
|
-
if (!collectExportedEnum(node)) collectOtherExport(node);
|
|
654
|
-
},
|
|
655
|
-
"Program:exit"() {
|
|
656
|
-
if (exportedEnums.length === 0) return;
|
|
657
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
658
|
-
if (exportedEnums.length > 1) {
|
|
659
|
-
const enumNames = exportedEnums.map((e) => e.name).join(", ");
|
|
660
|
-
for (const enumInfo of exportedEnums) {
|
|
661
|
-
context.report({
|
|
662
|
-
node: enumInfo.node,
|
|
663
|
-
messageId: "multipleEnums",
|
|
664
|
-
data: { enumNames }
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
const enumName = exportedEnums[0].name;
|
|
670
|
-
const enumNode = exportedEnums[0].node;
|
|
671
|
-
if (otherExportNodes.length === 0) return;
|
|
672
|
-
const unrelatedExports = otherExportNodes.filter((node) => {
|
|
673
|
-
const text = sourceCode.getText(node);
|
|
674
|
-
return !referencesEnum(text, enumName);
|
|
675
|
-
});
|
|
676
|
-
if (unrelatedExports.length > 0) {
|
|
677
|
-
const suggestedFile = enumName.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().concat(".ts");
|
|
678
|
-
context.report({
|
|
679
|
-
node: enumNode,
|
|
680
|
-
messageId: "unrelatedExports",
|
|
681
|
-
data: { enumName, suggestedFile }
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
var enum_file_isolation_default = {
|
|
689
|
-
rules: {
|
|
690
|
-
"enum-file-isolation": enumFileIsolationRule
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
// src/rules/i18n-interpolation.js
|
|
695
|
-
var DOUBLE_BRACE_REGEX = /\{\{(\w+)\}\}/g;
|
|
696
|
-
var SINGLE_BRACE_REGEX = /(?<!\{)\{(\w+)\}(?!\})/g;
|
|
697
|
-
var ALLOWED_NAMES = /* @__PURE__ */ new Set(["p1", "p2", "p3"]);
|
|
698
|
-
var MAX_POSITIONAL_PARAMS = 3;
|
|
699
|
-
var rule = {
|
|
700
|
-
meta: {
|
|
701
|
-
type: "problem",
|
|
702
|
-
docs: {
|
|
703
|
-
description: "Enforce {{p1}}/{{p2}}/{{p3}} interpolation placeholders in translation JSON files"
|
|
704
|
-
},
|
|
705
|
-
fixable: "code",
|
|
706
|
-
schema: [],
|
|
707
|
-
messages: {
|
|
708
|
-
nonStandardPlaceholder: 'Non-standard placeholder "{{placeholder}}" found. Use {{p1}}/{{p2}}/{{p3}} instead.',
|
|
709
|
-
singleBracePlaceholder: 'Single-brace placeholder "{{{placeholder}}}" found. Use double braces: {{{{{fixedName}}}}}.',
|
|
710
|
-
tooManyPlaceholders: "Translation has {{count}} unique placeholders but FM() only supports 3. Refactor the translation string."
|
|
711
|
-
}
|
|
712
|
-
},
|
|
713
|
-
create(context) {
|
|
714
|
-
return {
|
|
715
|
-
JSONLiteral(node) {
|
|
716
|
-
if (typeof node.value !== "string") return;
|
|
717
|
-
const raw = node.value;
|
|
718
|
-
const doubleBraceMatches = [];
|
|
719
|
-
let match;
|
|
720
|
-
while ((match = DOUBLE_BRACE_REGEX.exec(raw)) !== null) {
|
|
721
|
-
if (!ALLOWED_NAMES.has(match[1]))
|
|
722
|
-
doubleBraceMatches.push({ name: match[1], index: match.index });
|
|
723
|
-
}
|
|
724
|
-
const singleBraceMatches = [];
|
|
725
|
-
while ((match = SINGLE_BRACE_REGEX.exec(raw)) !== null)
|
|
726
|
-
singleBraceMatches.push({ name: match[1], index: match.index });
|
|
727
|
-
const hasDoubleBraceIssues = doubleBraceMatches.length > 0;
|
|
728
|
-
const hasSingleBraceIssues = singleBraceMatches.length > 0;
|
|
729
|
-
if (!hasDoubleBraceIssues && !hasSingleBraceIssues) return;
|
|
730
|
-
const seenNames = [];
|
|
731
|
-
const allMatches = [...doubleBraceMatches, ...singleBraceMatches].sort(
|
|
732
|
-
(a, b) => a.index - b.index
|
|
733
|
-
);
|
|
734
|
-
for (const m of allMatches) {
|
|
735
|
-
if (!seenNames.includes(m.name) && !ALLOWED_NAMES.has(m.name))
|
|
736
|
-
seenNames.push(m.name);
|
|
737
|
-
}
|
|
738
|
-
const existingValid = /* @__PURE__ */ new Set();
|
|
739
|
-
let m2;
|
|
740
|
-
const tempRegex = /\{\{(\w+)\}\}/g;
|
|
741
|
-
while ((m2 = tempRegex.exec(raw)) !== null) {
|
|
742
|
-
if (ALLOWED_NAMES.has(m2[1])) existingValid.add(m2[1]);
|
|
743
|
-
}
|
|
744
|
-
const tempSingleRegex = /(?<!\{)\{(\w+)\}(?!\})/g;
|
|
745
|
-
while ((m2 = tempSingleRegex.exec(raw)) !== null) {
|
|
746
|
-
if (ALLOWED_NAMES.has(m2[1])) existingValid.add(m2[1]);
|
|
747
|
-
}
|
|
748
|
-
const totalUnique = seenNames.length + existingValid.size;
|
|
749
|
-
if (totalUnique > MAX_POSITIONAL_PARAMS) {
|
|
750
|
-
context.report({
|
|
751
|
-
node,
|
|
752
|
-
messageId: "tooManyPlaceholders",
|
|
753
|
-
data: { count: String(totalUnique) }
|
|
754
|
-
});
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
const usedPositional = new Set(existingValid);
|
|
758
|
-
const nameMap = {};
|
|
759
|
-
const positionalNames = ["p1", "p2", "p3"];
|
|
760
|
-
let nextIdx = 0;
|
|
761
|
-
for (const name of seenNames) {
|
|
762
|
-
while (nextIdx < positionalNames.length && usedPositional.has(positionalNames[nextIdx]))
|
|
763
|
-
nextIdx++;
|
|
764
|
-
if (nextIdx < positionalNames.length) {
|
|
765
|
-
nameMap[name] = positionalNames[nextIdx];
|
|
766
|
-
usedPositional.add(positionalNames[nextIdx]);
|
|
767
|
-
nextIdx++;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
if (hasDoubleBraceIssues) {
|
|
771
|
-
const fixedValue = raw.replace(DOUBLE_BRACE_REGEX, (full, name) => {
|
|
772
|
-
if (ALLOWED_NAMES.has(name)) return full;
|
|
773
|
-
const replacement = nameMap[name];
|
|
774
|
-
return replacement !== void 0 ? `{{${replacement}}}` : full;
|
|
775
|
-
});
|
|
776
|
-
context.report({
|
|
777
|
-
node,
|
|
778
|
-
messageId: "nonStandardPlaceholder",
|
|
779
|
-
data: { placeholder: doubleBraceMatches[0].name },
|
|
780
|
-
fix(fixer) {
|
|
781
|
-
let finalValue = fixedValue;
|
|
782
|
-
if (hasSingleBraceIssues)
|
|
783
|
-
finalValue = finalValue.replace(
|
|
784
|
-
SINGLE_BRACE_REGEX,
|
|
785
|
-
(full, name) => {
|
|
786
|
-
if (ALLOWED_NAMES.has(name)) return `{{${name}}}`;
|
|
787
|
-
const replacement = nameMap[name];
|
|
788
|
-
return replacement !== void 0 ? `{{${replacement}}}` : `{{${name}}}`;
|
|
789
|
-
}
|
|
790
|
-
);
|
|
791
|
-
return fixer.replaceText(node, JSON.stringify(finalValue));
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
} else if (hasSingleBraceIssues) {
|
|
795
|
-
const fixedValue = raw.replace(SINGLE_BRACE_REGEX, (full, name) => {
|
|
796
|
-
if (ALLOWED_NAMES.has(name)) return `{{${name}}}`;
|
|
797
|
-
const replacement = nameMap[name];
|
|
798
|
-
return replacement !== void 0 ? `{{${replacement}}}` : `{{${name}}}`;
|
|
799
|
-
});
|
|
800
|
-
context.report({
|
|
801
|
-
node,
|
|
802
|
-
messageId: "singleBracePlaceholder",
|
|
803
|
-
data: {
|
|
804
|
-
placeholder: singleBraceMatches[0].name,
|
|
805
|
-
fixedName: ALLOWED_NAMES.has(singleBraceMatches[0].name) ? singleBraceMatches[0].name : nameMap[singleBraceMatches[0].name] ?? singleBraceMatches[0].name
|
|
806
|
-
},
|
|
807
|
-
fix(fixer) {
|
|
808
|
-
return fixer.replaceText(node, JSON.stringify(fixedValue));
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
var i18n_interpolation_default = {
|
|
817
|
-
rules: {
|
|
818
|
-
"i18n-interpolation": rule
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
// src/rules/i18n-param-names.js
|
|
823
|
-
var ALLOWED_PARAM_NAMES = /* @__PURE__ */ new Set(["p1", "p2", "p3"]);
|
|
824
|
-
var I18NEXT_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
825
|
-
"defaultValue",
|
|
826
|
-
"ns",
|
|
827
|
-
"lng",
|
|
828
|
-
"context",
|
|
829
|
-
"returnObjects",
|
|
830
|
-
"keySeparator",
|
|
831
|
-
"nsSeparator",
|
|
832
|
-
"interpolation",
|
|
833
|
-
"joinArrays",
|
|
834
|
-
"postProcess",
|
|
835
|
-
"replace",
|
|
836
|
-
"ordinal",
|
|
837
|
-
"formatParams",
|
|
838
|
-
"missingInterpolationHandler"
|
|
839
|
-
]);
|
|
840
|
-
var rule2 = {
|
|
841
|
-
meta: {
|
|
842
|
-
type: "problem",
|
|
843
|
-
docs: {
|
|
844
|
-
description: "Enforce p1/p2/p3 parameter names in t() interpolation calls. Translation JSON uses {{p1}}/{{p2}}/{{p3}} placeholders, so call sites must pass { p1: value } \u2014 not { count: value } or other names.",
|
|
845
|
-
category: "Possible Errors",
|
|
846
|
-
recommended: true
|
|
847
|
-
},
|
|
848
|
-
schema: [],
|
|
849
|
-
messages: {
|
|
850
|
-
nonStandardParam: 'Non-standard interpolation param "{{paramName}}" in t() call. Translation placeholders use {{p1}}/{{p2}}/{{p3}}. Use FM(key, value) or t(key, { p1: value }) instead.',
|
|
851
|
-
preferFM: "Prefer FM() over t() for parameterized translations. FM() enforces positional params (p1, p2, p3) by design."
|
|
852
|
-
}
|
|
853
|
-
},
|
|
854
|
-
create(context) {
|
|
855
|
-
return {
|
|
856
|
-
CallExpression(node) {
|
|
857
|
-
if (node.callee.type !== "Identifier" || node.callee.name !== "t")
|
|
858
|
-
return;
|
|
859
|
-
if (node.arguments.length < 2) return;
|
|
860
|
-
const optionsArg = node.arguments.length >= 3 ? node.arguments[2] : node.arguments[1];
|
|
861
|
-
if (!optionsArg || optionsArg.type !== "ObjectExpression") return;
|
|
862
|
-
const properties = optionsArg.properties;
|
|
863
|
-
for (const prop of properties) {
|
|
864
|
-
if (prop.type === "SpreadElement") continue;
|
|
865
|
-
const keyName = prop.key.type === "Identifier" ? prop.key.name : prop.key.type === "Literal" ? String(prop.key.value) : null;
|
|
866
|
-
if (keyName === null) continue;
|
|
867
|
-
if (I18NEXT_CONFIG_KEYS.has(keyName)) continue;
|
|
868
|
-
if (!ALLOWED_PARAM_NAMES.has(keyName))
|
|
869
|
-
context.report({
|
|
870
|
-
node: prop,
|
|
871
|
-
messageId: "nonStandardParam",
|
|
872
|
-
data: { paramName: keyName }
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
var i18n_param_names_default = {
|
|
880
|
-
rules: {
|
|
881
|
-
"i18n-param-names": rule2
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
function isPureReExportFile(programNode) {
|
|
885
|
-
const { body } = programNode;
|
|
886
|
-
if (body.length === 0) return false;
|
|
887
|
-
return body.every((stmt) => {
|
|
888
|
-
if (stmt.type === "ImportDeclaration") return true;
|
|
889
|
-
if (stmt.type === "ExportAllDeclaration") return true;
|
|
890
|
-
const isReExport = stmt.type === "ExportNamedDeclaration" && stmt.source !== null;
|
|
891
|
-
return isReExport;
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
var noBarrelCompanionFileRule = {
|
|
895
|
-
meta: {
|
|
896
|
-
type: "problem",
|
|
897
|
-
fixable: "code",
|
|
898
|
-
docs: {
|
|
899
|
-
description: "Disallow .ts/.tsx files that shadow a same-named directory barrel (index.ts). This causes TypeScript to resolve imports to the file instead of the barrel, leading to missing export errors.",
|
|
900
|
-
category: "Possible Errors",
|
|
901
|
-
recommended: true
|
|
902
|
-
},
|
|
903
|
-
schema: [],
|
|
904
|
-
messages: {
|
|
905
|
-
companionFileConflict: 'File "{{fileName}}" shadows the barrel "{{barrelPath}}". TypeScript resolves `import from \'./{{baseName}}\'` to this file, ignoring the barrel. Delete this file and update imports to use the barrel, or consolidate into one location.'
|
|
906
|
-
}
|
|
907
|
-
},
|
|
908
|
-
create(context) {
|
|
909
|
-
return {
|
|
910
|
-
Program(node) {
|
|
911
|
-
const filePath = context.filename || context.getFilename();
|
|
912
|
-
if (!filePath || !filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) return;
|
|
913
|
-
if (filePath.endsWith(".d.ts")) return;
|
|
914
|
-
const fileBaseName = basename(filePath);
|
|
915
|
-
if (fileBaseName === "index.ts" || fileBaseName === "index.tsx") return;
|
|
916
|
-
const ext = fileBaseName.endsWith(".tsx") ? ".tsx" : ".ts";
|
|
917
|
-
const baseName = fileBaseName.slice(0, -ext.length);
|
|
918
|
-
const dir = dirname(filePath);
|
|
919
|
-
const siblingDir = join(dir, baseName);
|
|
920
|
-
const barrelTs = join(siblingDir, "index.ts");
|
|
921
|
-
const barrelTsx = join(siblingDir, "index.tsx");
|
|
922
|
-
const hasBarrelTs = existsSync(barrelTs);
|
|
923
|
-
const hasBarrelTsx = existsSync(barrelTsx);
|
|
924
|
-
if (hasBarrelTs || hasBarrelTsx) {
|
|
925
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
926
|
-
const trimmed = sourceCode.text.trim();
|
|
927
|
-
const safePattern = `export * from './${baseName}/index';`;
|
|
928
|
-
if (trimmed === safePattern) return;
|
|
929
|
-
const barrelPath = hasBarrelTs ? `${baseName}/index.ts` : `${baseName}/index.tsx`;
|
|
930
|
-
const canAutoFix = isPureReExportFile(node);
|
|
931
|
-
context.report({
|
|
932
|
-
node,
|
|
933
|
-
messageId: "companionFileConflict",
|
|
934
|
-
data: {
|
|
935
|
-
fileName: fileBaseName,
|
|
936
|
-
barrelPath,
|
|
937
|
-
baseName
|
|
938
|
-
},
|
|
939
|
-
...canAutoFix && {
|
|
940
|
-
fix(fixer) {
|
|
941
|
-
const fullRange = [0, sourceCode.text.length];
|
|
942
|
-
const replacement = `export * from './${baseName}/index';
|
|
943
|
-
`;
|
|
944
|
-
return fixer.replaceTextRange(fullRange, replacement);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
}
|
|
952
|
-
};
|
|
953
|
-
var no_barrel_companion_file_default = {
|
|
954
|
-
rules: {
|
|
955
|
-
"no-barrel-companion-file": noBarrelCompanionFileRule
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
|
|
959
|
-
// src/rules/no-duplicate-nav-prefix.js
|
|
960
|
-
function createDuplicateChecker(propName, messageId) {
|
|
961
|
-
return {
|
|
962
|
-
/** @param {import('estree').ArrayExpression} node */
|
|
963
|
-
check(node, context) {
|
|
964
|
-
const objectsWithProp = node.elements.filter(
|
|
965
|
-
(el) => el && el.type === "ObjectExpression" && el.properties.some(
|
|
966
|
-
(p) => p.type === "Property" && p.key.type === "Identifier" && p.key.name === propName
|
|
967
|
-
)
|
|
968
|
-
);
|
|
969
|
-
if (objectsWithProp.length === 0) return;
|
|
970
|
-
const seen = /* @__PURE__ */ new Map();
|
|
971
|
-
for (const obj of objectsWithProp) {
|
|
972
|
-
const prop = obj.properties.find(
|
|
973
|
-
(p) => p.type === "Property" && p.key.type === "Identifier" && p.key.name === propName
|
|
974
|
-
);
|
|
975
|
-
if (!prop) continue;
|
|
976
|
-
let value;
|
|
977
|
-
if (prop.value.type === "Literal") {
|
|
978
|
-
value = String(prop.value.value);
|
|
979
|
-
} else if (prop.value.type === "MemberExpression") {
|
|
980
|
-
const src = context.sourceCode || context.getSourceCode();
|
|
981
|
-
value = src.getText(prop.value);
|
|
982
|
-
} else if (prop.value.type === "TemplateLiteral" && prop.value.quasis.length === 1) {
|
|
983
|
-
value = prop.value.quasis[0].value.cooked;
|
|
984
|
-
} else {
|
|
985
|
-
continue;
|
|
986
|
-
}
|
|
987
|
-
if (seen.has(value)) {
|
|
988
|
-
context.report({
|
|
989
|
-
node: prop.value,
|
|
990
|
-
messageId,
|
|
991
|
-
data: { value }
|
|
992
|
-
});
|
|
993
|
-
} else {
|
|
994
|
-
seen.set(value, prop);
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
};
|
|
999
|
-
}
|
|
1000
|
-
var noDuplicateNavPrefixRule = {
|
|
1001
|
-
meta: {
|
|
1002
|
-
type: "problem",
|
|
1003
|
-
docs: {
|
|
1004
|
-
description: "Disallow duplicate route or key values in module sidebarItems. Duplicate routes cause navigation collisions; duplicate keys cause rendering issues.",
|
|
1005
|
-
category: "Possible Errors",
|
|
1006
|
-
recommended: true
|
|
1007
|
-
},
|
|
1008
|
-
schema: [],
|
|
1009
|
-
messages: {
|
|
1010
|
-
duplicateRoute: 'Duplicate route "{{value}}" - each sidebar item must have a unique route.',
|
|
1011
|
-
duplicateKey: 'Duplicate key "{{value}}" - each sidebar item must have a unique key.'
|
|
1012
|
-
}
|
|
1013
|
-
},
|
|
1014
|
-
create(context) {
|
|
1015
|
-
const routeChecker = createDuplicateChecker("route", "duplicateRoute");
|
|
1016
|
-
const keyChecker = createDuplicateChecker("key", "duplicateKey");
|
|
1017
|
-
return {
|
|
1018
|
-
ArrayExpression(node) {
|
|
1019
|
-
routeChecker.check(node, context);
|
|
1020
|
-
keyChecker.check(node, context);
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
var no_duplicate_nav_prefix_default = {
|
|
1026
|
-
rules: {
|
|
1027
|
-
"no-duplicate-nav-prefix": noDuplicateNavPrefixRule
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
function normalizePath(filePath) {
|
|
1031
|
-
return filePath.split(sep).join(posix.sep);
|
|
1032
|
-
}
|
|
1033
|
-
function collectComponentNames(dirPath) {
|
|
1034
|
-
const names = /* @__PURE__ */ new Set();
|
|
1035
|
-
if (!existsSync(dirPath)) return names;
|
|
1036
|
-
function walk(dir) {
|
|
1037
|
-
try {
|
|
1038
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
1039
|
-
for (const entry of entries) {
|
|
1040
|
-
if (entry.isDirectory()) {
|
|
1041
|
-
walk(join(dir, entry.name));
|
|
1042
|
-
continue;
|
|
1043
|
-
}
|
|
1044
|
-
const name = entry.name;
|
|
1045
|
-
if (!name.endsWith(".tsx")) continue;
|
|
1046
|
-
if (name.endsWith(".test.tsx")) continue;
|
|
1047
|
-
if (name === "index.tsx") continue;
|
|
1048
|
-
names.add(name);
|
|
1049
|
-
}
|
|
1050
|
-
} catch {
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
walk(dirPath);
|
|
1054
|
-
return names;
|
|
1055
|
-
}
|
|
1056
|
-
function isInsideProductDirectory(filePath) {
|
|
1057
|
-
const normalized = normalizePath(filePath);
|
|
1058
|
-
return normalized.includes("/packages/") && normalized.includes("-module/src/") || normalized.includes("/src/features/");
|
|
1059
|
-
}
|
|
1060
|
-
function findSharedComponentsDir(filePath) {
|
|
1061
|
-
const normalized = normalizePath(filePath);
|
|
1062
|
-
const baseClientIdx = normalized.indexOf("/BaseClient/");
|
|
1063
|
-
if (baseClientIdx === -1) return null;
|
|
1064
|
-
const baseClientRoot = filePath.split(sep).join(posix.sep).slice(0, baseClientIdx + "/BaseClient".length);
|
|
1065
|
-
const osPath = baseClientRoot.split(posix.sep).join(sep);
|
|
1066
|
-
return join(osPath, "src", "components");
|
|
1067
|
-
}
|
|
1068
|
-
var sharedNamesCache = /* @__PURE__ */ new Map();
|
|
1069
|
-
var noDuplicateSharedPatternsRule = {
|
|
1070
|
-
meta: {
|
|
1071
|
-
type: "suggestion",
|
|
1072
|
-
docs: {
|
|
1073
|
-
description: "Warn when product modules create components that share names with existing shared components in src/components/.",
|
|
1074
|
-
category: "Best Practices",
|
|
1075
|
-
recommended: false
|
|
1076
|
-
},
|
|
1077
|
-
schema: [],
|
|
1078
|
-
messages: {
|
|
1079
|
-
duplicateSharedPattern: '"{{fileName}}" already exists as a shared component in src/components/. Consider reusing the shared version or renaming this component to clarify its purpose.'
|
|
1080
|
-
}
|
|
1081
|
-
},
|
|
1082
|
-
create(context) {
|
|
1083
|
-
const filePath = context.filename || context.getFilename();
|
|
1084
|
-
if (!filePath) return {};
|
|
1085
|
-
if (!filePath.endsWith(".tsx")) return {};
|
|
1086
|
-
const fileName = basename(filePath);
|
|
1087
|
-
if (fileName.endsWith(".test.tsx")) return {};
|
|
1088
|
-
if (fileName === "index.tsx") return {};
|
|
1089
|
-
if (!isInsideProductDirectory(filePath)) return {};
|
|
1090
|
-
return {
|
|
1091
|
-
Program() {
|
|
1092
|
-
const componentsDir = findSharedComponentsDir(filePath);
|
|
1093
|
-
if (!componentsDir) return;
|
|
1094
|
-
if (!sharedNamesCache.has(componentsDir))
|
|
1095
|
-
sharedNamesCache.set(
|
|
1096
|
-
componentsDir,
|
|
1097
|
-
collectComponentNames(componentsDir)
|
|
1098
|
-
);
|
|
1099
|
-
const sharedNames = sharedNamesCache.get(componentsDir);
|
|
1100
|
-
if (sharedNames.has(fileName))
|
|
1101
|
-
context.report({
|
|
1102
|
-
loc: { line: 1, column: 0 },
|
|
1103
|
-
messageId: "duplicateSharedPattern",
|
|
1104
|
-
data: { fileName }
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
var no_duplicate_shared_patterns_default = {
|
|
1111
|
-
rules: {
|
|
1112
|
-
"no-duplicate-shared-patterns": noDuplicateSharedPatternsRule
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
// src/rules/no-generated-models-barrel-value-import.js
|
|
1117
|
-
var BARREL_PATTERN = /autoGeneratedHooks\/[^/]+\/models(?:\/index)?$/;
|
|
1118
|
-
function isTypeOnlyImport(node) {
|
|
1119
|
-
if (node.importKind === "type") return true;
|
|
1120
|
-
const specifiers = node.specifiers ?? [];
|
|
1121
|
-
if (specifiers.length === 0) return false;
|
|
1122
|
-
return specifiers.every((s) => s.importKind === "type");
|
|
1123
|
-
}
|
|
1124
|
-
var noGeneratedModelsBarrelValueImportRule = {
|
|
1125
|
-
meta: {
|
|
1126
|
-
type: "problem",
|
|
1127
|
-
docs: {
|
|
1128
|
-
description: "Disallow runtime (value) imports from generated model barrels; use specific leaf modules or type-only imports.",
|
|
1129
|
-
category: "Best Practices",
|
|
1130
|
-
recommended: true
|
|
1131
|
-
},
|
|
1132
|
-
schema: [],
|
|
1133
|
-
messages: {
|
|
1134
|
-
noValueImport: 'Do not import runtime values from "{{module}}". Import from a specific leaf model module instead (e.g. \u2026/models/questionType). Type-only imports are allowed.'
|
|
1135
|
-
}
|
|
1136
|
-
},
|
|
1137
|
-
create(context) {
|
|
1138
|
-
return {
|
|
1139
|
-
ImportDeclaration(node) {
|
|
1140
|
-
const moduleName = node.source?.value;
|
|
1141
|
-
if (typeof moduleName !== "string") return;
|
|
1142
|
-
if (!BARREL_PATTERN.test(moduleName)) return;
|
|
1143
|
-
if (isTypeOnlyImport(node)) return;
|
|
1144
|
-
context.report({
|
|
1145
|
-
node,
|
|
1146
|
-
messageId: "noValueImport",
|
|
1147
|
-
data: { module: moduleName }
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
var no_generated_models_barrel_value_import_default = {
|
|
1154
|
-
rules: {
|
|
1155
|
-
"no-generated-models-barrel-value-import": noGeneratedModelsBarrelValueImportRule
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
// src/rules/no-null-check.js
|
|
1160
|
-
var noNullCheckRule = {
|
|
1161
|
-
meta: {
|
|
1162
|
-
type: "suggestion",
|
|
1163
|
-
docs: {
|
|
1164
|
-
description: "Disallow direct null/undefined checks. Use isValueDefined() or isNullOrUndefined() instead.",
|
|
1165
|
-
category: "Best Practices",
|
|
1166
|
-
recommended: true
|
|
1167
|
-
},
|
|
1168
|
-
fixable: "code",
|
|
1169
|
-
schema: [
|
|
1170
|
-
{
|
|
1171
|
-
type: "object",
|
|
1172
|
-
properties: {
|
|
1173
|
-
utilImportPath: {
|
|
1174
|
-
type: "string",
|
|
1175
|
-
description: "Import path for the utility functions",
|
|
1176
|
-
default: "@dloizides/utils"
|
|
1177
|
-
}
|
|
1178
|
-
},
|
|
1179
|
-
additionalProperties: false
|
|
1180
|
-
}
|
|
1181
|
-
],
|
|
1182
|
-
messages: {
|
|
1183
|
-
noNotEqualsNull: 'Avoid "!== null" checks. Use isValueDefined({{identifier}}) instead, which handles both null and undefined.',
|
|
1184
|
-
noEqualsNull: 'Avoid "=== null" checks. Use !isValueDefined({{identifier}}) or isNullOrUndefined({{identifier}}) instead.',
|
|
1185
|
-
noNotEqualsNullComplex: 'Avoid "!== null" checks. Use isValueDefined() instead, which handles both null and undefined.',
|
|
1186
|
-
noEqualsNullComplex: 'Avoid "=== null" checks. Use !isValueDefined() or isNullOrUndefined() instead.',
|
|
1187
|
-
noNotEqualsUndefined: 'Avoid "!== undefined" checks. Use isValueDefined({{identifier}}) instead, which handles both null and undefined.',
|
|
1188
|
-
noEqualsUndefined: 'Avoid "=== undefined" checks. Use !isValueDefined({{identifier}}) or isNullOrUndefined({{identifier}}) instead.',
|
|
1189
|
-
noNotEqualsUndefinedComplex: 'Avoid "!== undefined" checks. Use isValueDefined() instead, which handles both null and undefined.',
|
|
1190
|
-
noEqualsUndefinedComplex: 'Avoid "=== undefined" checks. Use !isValueDefined() or isNullOrUndefined() instead.'
|
|
1191
|
-
}
|
|
1192
|
-
},
|
|
1193
|
-
create(context) {
|
|
1194
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
1195
|
-
function isNullLiteral(node) {
|
|
1196
|
-
return node && node.type === "Literal" && node.value === null;
|
|
1197
|
-
}
|
|
1198
|
-
function isUndefinedIdentifier(node) {
|
|
1199
|
-
return node && node.type === "Identifier" && node.name === "undefined";
|
|
1200
|
-
}
|
|
1201
|
-
function getNodeText(node) {
|
|
1202
|
-
return sourceCode.getText(node);
|
|
1203
|
-
}
|
|
1204
|
-
function isSimpleIdentifier(node) {
|
|
1205
|
-
return node.type === "Identifier" || node.type === "MemberExpression" && !node.computed;
|
|
1206
|
-
}
|
|
1207
|
-
function checkBinaryExpression(node) {
|
|
1208
|
-
const { operator, left, right } = node;
|
|
1209
|
-
if (operator !== "===" && operator !== "!==") {
|
|
1210
|
-
return;
|
|
1211
|
-
}
|
|
1212
|
-
const leftIsNull = isNullLiteral(left);
|
|
1213
|
-
const rightIsNull = isNullLiteral(right);
|
|
1214
|
-
const leftIsUndefined = isUndefinedIdentifier(left);
|
|
1215
|
-
const rightIsUndefined = isUndefinedIdentifier(right);
|
|
1216
|
-
const isNullCheck = leftIsNull || rightIsNull;
|
|
1217
|
-
const isUndefinedCheck = leftIsUndefined || rightIsUndefined;
|
|
1218
|
-
if (!isNullCheck && !isUndefinedCheck) {
|
|
1219
|
-
return;
|
|
1220
|
-
}
|
|
1221
|
-
const valueNode = leftIsNull || leftIsUndefined ? right : left;
|
|
1222
|
-
const valueText = getNodeText(valueNode);
|
|
1223
|
-
const isSimple = isSimpleIdentifier(valueNode);
|
|
1224
|
-
if (operator === "!==") {
|
|
1225
|
-
const messageId = isNullCheck ? isSimple ? "noNotEqualsNull" : "noNotEqualsNullComplex" : isSimple ? "noNotEqualsUndefined" : "noNotEqualsUndefinedComplex";
|
|
1226
|
-
context.report({
|
|
1227
|
-
node,
|
|
1228
|
-
messageId,
|
|
1229
|
-
data: isSimple ? { identifier: valueText } : {},
|
|
1230
|
-
fix(fixer) {
|
|
1231
|
-
return fixer.replaceText(node, `isValueDefined(${valueText})`);
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
} else {
|
|
1235
|
-
const messageId = isNullCheck ? isSimple ? "noEqualsNull" : "noEqualsNullComplex" : isSimple ? "noEqualsUndefined" : "noEqualsUndefinedComplex";
|
|
1236
|
-
context.report({
|
|
1237
|
-
node,
|
|
1238
|
-
messageId,
|
|
1239
|
-
data: isSimple ? { identifier: valueText } : {},
|
|
1240
|
-
fix(fixer) {
|
|
1241
|
-
return fixer.replaceText(node, `!isValueDefined(${valueText})`);
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
return {
|
|
1247
|
-
BinaryExpression: checkBinaryExpression
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
var no_null_check_default = {
|
|
1252
|
-
rules: {
|
|
1253
|
-
"no-null-check": noNullCheckRule
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
|
|
1257
|
-
// src/rules/no-optional-undefined.js
|
|
1258
|
-
var no_optional_undefined_default = {
|
|
1259
|
-
rules: {
|
|
1260
|
-
"no-optional-undefined": {
|
|
1261
|
-
meta: {
|
|
1262
|
-
type: "suggestion",
|
|
1263
|
-
docs: {
|
|
1264
|
-
description: "Disallow combining optional marker (?) with `| undefined` in type annotations"
|
|
1265
|
-
},
|
|
1266
|
-
messages: {
|
|
1267
|
-
noOptionalUndefined: "Do not combine optional (?) with `| undefined`. Use `?: {{type}}` and omit the key when the value is undefined."
|
|
1268
|
-
},
|
|
1269
|
-
schema: []
|
|
1270
|
-
},
|
|
1271
|
-
create(context) {
|
|
1272
|
-
function getTypeWithoutUndefined(typeAnnotation) {
|
|
1273
|
-
if (!typeAnnotation || typeAnnotation.type !== "TSUnionType") return null;
|
|
1274
|
-
const hasUndefined = typeAnnotation.types.some(
|
|
1275
|
-
(t) => t.type === "TSUndefinedKeyword"
|
|
1276
|
-
);
|
|
1277
|
-
if (!hasUndefined) return null;
|
|
1278
|
-
const nonUndefinedTypes = typeAnnotation.types.filter(
|
|
1279
|
-
(t) => t.type !== "TSUndefinedKeyword"
|
|
1280
|
-
);
|
|
1281
|
-
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
1282
|
-
if (nonUndefinedTypes.length === 1)
|
|
1283
|
-
return sourceCode.getText(nonUndefinedTypes[0]);
|
|
1284
|
-
return nonUndefinedTypes.map((t) => sourceCode.getText(t)).join(" | ");
|
|
1285
|
-
}
|
|
1286
|
-
function checkNode(node, typeAnnotationNode) {
|
|
1287
|
-
if (!node.optional) return;
|
|
1288
|
-
if (!typeAnnotationNode) return;
|
|
1289
|
-
const annotation = typeAnnotationNode.typeAnnotation ?? typeAnnotationNode;
|
|
1290
|
-
const cleanType = getTypeWithoutUndefined(annotation);
|
|
1291
|
-
if (cleanType === null) return;
|
|
1292
|
-
context.report({
|
|
1293
|
-
node: typeAnnotationNode,
|
|
1294
|
-
messageId: "noOptionalUndefined",
|
|
1295
|
-
data: { type: cleanType }
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
return {
|
|
1299
|
-
// Interface / type alias properties: foo?: string | undefined
|
|
1300
|
-
TSPropertySignature(node) {
|
|
1301
|
-
checkNode(node, node.typeAnnotation?.typeAnnotation);
|
|
1302
|
-
},
|
|
1303
|
-
// Function parameters: function foo(bar?: string | undefined)
|
|
1304
|
-
// Arrow functions, methods, etc.
|
|
1305
|
-
Identifier(node) {
|
|
1306
|
-
if (!node.optional) return;
|
|
1307
|
-
const parent = node.parent;
|
|
1308
|
-
if (!parent) return;
|
|
1309
|
-
const isParam = (parent.type === "FunctionDeclaration" || parent.type === "FunctionExpression" || parent.type === "ArrowFunctionExpression") && parent.params.includes(node);
|
|
1310
|
-
if (!isParam) return;
|
|
1311
|
-
checkNode(node, node.typeAnnotation?.typeAnnotation);
|
|
1312
|
-
}
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
};
|
|
1318
|
-
var ALLOWED_BASECLIENT_PACKAGES = /* @__PURE__ */ new Set([
|
|
1319
|
-
"@baseclient/core",
|
|
1320
|
-
"@baseclient/identity-client",
|
|
1321
|
-
"@baseclient/identity-module"
|
|
1322
|
-
]);
|
|
1323
|
-
var PRODUCT_HOOK_DIRS = /* @__PURE__ */ new Set([
|
|
1324
|
-
"onlinemenu",
|
|
1325
|
-
"questioner",
|
|
1326
|
-
"content",
|
|
1327
|
-
"notification"
|
|
1328
|
-
]);
|
|
1329
|
-
function normalizePath2(filePath) {
|
|
1330
|
-
return filePath.split(sep).join(posix.sep);
|
|
1331
|
-
}
|
|
1332
|
-
function isInsideSharedComponents(filePath) {
|
|
1333
|
-
const normalized = normalizePath2(filePath);
|
|
1334
|
-
return normalized.includes("/src/components/");
|
|
1335
|
-
}
|
|
1336
|
-
function isBannedBaseclientModule(source) {
|
|
1337
|
-
if (!source.startsWith("@baseclient/")) return false;
|
|
1338
|
-
if (ALLOWED_BASECLIENT_PACKAGES.has(source)) return false;
|
|
1339
|
-
return source.endsWith("-module");
|
|
1340
|
-
}
|
|
1341
|
-
function isBannedAutoGeneratedHook(source) {
|
|
1342
|
-
const normalized = normalizePath2(source);
|
|
1343
|
-
for (const dir of PRODUCT_HOOK_DIRS) {
|
|
1344
|
-
if (normalized.includes(`autoGeneratedHooks/${dir}`)) return true;
|
|
1345
|
-
if (normalized.includes(`autoGeneratedHooks/${dir}/`)) return true;
|
|
1346
|
-
}
|
|
1347
|
-
return false;
|
|
1348
|
-
}
|
|
1349
|
-
function isBannedFeatureOrModulePath(source) {
|
|
1350
|
-
const normalized = normalizePath2(source);
|
|
1351
|
-
return normalized.includes("/src/features/") || normalized.includes("/src/modules/") || normalized.includes("/features/") || normalized.includes("/modules/");
|
|
1352
|
-
}
|
|
1353
|
-
var noProductImportsInSharedRule = {
|
|
1354
|
-
meta: {
|
|
1355
|
-
type: "problem",
|
|
1356
|
-
docs: {
|
|
1357
|
-
description: "Disallow product-specific imports in src/components/. Shared components must not depend on product modules.",
|
|
1358
|
-
category: "Best Practices",
|
|
1359
|
-
recommended: true
|
|
1360
|
-
},
|
|
1361
|
-
schema: [],
|
|
1362
|
-
messages: {
|
|
1363
|
-
productImportInShared: "Shared components in src/components/ must not import from product-specific modules ({{source}}). Move product-specific logic to the feature module, or extract shared types to @baseclient/core."
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
create(context) {
|
|
1367
|
-
const filePath = context.filename || context.getFilename();
|
|
1368
|
-
if (!filePath) return {};
|
|
1369
|
-
if (!isInsideSharedComponents(filePath)) return {};
|
|
1370
|
-
function checkImportSource(node) {
|
|
1371
|
-
const source = node.source;
|
|
1372
|
-
if (!source) return;
|
|
1373
|
-
const importPath = source.value;
|
|
1374
|
-
if (typeof importPath !== "string") return;
|
|
1375
|
-
const isBanned = isBannedBaseclientModule(importPath) || isBannedAutoGeneratedHook(importPath) || isBannedFeatureOrModulePath(importPath);
|
|
1376
|
-
if (isBanned)
|
|
1377
|
-
context.report({
|
|
1378
|
-
node,
|
|
1379
|
-
messageId: "productImportInShared",
|
|
1380
|
-
data: { source: importPath }
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
return {
|
|
1384
|
-
ImportDeclaration: checkImportSource,
|
|
1385
|
-
ExportNamedDeclaration: checkImportSource,
|
|
1386
|
-
ExportAllDeclaration: checkImportSource
|
|
1387
|
-
};
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
var no_product_imports_in_shared_default = {
|
|
1391
|
-
rules: {
|
|
1392
|
-
"no-product-imports-in-shared": noProductImportsInSharedRule
|
|
1393
|
-
}
|
|
1394
|
-
};
|
|
1395
|
-
|
|
1396
|
-
// src/rules/prefer-const-enum.js
|
|
1397
|
-
function toPascalCase(value) {
|
|
1398
|
-
const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[-_\s]+/).filter((w) => w.length > 0);
|
|
1399
|
-
const result = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
1400
|
-
if (/^\d/.test(result)) return `_${result}`;
|
|
1401
|
-
return result;
|
|
1402
|
-
}
|
|
1403
|
-
var preferConstEnumRule = {
|
|
1404
|
-
meta: {
|
|
1405
|
-
type: "suggestion",
|
|
1406
|
-
docs: {
|
|
1407
|
-
description: "Prefer const enum over string literal union types for better autocomplete, refactoring, and centralized definitions.",
|
|
1408
|
-
category: "Best Practices",
|
|
1409
|
-
recommended: true
|
|
1410
|
-
},
|
|
1411
|
-
hasSuggestions: true,
|
|
1412
|
-
schema: [],
|
|
1413
|
-
messages: {
|
|
1414
|
-
preferConstEnum: 'String literal union type "{{name}}" should be a const enum. Const enums provide autocomplete, refactoring support, and centralized definitions.',
|
|
1415
|
-
convertToConstEnum: 'Convert "{{name}}" to const enum'
|
|
1416
|
-
}
|
|
1417
|
-
},
|
|
1418
|
-
create(context) {
|
|
1419
|
-
return {
|
|
1420
|
-
TSTypeAliasDeclaration(node) {
|
|
1421
|
-
const { typeAnnotation } = node;
|
|
1422
|
-
if (typeAnnotation.type !== "TSUnionType") return;
|
|
1423
|
-
const { types } = typeAnnotation;
|
|
1424
|
-
if (types.length < 2) return;
|
|
1425
|
-
const allStringLiterals = types.every(
|
|
1426
|
-
(member) => member.type === "TSLiteralType" && member.literal.type === "Literal" && typeof member.literal.value === "string"
|
|
1427
|
-
);
|
|
1428
|
-
if (!allStringLiterals) return;
|
|
1429
|
-
const typeName = node.id.name;
|
|
1430
|
-
const isExported = node.parent.type === "ExportNamedDeclaration";
|
|
1431
|
-
const exportPrefix = isExported ? "export " : "";
|
|
1432
|
-
const enumMembers = types.map((member) => {
|
|
1433
|
-
const value = member.literal.value;
|
|
1434
|
-
const memberName = toPascalCase(value);
|
|
1435
|
-
return ` ${memberName} = '${value}',`;
|
|
1436
|
-
}).join("\n");
|
|
1437
|
-
const replacement = `${exportPrefix}const enum ${typeName} {
|
|
1438
|
-
${enumMembers}
|
|
1439
|
-
}`;
|
|
1440
|
-
const targetNode = isExported ? node.parent : node;
|
|
1441
|
-
context.report({
|
|
1442
|
-
node: node.id,
|
|
1443
|
-
messageId: "preferConstEnum",
|
|
1444
|
-
data: { name: typeName },
|
|
1445
|
-
suggest: [
|
|
1446
|
-
{
|
|
1447
|
-
messageId: "convertToConstEnum",
|
|
1448
|
-
data: { name: typeName },
|
|
1449
|
-
fix(fixer) {
|
|
1450
|
-
return fixer.replaceText(targetNode, replacement);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
]
|
|
1454
|
-
});
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
};
|
|
1459
|
-
var prefer_const_enum_default = {
|
|
1460
|
-
rules: {
|
|
1461
|
-
"prefer-const-enum": preferConstEnumRule
|
|
1462
|
-
}
|
|
1463
|
-
};
|
|
1464
|
-
|
|
1465
|
-
// src/rules/require-stable-hook-args.js
|
|
1466
|
-
var STABLE_INIT_CALLS = /* @__PURE__ */ new Set([
|
|
1467
|
-
"useCallback",
|
|
1468
|
-
"useMemo",
|
|
1469
|
-
"useRef",
|
|
1470
|
-
"useState",
|
|
1471
|
-
"useReducer",
|
|
1472
|
-
"useContext",
|
|
1473
|
-
"useId",
|
|
1474
|
-
"useDeferredValue",
|
|
1475
|
-
"useTransition",
|
|
1476
|
-
"useSyncExternalStore",
|
|
1477
|
-
"useActionState",
|
|
1478
|
-
"useFormStatus",
|
|
1479
|
-
"useOptimistic",
|
|
1480
|
-
"StyleSheet.create",
|
|
1481
|
-
"Object.freeze"
|
|
1482
|
-
]);
|
|
1483
|
-
var IGNORED_HOOKS = /* @__PURE__ */ new Set([
|
|
1484
|
-
// React built-in
|
|
1485
|
-
"useState",
|
|
1486
|
-
"useEffect",
|
|
1487
|
-
"useLayoutEffect",
|
|
1488
|
-
"useCallback",
|
|
1489
|
-
"useMemo",
|
|
1490
|
-
"useRef",
|
|
1491
|
-
"useReducer",
|
|
1492
|
-
"useContext",
|
|
1493
|
-
"useImperativeHandle",
|
|
1494
|
-
"useDebugValue",
|
|
1495
|
-
"useId",
|
|
1496
|
-
"useDeferredValue",
|
|
1497
|
-
"useTransition",
|
|
1498
|
-
"useSyncExternalStore",
|
|
1499
|
-
"useInsertionEffect",
|
|
1500
|
-
"useActionState",
|
|
1501
|
-
"useFormStatus",
|
|
1502
|
-
"useOptimistic",
|
|
1503
|
-
"use",
|
|
1504
|
-
// Redux - selector runs on every render by design
|
|
1505
|
-
"useSelector",
|
|
1506
|
-
"useDispatch",
|
|
1507
|
-
"useStore",
|
|
1508
|
-
// React Query / TanStack Query - callbacks are not deps
|
|
1509
|
-
"useQuery",
|
|
1510
|
-
"useMutation",
|
|
1511
|
-
"useInfiniteQuery",
|
|
1512
|
-
"useQueryClient",
|
|
1513
|
-
"useSuspenseQuery",
|
|
1514
|
-
"useSuspenseInfiniteQuery",
|
|
1515
|
-
"useQueries",
|
|
1516
|
-
"usePrefetchQuery",
|
|
1517
|
-
"useIsFetching",
|
|
1518
|
-
"useIsMutating",
|
|
1519
|
-
// React Navigation / Expo Router
|
|
1520
|
-
"useNavigation",
|
|
1521
|
-
"useRoute",
|
|
1522
|
-
"useRouter",
|
|
1523
|
-
"usePathname",
|
|
1524
|
-
"useSegments",
|
|
1525
|
-
"useSearchParams",
|
|
1526
|
-
"useLocalSearchParams",
|
|
1527
|
-
"useGlobalSearchParams",
|
|
1528
|
-
"useFocusEffect",
|
|
1529
|
-
"useNavigationState",
|
|
1530
|
-
// i18next
|
|
1531
|
-
"useTranslation",
|
|
1532
|
-
// Zustand - selector runs on every render
|
|
1533
|
-
"useStoreWithEqualityFn",
|
|
1534
|
-
// React Spring / Animated
|
|
1535
|
-
"useSpring",
|
|
1536
|
-
"useSprings",
|
|
1537
|
-
"useTrail",
|
|
1538
|
-
"useChain",
|
|
1539
|
-
// Syncfusion
|
|
1540
|
-
"useDynamicFormStyles",
|
|
1541
|
-
// React Hook Form - options object is safely handled
|
|
1542
|
-
"useForm",
|
|
1543
|
-
"useFormContext",
|
|
1544
|
-
"useController",
|
|
1545
|
-
"useWatch",
|
|
1546
|
-
"useFieldArray"
|
|
1547
|
-
]);
|
|
1548
|
-
function isUnstableInit(initNode) {
|
|
1549
|
-
if (!initNode) return null;
|
|
1550
|
-
if (initNode.type === "ArrowFunctionExpression" || initNode.type === "FunctionExpression")
|
|
1551
|
-
return "function";
|
|
1552
|
-
if (initNode.type === "ObjectExpression") return "object";
|
|
1553
|
-
if (initNode.type === "ArrayExpression") return "array";
|
|
1554
|
-
return null;
|
|
1555
|
-
}
|
|
1556
|
-
function isStableCall(initNode) {
|
|
1557
|
-
if (initNode.type !== "CallExpression") return false;
|
|
1558
|
-
const callee = initNode.callee;
|
|
1559
|
-
if (callee.type === "Identifier")
|
|
1560
|
-
return STABLE_INIT_CALLS.has(callee.name);
|
|
1561
|
-
if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.property.type === "Identifier")
|
|
1562
|
-
return STABLE_INIT_CALLS.has(`${callee.object.name}.${callee.property.name}`);
|
|
1563
|
-
return false;
|
|
1564
|
-
}
|
|
1565
|
-
function getCalleeName(callNode) {
|
|
1566
|
-
const callee = callNode.callee;
|
|
1567
|
-
if (callee.type === "Identifier") return callee.name;
|
|
1568
|
-
if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.property.type === "Identifier")
|
|
1569
|
-
return `${callee.object.name}.${callee.property.name}`;
|
|
1570
|
-
return null;
|
|
1571
|
-
}
|
|
1572
|
-
function isCustomHookName(name, extraIgnored, patterns) {
|
|
1573
|
-
if (!name || name.length <= 3 || !name.startsWith("use")) return false;
|
|
1574
|
-
const charAfterUse = name[3];
|
|
1575
|
-
const isUpperCase = charAfterUse === charAfterUse.toUpperCase() && charAfterUse !== charAfterUse.toLowerCase();
|
|
1576
|
-
if (!isUpperCase) return false;
|
|
1577
|
-
if (IGNORED_HOOKS.has(name)) return false;
|
|
1578
|
-
if (extraIgnored && extraIgnored.has(name)) return false;
|
|
1579
|
-
if (patterns && patterns.some((re) => re.test(name))) return false;
|
|
1580
|
-
return true;
|
|
1581
|
-
}
|
|
1582
|
-
function isInsideComponentOrHook(node) {
|
|
1583
|
-
let current = node.parent;
|
|
1584
|
-
while (current) {
|
|
1585
|
-
const isFunction = current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression";
|
|
1586
|
-
if (isFunction) {
|
|
1587
|
-
const name = getFunctionName(current);
|
|
1588
|
-
if (!name) return false;
|
|
1589
|
-
const isPascalCase = name[0] === name[0].toUpperCase() && name[0] !== name[0].toLowerCase();
|
|
1590
|
-
const isHook = name.length > 3 && name.startsWith("use");
|
|
1591
|
-
return isPascalCase || isHook;
|
|
1592
|
-
}
|
|
1593
|
-
current = current.parent;
|
|
1594
|
-
}
|
|
1595
|
-
return false;
|
|
1596
|
-
}
|
|
1597
|
-
function getFunctionName(funcNode) {
|
|
1598
|
-
if (funcNode.id) return funcNode.id.name;
|
|
1599
|
-
if (funcNode.parent && funcNode.parent.type === "VariableDeclarator" && funcNode.parent.id && funcNode.parent.id.type === "Identifier")
|
|
1600
|
-
return funcNode.parent.id.name;
|
|
1601
|
-
return null;
|
|
1602
|
-
}
|
|
1603
|
-
var requireStableHookArgsRule = {
|
|
1604
|
-
meta: {
|
|
1605
|
-
type: "problem",
|
|
1606
|
-
docs: {
|
|
1607
|
-
description: "Disallow passing unstable functions/objects/arrays to custom hooks. Wrap in useCallback/useMemo to prevent infinite re-renders.",
|
|
1608
|
-
category: "Possible Errors",
|
|
1609
|
-
recommended: true
|
|
1610
|
-
},
|
|
1611
|
-
schema: [
|
|
1612
|
-
{
|
|
1613
|
-
type: "object",
|
|
1614
|
-
properties: {
|
|
1615
|
-
ignoreHooks: {
|
|
1616
|
-
type: "array",
|
|
1617
|
-
items: { type: "string" },
|
|
1618
|
-
description: 'Additional hook names to ignore (e.g., ["useMyLibraryHook"])'
|
|
1619
|
-
},
|
|
1620
|
-
ignoreHookPatterns: {
|
|
1621
|
-
type: "array",
|
|
1622
|
-
items: { type: "string" },
|
|
1623
|
-
description: 'Regex patterns for hook names to ignore (e.g., ["^useIdentityService", "^useQuestionerWeb"])'
|
|
1624
|
-
}
|
|
1625
|
-
},
|
|
1626
|
-
additionalProperties: false
|
|
1627
|
-
}
|
|
1628
|
-
],
|
|
1629
|
-
messages: {
|
|
1630
|
-
unstableFunction: 'Unstable function "{{name}}" passed to hook "{{hook}}". Wrap in useCallback() to prevent infinite re-renders.',
|
|
1631
|
-
unstableObject: 'Unstable object "{{name}}" passed to hook "{{hook}}". Wrap in useMemo() to prevent infinite re-renders.',
|
|
1632
|
-
unstableArray: 'Unstable array "{{name}}" passed to hook "{{hook}}". Wrap in useMemo() to prevent infinite re-renders.',
|
|
1633
|
-
unstableInlineFunction: 'Inline function passed to hook "{{hook}}". Extract to a useCallback() variable to prevent infinite re-renders.',
|
|
1634
|
-
unstableInlineObject: 'Inline object passed to hook "{{hook}}". Extract to a useMemo() variable to prevent infinite re-renders.',
|
|
1635
|
-
unstableInlineArray: 'Inline array passed to hook "{{hook}}". Extract to a useMemo() variable to prevent infinite re-renders.'
|
|
1636
|
-
}
|
|
1637
|
-
},
|
|
1638
|
-
create(context) {
|
|
1639
|
-
const options = context.options[0] || {};
|
|
1640
|
-
const extraIgnored = options.ignoreHooks ? new Set(options.ignoreHooks) : null;
|
|
1641
|
-
const ignorePatterns = (options.ignoreHookPatterns || []).map((p) => new RegExp(p));
|
|
1642
|
-
const unstableVars = /* @__PURE__ */ new Map();
|
|
1643
|
-
return {
|
|
1644
|
-
/**
|
|
1645
|
-
* Track variable declarations with unstable initializers.
|
|
1646
|
-
* e.g., const t = (key) => i18nT(key);
|
|
1647
|
-
*/
|
|
1648
|
-
VariableDeclarator(node) {
|
|
1649
|
-
if (!node.id || node.id.type !== "Identifier" || !node.init)
|
|
1650
|
-
return;
|
|
1651
|
-
if (isStableCall(node.init)) return;
|
|
1652
|
-
const unstableType = isUnstableInit(node.init);
|
|
1653
|
-
if (!unstableType) return;
|
|
1654
|
-
if (!isInsideComponentOrHook(node)) return;
|
|
1655
|
-
unstableVars.set(node.id.name, {
|
|
1656
|
-
type: unstableType,
|
|
1657
|
-
node
|
|
1658
|
-
});
|
|
1659
|
-
},
|
|
1660
|
-
/**
|
|
1661
|
-
* Check call expressions that look like custom hooks.
|
|
1662
|
-
* Flag any arguments that reference unstable variables or are inline literals.
|
|
1663
|
-
*/
|
|
1664
|
-
CallExpression(node) {
|
|
1665
|
-
const hookName = getCalleeName(node);
|
|
1666
|
-
if (!isCustomHookName(hookName, extraIgnored, ignorePatterns)) return;
|
|
1667
|
-
if (!isInsideComponentOrHook(node)) return;
|
|
1668
|
-
for (const arg of node.arguments) {
|
|
1669
|
-
if (arg.type === "Identifier") {
|
|
1670
|
-
const tracked = unstableVars.get(arg.name);
|
|
1671
|
-
if (!tracked) continue;
|
|
1672
|
-
const messageMap = {
|
|
1673
|
-
function: "unstableFunction",
|
|
1674
|
-
object: "unstableObject",
|
|
1675
|
-
array: "unstableArray"
|
|
1676
|
-
};
|
|
1677
|
-
context.report({
|
|
1678
|
-
node: arg,
|
|
1679
|
-
messageId: messageMap[tracked.type],
|
|
1680
|
-
data: {
|
|
1681
|
-
name: arg.name,
|
|
1682
|
-
hook: hookName
|
|
1683
|
-
}
|
|
1684
|
-
});
|
|
1685
|
-
continue;
|
|
1686
|
-
}
|
|
1687
|
-
const inlineType = isUnstableInit(arg);
|
|
1688
|
-
if (inlineType) {
|
|
1689
|
-
const inlineMessageMap = {
|
|
1690
|
-
function: "unstableInlineFunction",
|
|
1691
|
-
object: "unstableInlineObject",
|
|
1692
|
-
array: "unstableInlineArray"
|
|
1693
|
-
};
|
|
1694
|
-
context.report({
|
|
1695
|
-
node: arg,
|
|
1696
|
-
messageId: inlineMessageMap[inlineType],
|
|
1697
|
-
data: { hook: hookName }
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
};
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
var require_stable_hook_args_default = {
|
|
1706
|
-
rules: {
|
|
1707
|
-
"require-stable-hook-args": requireStableHookArgsRule
|
|
1708
|
-
}
|
|
1709
|
-
};
|
|
1710
|
-
|
|
1711
|
-
// src/rules/smart-max-lines.js
|
|
1712
|
-
var COMPONENT_MAX_DEFAULT = 200;
|
|
1713
|
-
var FUNCTION_MAX_DEFAULT = 50;
|
|
1714
|
-
var FUNCTION_WARN_DEFAULT = 30;
|
|
1715
|
-
function isJSX2(node) {
|
|
1716
|
-
if (!node) {
|
|
1717
|
-
return false;
|
|
1718
|
-
}
|
|
1719
|
-
return node.type === "JSXElement" || node.type === "JSXFragment";
|
|
1720
|
-
}
|
|
1721
|
-
function expressionReturnsJSX2(node) {
|
|
1722
|
-
if (!node) {
|
|
1723
|
-
return false;
|
|
1724
|
-
}
|
|
1725
|
-
if (isJSX2(node)) {
|
|
1726
|
-
return true;
|
|
1727
|
-
}
|
|
1728
|
-
if (node.type === "ConditionalExpression") {
|
|
1729
|
-
return expressionReturnsJSX2(node.consequent) || expressionReturnsJSX2(node.alternate);
|
|
1730
|
-
}
|
|
1731
|
-
if (node.type === "LogicalExpression") {
|
|
1732
|
-
return expressionReturnsJSX2(node.left) || expressionReturnsJSX2(node.right);
|
|
1733
|
-
}
|
|
1734
|
-
if (node.type === "ParenthesizedExpression") {
|
|
1735
|
-
return expressionReturnsJSX2(node.expression);
|
|
1736
|
-
}
|
|
1737
|
-
if (node.type === "SequenceExpression") {
|
|
1738
|
-
const lastExpr = node.expressions[node.expressions.length - 1];
|
|
1739
|
-
return expressionReturnsJSX2(lastExpr);
|
|
1740
|
-
}
|
|
1741
|
-
return false;
|
|
1742
|
-
}
|
|
1743
|
-
function blockReturnsJSX2(blockBody) {
|
|
1744
|
-
if (!blockBody || !Array.isArray(blockBody)) {
|
|
1745
|
-
return false;
|
|
1746
|
-
}
|
|
1747
|
-
for (const statement of blockBody) {
|
|
1748
|
-
if (statementReturnsJSX(statement)) {
|
|
1749
|
-
return true;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
return false;
|
|
1753
|
-
}
|
|
1754
|
-
function statementReturnsJSX(statement) {
|
|
1755
|
-
if (!statement) {
|
|
1756
|
-
return false;
|
|
1757
|
-
}
|
|
1758
|
-
switch (statement.type) {
|
|
1759
|
-
case "ReturnStatement":
|
|
1760
|
-
return expressionReturnsJSX2(statement.argument);
|
|
1761
|
-
case "IfStatement":
|
|
1762
|
-
if (statement.consequent) {
|
|
1763
|
-
if (statement.consequent.type === "BlockStatement") {
|
|
1764
|
-
if (blockReturnsJSX2(statement.consequent.body)) {
|
|
1765
|
-
return true;
|
|
1766
|
-
}
|
|
1767
|
-
} else if (statementReturnsJSX(statement.consequent)) {
|
|
1768
|
-
return true;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
if (statement.alternate) {
|
|
1772
|
-
if (statement.alternate.type === "BlockStatement") {
|
|
1773
|
-
if (blockReturnsJSX2(statement.alternate.body)) {
|
|
1774
|
-
return true;
|
|
1775
|
-
}
|
|
1776
|
-
} else if (statementReturnsJSX(statement.alternate)) {
|
|
1777
|
-
return true;
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
return false;
|
|
1781
|
-
case "SwitchStatement":
|
|
1782
|
-
for (const switchCase of statement.cases) {
|
|
1783
|
-
if (blockReturnsJSX2(switchCase.consequent)) {
|
|
1784
|
-
return true;
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
return false;
|
|
1788
|
-
case "TryStatement":
|
|
1789
|
-
if (statement.block && blockReturnsJSX2(statement.block.body)) {
|
|
1790
|
-
return true;
|
|
1791
|
-
}
|
|
1792
|
-
if (statement.handler && statement.handler.body && blockReturnsJSX2(statement.handler.body.body)) {
|
|
1793
|
-
return true;
|
|
1794
|
-
}
|
|
1795
|
-
if (statement.finalizer && blockReturnsJSX2(statement.finalizer.body)) {
|
|
1796
|
-
return true;
|
|
1797
|
-
}
|
|
1798
|
-
return false;
|
|
1799
|
-
case "BlockStatement":
|
|
1800
|
-
return blockReturnsJSX2(statement.body);
|
|
1801
|
-
default:
|
|
1802
|
-
return false;
|
|
1803
|
-
}
|
|
1804
|
-
}
|
|
1805
|
-
function isReactComponent(node) {
|
|
1806
|
-
if (node.type === "ArrowFunctionExpression") {
|
|
1807
|
-
if (node.body.type !== "BlockStatement") {
|
|
1808
|
-
return expressionReturnsJSX2(node.body);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
const body = node.body;
|
|
1812
|
-
if (body && body.type === "BlockStatement") {
|
|
1813
|
-
return blockReturnsJSX2(body.body);
|
|
1814
|
-
}
|
|
1815
|
-
return false;
|
|
1816
|
-
}
|
|
1817
|
-
function countLines(node, sourceCode, skipBlankLines, skipComments) {
|
|
1818
|
-
const startLine = node.loc.start.line;
|
|
1819
|
-
const endLine = node.loc.end.line;
|
|
1820
|
-
if (!skipBlankLines && !skipComments) {
|
|
1821
|
-
return endLine - startLine + 1;
|
|
1822
|
-
}
|
|
1823
|
-
const lines = sourceCode.lines.slice(startLine - 1, endLine);
|
|
1824
|
-
let count = 0;
|
|
1825
|
-
const allComments = sourceCode.getAllComments();
|
|
1826
|
-
const functionComments = allComments.filter(
|
|
1827
|
-
(comment) => comment.loc.start.line >= startLine && comment.loc.end.line <= endLine
|
|
1828
|
-
);
|
|
1829
|
-
const commentOnlyLines = /* @__PURE__ */ new Set();
|
|
1830
|
-
if (skipComments) {
|
|
1831
|
-
for (const comment of functionComments) {
|
|
1832
|
-
for (let line = comment.loc.start.line; line <= comment.loc.end.line; line++) {
|
|
1833
|
-
const lineContent = sourceCode.lines[line - 1];
|
|
1834
|
-
if (lineContent) {
|
|
1835
|
-
const trimmed = lineContent.trim();
|
|
1836
|
-
const isOnlyComment = trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*") || trimmed.endsWith("*/") || trimmed === "";
|
|
1837
|
-
if (isOnlyComment) {
|
|
1838
|
-
commentOnlyLines.add(line);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
for (let i = 0; i < lines.length; i++) {
|
|
1845
|
-
const lineNumber = startLine + i;
|
|
1846
|
-
const lineContent = lines[i];
|
|
1847
|
-
if (skipBlankLines && lineContent.trim() === "") {
|
|
1848
|
-
continue;
|
|
1849
|
-
}
|
|
1850
|
-
if (skipComments && commentOnlyLines.has(lineNumber)) {
|
|
1851
|
-
continue;
|
|
1852
|
-
}
|
|
1853
|
-
count++;
|
|
1854
|
-
}
|
|
1855
|
-
return count;
|
|
1856
|
-
}
|
|
1857
|
-
var smartMaxLinesRule = {
|
|
1858
|
-
meta: {
|
|
1859
|
-
type: "suggestion",
|
|
1860
|
-
docs: {
|
|
1861
|
-
description: "Enforce different line limits for React components vs regular functions",
|
|
1862
|
-
category: "Best Practices",
|
|
1863
|
-
recommended: true
|
|
1864
|
-
},
|
|
1865
|
-
schema: [
|
|
1866
|
-
{
|
|
1867
|
-
type: "object",
|
|
1868
|
-
properties: {
|
|
1869
|
-
componentMax: {
|
|
1870
|
-
type: "integer",
|
|
1871
|
-
minimum: 1,
|
|
1872
|
-
description: "Maximum lines for React components"
|
|
1873
|
-
},
|
|
1874
|
-
functionMax: {
|
|
1875
|
-
type: "integer",
|
|
1876
|
-
minimum: 1,
|
|
1877
|
-
description: "Maximum lines for regular functions (error threshold)"
|
|
1878
|
-
},
|
|
1879
|
-
functionWarn: {
|
|
1880
|
-
type: "integer",
|
|
1881
|
-
minimum: 1,
|
|
1882
|
-
description: "Warning threshold for regular functions"
|
|
1883
|
-
},
|
|
1884
|
-
skipBlankLines: {
|
|
1885
|
-
type: "boolean",
|
|
1886
|
-
description: "Skip blank lines when counting"
|
|
1887
|
-
},
|
|
1888
|
-
skipComments: {
|
|
1889
|
-
type: "boolean",
|
|
1890
|
-
description: "Skip comment lines when counting"
|
|
1891
|
-
}
|
|
1892
|
-
},
|
|
1893
|
-
additionalProperties: false
|
|
1894
|
-
}
|
|
1895
|
-
],
|
|
1896
|
-
messages: {
|
|
1897
|
-
componentTooLong: "React component has too many lines ({{count}}). Maximum allowed is {{max}}.",
|
|
1898
|
-
functionTooLong: "Function has too many lines ({{count}}). Maximum allowed is {{max}}.",
|
|
1899
|
-
functionWarning: "Function has {{count}} lines which exceeds recommended limit of {{warn}}. Consider refactoring."
|
|
1900
|
-
}
|
|
1901
|
-
},
|
|
1902
|
-
create(context) {
|
|
1903
|
-
const options = context.options[0] || {};
|
|
1904
|
-
const componentMax = options.componentMax ?? COMPONENT_MAX_DEFAULT;
|
|
1905
|
-
const functionMax = options.functionMax ?? FUNCTION_MAX_DEFAULT;
|
|
1906
|
-
const functionWarn = options.functionWarn ?? FUNCTION_WARN_DEFAULT;
|
|
1907
|
-
const skipBlankLines = options.skipBlankLines ?? true;
|
|
1908
|
-
const skipComments = options.skipComments ?? true;
|
|
1909
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
1910
|
-
function checkFunction(node) {
|
|
1911
|
-
const lineCount = countLines(node, sourceCode, skipBlankLines, skipComments);
|
|
1912
|
-
const isComponent = isReactComponent(node);
|
|
1913
|
-
if (isComponent) {
|
|
1914
|
-
if (lineCount > componentMax) {
|
|
1915
|
-
context.report({
|
|
1916
|
-
node,
|
|
1917
|
-
messageId: "componentTooLong",
|
|
1918
|
-
data: {
|
|
1919
|
-
count: String(lineCount),
|
|
1920
|
-
max: String(componentMax)
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
}
|
|
1924
|
-
} else {
|
|
1925
|
-
if (lineCount > functionMax) {
|
|
1926
|
-
context.report({
|
|
1927
|
-
node,
|
|
1928
|
-
messageId: "functionTooLong",
|
|
1929
|
-
data: {
|
|
1930
|
-
count: String(lineCount),
|
|
1931
|
-
max: String(functionMax)
|
|
1932
|
-
}
|
|
1933
|
-
});
|
|
1934
|
-
} else if (lineCount > functionWarn) {
|
|
1935
|
-
context.report({
|
|
1936
|
-
node,
|
|
1937
|
-
messageId: "functionWarning",
|
|
1938
|
-
data: {
|
|
1939
|
-
count: String(lineCount),
|
|
1940
|
-
warn: String(functionWarn)
|
|
1941
|
-
}
|
|
1942
|
-
});
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
return {
|
|
1947
|
-
FunctionDeclaration: checkFunction,
|
|
1948
|
-
FunctionExpression: checkFunction,
|
|
1949
|
-
ArrowFunctionExpression: checkFunction
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
};
|
|
1953
|
-
var smart_max_lines_default = {
|
|
1954
|
-
rules: {
|
|
1955
|
-
"smart-max-lines": smartMaxLinesRule
|
|
1956
|
-
}
|
|
1957
|
-
};
|
|
1958
|
-
|
|
1959
|
-
// src/eslint/plugin.ts
|
|
1960
|
-
var PLUGIN_VERSION = "1.0.0";
|
|
1961
|
-
var ruleModules = [
|
|
1962
|
-
enforce_function_style_default,
|
|
1963
|
-
enforce_module_structure_default,
|
|
1964
|
-
enforce_route_preload_default,
|
|
1965
|
-
enforce_test_colocation_default,
|
|
1966
|
-
enum_file_isolation_default,
|
|
1967
|
-
i18n_interpolation_default,
|
|
1968
|
-
i18n_param_names_default,
|
|
1969
|
-
no_barrel_companion_file_default,
|
|
1970
|
-
no_duplicate_nav_prefix_default,
|
|
1971
|
-
no_duplicate_shared_patterns_default,
|
|
1972
|
-
no_generated_models_barrel_value_import_default,
|
|
1973
|
-
no_null_check_default,
|
|
1974
|
-
no_optional_undefined_default,
|
|
1975
|
-
no_product_imports_in_shared_default,
|
|
1976
|
-
prefer_const_enum_default,
|
|
1977
|
-
require_stable_hook_args_default,
|
|
1978
|
-
smart_max_lines_default
|
|
1979
|
-
];
|
|
1980
|
-
function mergeRules(modules) {
|
|
1981
|
-
const merged = {};
|
|
1982
|
-
for (const mod of modules) {
|
|
1983
|
-
for (const [name, rule3] of Object.entries(mod.rules)) {
|
|
1984
|
-
if (merged[name] !== void 0) {
|
|
1985
|
-
throw new Error(`Duplicate ESLint rule name: "${name}"`);
|
|
1986
|
-
}
|
|
1987
|
-
merged[name] = rule3;
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
return merged;
|
|
1991
|
-
}
|
|
1992
|
-
var plugin = {
|
|
1993
|
-
meta: { name: "@dloizides/frontend-devtools", version: PLUGIN_VERSION },
|
|
1994
|
-
rules: mergeRules(ruleModules)
|
|
1995
|
-
};
|
|
1996
|
-
var rules = plugin.rules;
|
|
1997
|
-
var ruleNames = Object.keys(plugin.rules).sort();
|
|
1998
|
-
|
|
1999
|
-
// src/eslint/legacy.ts
|
|
2000
|
-
var legacyPlugins = buildLegacyPlugins();
|
|
2001
|
-
function buildLegacyPlugins() {
|
|
2002
|
-
const out = {};
|
|
2003
|
-
for (const [name, rule3] of Object.entries(rules)) {
|
|
2004
|
-
out[name] = oneRulePlugin(name, rule3);
|
|
2005
|
-
}
|
|
2006
|
-
return out;
|
|
2007
|
-
}
|
|
2008
|
-
function oneRulePlugin(name, rule3) {
|
|
2009
|
-
return {
|
|
2010
|
-
meta: { name, version: "1.0.0" },
|
|
2011
|
-
rules: { [name]: rule3 }
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
export { initI18n, legacyPlugins, plugin, ruleNames, rules };
|
|
29
|
+
export { initI18n };
|
|
2016
30
|
//# sourceMappingURL=index.mjs.map
|
|
2017
31
|
//# sourceMappingURL=index.mjs.map
|