@mandujs/core 0.50.0 → 0.51.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/package.json
CHANGED
|
@@ -304,6 +304,45 @@ function truncate(s: string, max: number): string {
|
|
|
304
304
|
return JSON.stringify(s.slice(0, max - 1) + "…");
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Run the same DESIGN_INLINE_CLASS scan against a single file —
|
|
309
|
+
* surface used by the MCP `mandu_design_check` wrapper so an agent
|
|
310
|
+
* can preview violations on a file it's about to edit, without
|
|
311
|
+
* walking the whole project tree. Returns the same `GuardViolation`
|
|
312
|
+
* shape as the project-wide checker.
|
|
313
|
+
*/
|
|
314
|
+
export async function checkFileForDesignInlineClasses(
|
|
315
|
+
rootDir: string,
|
|
316
|
+
filePath: string,
|
|
317
|
+
config: DesignGuardConfig | undefined,
|
|
318
|
+
): Promise<GuardViolation[]> {
|
|
319
|
+
if (!config) return [];
|
|
320
|
+
const resolved = await resolveConfig(rootDir, config);
|
|
321
|
+
if (resolved.forbid.size === 0) return [];
|
|
322
|
+
|
|
323
|
+
const absolute = path.isAbsolute(filePath) ? filePath : path.join(rootDir, filePath);
|
|
324
|
+
const rel = path.relative(rootDir, absolute).replace(/\\/g, "/");
|
|
325
|
+
if (isExcluded(rel, resolved.exclude)) return [];
|
|
326
|
+
|
|
327
|
+
let content: string;
|
|
328
|
+
try {
|
|
329
|
+
content = await fs.readFile(absolute, "utf-8");
|
|
330
|
+
} catch {
|
|
331
|
+
return [];
|
|
332
|
+
}
|
|
333
|
+
const hits = scanContent(content, resolved.forbid);
|
|
334
|
+
return hits.map((hit) => ({
|
|
335
|
+
ruleId: "DESIGN_INLINE_CLASS",
|
|
336
|
+
file: rel,
|
|
337
|
+
line: hit.line,
|
|
338
|
+
message: buildMessage(hit, resolved.requireComponent),
|
|
339
|
+
suggestion: resolved.requireComponent[hit.token]
|
|
340
|
+
? `Replace with ${resolved.requireComponent[hit.token]}.`
|
|
341
|
+
: "Extract this class into a component under src/client/shared/ui/ or src/client/widgets/, or remove the inline usage.",
|
|
342
|
+
severity: resolved.severity,
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
|
|
307
346
|
/**
|
|
308
347
|
* Run the design-inline-class checker against the project source.
|
|
309
348
|
* Returns Guard violations using the standard `GuardViolation` shape
|