@docker-doctor/cli 0.4.2 → 0.4.4

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/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as runDockerfileRules, c as parseCompose, d as version, i as runComposeRules, l as parseDockerfile, n as calculateScore, o as allRules, r as loadConfig, s as findRule, t as toJsonReport, u as discoverProject } from "./src-BuUGk4ND.mjs";
2
+ import { a as runDockerfileRules, c as createComposeLocator, d as discoverProject, f as version, i as runComposeRules, l as parseCompose, n as calculateScore, o as allRules, r as loadConfig, s as findRule, t as toJsonReport, u as parseDockerfile } from "./src-CvOv-hL3.mjs";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import os from "node:os";
@@ -538,6 +538,18 @@ const tryCommands = async (commands, text) => {
538
538
  };
539
539
  const copyToClipboard = (text) => tryCommands(getClipboardCommands(), text);
540
540
 
541
+ //#endregion
542
+ //#region src/agents/sanitize.ts
543
+ const CONTROL_CHARS_RE = /[\u0000-\u001F\u007F]+/gu;
544
+ const MAX_MESSAGE_LENGTH = 300;
545
+ const MAX_PATH_LENGTH = 200;
546
+ const flatten = (value, maxLength) => {
547
+ const flat = value.replaceAll(CONTROL_CHARS_RE, " ").trim();
548
+ return flat.length > maxLength ? `${flat.slice(0, maxLength)}…` : flat;
549
+ };
550
+ const sanitizeMessage = (message) => flatten(message, MAX_MESSAGE_LENGTH);
551
+ const sanitizePath = (filePath) => flatten(filePath, MAX_PATH_LENGTH);
552
+
541
553
  //#endregion
542
554
  //#region src/agents/diagnostics-dir.ts
543
555
  const DIAGNOSTICS_DIR_NAME = ".docker-doctor";
@@ -572,10 +584,10 @@ const writeDiagnosticsDirectory = async (diagnostics, report, rootDir) => {
572
584
  const lines = [
573
585
  TRUST_BOUNDARY_NOTE,
574
586
  `${rule} (${first.severity})`,
575
- first.message,
587
+ sanitizeMessage(first.message),
576
588
  `Fix: ${first.help}`,
577
589
  "",
578
- ...ruleDiagnostics.map((d) => `${d.file}${d.line === void 0 ? "" : `:${d.line}`}`),
590
+ ...ruleDiagnostics.map((d) => `${sanitizePath(d.file)}${d.line === void 0 ? "" : `:${d.line}`}`),
579
591
  ""
580
592
  ];
581
593
  writes.push(fs.writeFile(path.join(dir, ruleFileName(rule)), lines.join("\n"), "utf-8"));
@@ -622,12 +634,6 @@ const SEVERITY_LABEL = {
622
634
  info: "INFO",
623
635
  warning: "WARN"
624
636
  };
625
- const MAX_MESSAGE_LENGTH = 300;
626
- const CONTROL_CHARS_RE = /[\u0000-\u001F\u007F]+/gu;
627
- const sanitizeMessage = (message) => {
628
- const flat = message.replaceAll(CONTROL_CHARS_RE, " ").trim();
629
- return flat.length > MAX_MESSAGE_LENGTH ? `${flat.slice(0, MAX_MESSAGE_LENGTH)}…` : flat;
630
- };
631
637
  const buildHandoffPayload = (input) => {
632
638
  const groups = [...groupDiagnosticsByRule(input.diagnostics).entries()].toSorted(([, a], [, b]) => {
633
639
  const rankDelta = SEVERITY_RANK[a[0].severity] - SEVERITY_RANK[b[0].severity];
@@ -637,7 +643,7 @@ const buildHandoffPayload = (input) => {
637
643
  const issueWord = issueCount === 1 ? "issue" : "issues";
638
644
  const ruleWord = groups.length === 1 ? "rule" : "rules";
639
645
  const lines = [
640
- `Fix the ${issueCount} Docker Doctor ${issueWord} (${groups.length} ${ruleWord}) in ${input.projectName}.`,
646
+ `Fix the ${issueCount} Docker Doctor ${issueWord} (${groups.length} ${ruleWord}) in ${sanitizePath(input.projectName)}.`,
641
647
  TRUST_BOUNDARY_NOTE,
642
648
  ""
643
649
  ];
@@ -649,7 +655,7 @@ const buildHandoffPayload = (input) => {
649
655
  const files = [...new Set(ruleDiagnostics.map((d) => d.file))];
650
656
  for (const file of files.slice(0, MAX_FILES_PER_RULE)) {
651
657
  const firstSite = ruleDiagnostics.find((d) => d.file === file && d.line !== void 0);
652
- lines.push(` - ${file}${firstSite ? `:${firstSite.line}` : ""}`);
658
+ lines.push(` - ${sanitizePath(file)}${firstSite ? `:${firstSite.line}` : ""}`);
653
659
  }
654
660
  const remaining = files.length - MAX_FILES_PER_RULE;
655
661
  if (remaining > 0) lines.push(` - +${remaining} more files`);
@@ -1210,7 +1216,7 @@ const runRulesEngine = async (rootDir, project, rulesConfig, categoriesConfig, p
1210
1216
  const content = await fs.readFile(fullPath, "utf-8");
1211
1217
  fileContents[cf] = content;
1212
1218
  const composeObj = parseCompose(content, cf);
1213
- return runComposeRules(composeObj, cf, rulesConfig, categoriesConfig);
1219
+ return runComposeRules(composeObj, cf, rulesConfig, categoriesConfig, createComposeLocator(content));
1214
1220
  } catch (error) {
1215
1221
  const msg = error instanceof Error ? error.message : String(error);
1216
1222
  console.error(`Failed to analyze Compose file ${cf}: ${msg}`);
@@ -1288,7 +1294,9 @@ program.argument("[dir]", "directory to scan", ".").option("-v, --verbose", "sho
1288
1294
  try {
1289
1295
  if (process.stdout.isTTY && !isSilent) await setTimeout(150);
1290
1296
  setStatus("Loading configuration...");
1291
- const config = await loadConfig(rootDir, options.config);
1297
+ const config = await loadConfig(rootDir, options.config, (message) => {
1298
+ console.error(`Warning: ${message}`);
1299
+ });
1292
1300
  setStatus("Scanning workspace files...");
1293
1301
  const project = await discoverProject(rootDir);
1294
1302
  const fileContents = {};