@kaynooo/cli-check 0.8.0 → 0.9.1

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/README.md CHANGED
@@ -89,7 +89,7 @@ errs --json -- keslint src # {errors, unrecognised, log?, code?}
89
89
  errs --in app -- vendor/bin/phpunit # in this compose service; --host forces the host
90
90
  ```
91
91
 
92
- Turns tsc, tsgo and vue-tsc (plain and pretty), bun check, eslint and keslint (stylish), bun test, vitest, playwright, phpunit, paratest, phpstan and php-cs-fixer logs into one `file:line:col: message (rule)` line per error, so a session reads the failures without the log. A failed bun test reads `file:line:col: <test name>: <assertion> (expected X, received Y)`, located at the first stack frame of its error, and an eslint warning is prefixed `warning:`. Absolute paths under the current folder are printed relative.
92
+ Turns tsc, tsgo and vue-tsc (plain and pretty), bun check, eslint and keslint (stylish), bun test, vitest, playwright, phpunit, paratest, phpstan, php-cs-fixer, go (build and vet), cargo (rustc), ruff (concise and full) and pytest logs into one `file:line:col: message (rule)` line per error, so a session reads the failures without the log. A failed bun test reads `file:line:col: <test name>: <assertion> (expected X, received Y)`, located at the first stack frame of its error, and an eslint warning is prefixed `warning:`. Absolute paths under the current folder are printed relative.
93
93
 
94
94
  | Tool | Read from | One error per |
95
95
  | --- | --- | --- |
@@ -97,8 +97,12 @@ Turns tsc, tsgo and vue-tsc (plain and pretty), bun check, eslint and keslint (s
97
97
  | `phpstan` | the default table, `--error-format=raw` and `json` | message: `file:line: message (identifier)`, a wrapped table message joined, problems with no file at line 0 |
98
98
  | `php-cs-fixer` | `fix --dry-run` (`-v` names the fixers, `--diff` is skipped) | file: `file:0:0: style issues to fix (fixer, fixer)` |
99
99
  | `playwright` | the list and line reporters | failed test: the spec file and line of the first stack frame, the first error line and `expected X, received Y`. A test that passed on retry is flaky and not reported |
100
+ | `go` | `go build`, `go vet` and `go test` compile errors | compiler message: `file:line:col: message`, paths as Go prints them (`./main.go`) |
101
+ | `cargo` | rustc's human format | diagnostic: `file:line:col: message (E0308)`, the code frame skipped, warnings prefixed `warning:` |
102
+ | `ruff` | `check` in the concise format and the full one (header plus `-->` line) | diagnostic: `file:line:col: message (F401)` |
103
+ | `pytest` | the failures and errors sections | failure: the location `file:line` of the assertion or exception with its `E` line; with `--tb=short` or a collection error the last frame carries the `E` line. Ruff and pytest are not installed here, so their fixtures are written from the documented output |
100
104
  | `vitest` | the default and verbose reporters | failed test, or suite that failed to load, at its first `file:line:col` frame |
101
105
 
102
- `--json` prints `{errors: [{tool, file, line, column, rule?, severity, message, test?}], unrecognised, log?, code?}`, `tool` one of `tsc`, `eslint`, `bun check`, `bun test`, `vitest`, `playwright`, `phpunit`, `phpstan` or `php-cs-fixer`. Lines no format recognised are never dropped silently: their count goes to stderr, with the path of the full log. A command run after `--` has its whole output saved with the same log writer as `out`, and `log` is that file (the file given when a log is read, nothing for stdin). A first argument that is neither an option nor an existing file starts the command, so the `--` is optional. A command runs in the compose service mounting the current folder like a `check` step does (see above), `--in` and `--host` applying only to a command; a service that is down exits 1 with the service named.
106
+ `--json` prints `{errors: [{tool, file, line, column, rule?, severity, message, test?}], unrecognised, log?, code?}`, `tool` one of `tsc`, `eslint`, `bun check`, `bun test`, `vitest`, `playwright`, `phpunit`, `phpstan`, `php-cs-fixer`, `go`, `cargo`, `ruff` or `pytest`. Lines no format recognised are never dropped silently: their count goes to stderr, with the path of the full log. A command run after `--` has its whole output saved with the same log writer as `out`, and `log` is that file (the file given when a log is read, nothing for stdin). A first argument that is neither an option nor an existing file starts the command, so the `--` is optional. A command runs in the compose service mounting the current folder like a `check` step does (see above), `--in` and `--host` applying only to a command; a service that is down exits 1 with the service named.
103
107
 
104
108
  Exit code 0 when no error was found and the command, if any, passed, 1 when errors were found or the command failed, 2 on bad usage.
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import process2 from "process";
14
14
  // ../kit/src/style.ts
15
15
  import process from "process";
16
16
 
17
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
18
  function x(s) {
19
19
  let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
20
20
  if (!/^[a-f0-9]+$/.test(r))
@@ -234,7 +234,7 @@ class e {
234
234
  }
235
235
  }
236
236
 
237
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
237
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
238
  var r = 39;
239
239
  var o = 49;
240
240
  var f2 = "\x1B[";
@@ -433,8 +433,12 @@ class HelpShown extends Exit {
433
433
 
434
434
  class Completing {
435
435
  options;
436
- constructor(options) {
436
+ positionals;
437
+ candidates;
438
+ constructor(options, positionals = [], candidates = {}) {
437
439
  this.options = options;
440
+ this.positionals = positionals;
441
+ this.candidates = candidates;
438
442
  }
439
443
  }
440
444
  var completion = { active: false };
@@ -477,8 +481,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
477
481
  function optionRows(options, colors = paint(process3.stdout)) {
478
482
  const rows = Object.entries(options).map(([name, option]) => {
479
483
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
480
- const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
481
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
484
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
485
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
486
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
487
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
482
488
  });
483
489
  const width = Math.max(0, ...rows.map((row) => row.width));
484
490
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
@@ -504,14 +510,13 @@ function applyOutput(color, plain, env = process3.env) {
504
510
  function parse(args, usage, options, settings = {}) {
505
511
  const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
506
512
  const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
513
+ const listing = listed(all, settings.allowNegative === true);
507
514
  if (completion.active)
508
- throw new Completing(all);
509
- const separator = settings.rest === true ? args.indexOf("--") : -1;
510
- const own = separator === -1 ? args : args.slice(0, separator);
511
- const rest = separator === -1 ? undefined : args.slice(separator + 1);
515
+ throw new Completing(listing, settings.positionals, settings.candidates);
516
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
512
517
  let parsed;
513
518
  try {
514
- parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
519
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
515
520
  } catch (error) {
516
521
  const message = parseError(error);
517
522
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -519,12 +524,84 @@ function parse(args, usage, options, settings = {}) {
519
524
  const values = parsed.values;
520
525
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
521
526
  if (values.help === true) {
522
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
527
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
523
528
  throw new HelpShown;
524
529
  }
530
+ checkChoices(parsed.values, all);
531
+ checkConflicts(parsed.values, all);
525
532
  if (settings.positionals !== undefined)
526
533
  checkPositionals(parsed.positionals, settings.positionals);
527
- return { ...parsed, positionals: parsed.positionals, rest };
534
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
535
+ }
536
+ function splitRest(args, passes) {
537
+ const separator = passes ? args.indexOf("--") : -1;
538
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
539
+ }
540
+ function splitTrailing(args, options, count) {
541
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
542
+ let seen = 0;
543
+ if (count === 0)
544
+ return { own: args, rest: undefined };
545
+ for (let at = 0;at < args.length; at++) {
546
+ const word = args[at];
547
+ if (word === "--")
548
+ break;
549
+ if (word.startsWith("-")) {
550
+ if (takesValue(word))
551
+ at++;
552
+ continue;
553
+ }
554
+ seen++;
555
+ if (seen === count)
556
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
557
+ }
558
+ return { own: args, rest: undefined };
559
+ }
560
+ function listed(options, allowNegative) {
561
+ if (!allowNegative)
562
+ return options;
563
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
564
+ if (option.type !== "boolean" || option.negative === undefined)
565
+ return [[name, option]];
566
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
567
+ }));
568
+ }
569
+ function withBare(args, options) {
570
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
571
+ if (bare.size === 0)
572
+ return args;
573
+ const separator = args.indexOf("--");
574
+ const own = separator === -1 ? args : args.slice(0, separator);
575
+ return [...own.flatMap((arg, index) => {
576
+ const optional = bare.get(arg);
577
+ const next = own[index + 1];
578
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
579
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
580
+ }), ...separator === -1 ? [] : args.slice(separator)];
581
+ }
582
+ function checkConflicts(values, options) {
583
+ const given = (name) => values[name] !== undefined && values[name] !== false;
584
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
585
+ const other = given(name) ? conflicts.find(given) : undefined;
586
+ if (other !== undefined)
587
+ badUsage(`--${name} cannot be used with --${other}`);
588
+ }
589
+ }
590
+ function checkChoices(values, options) {
591
+ for (const [name, option] of Object.entries(options)) {
592
+ if (option.choices === undefined)
593
+ continue;
594
+ const given = values[name];
595
+ for (const value of Array.isArray(given) ? given : [given]) {
596
+ if (typeof value === "string")
597
+ oneOf(value, name, option.choices);
598
+ }
599
+ }
600
+ }
601
+ function oneOf(value, name, choices) {
602
+ if (!choices.includes(value))
603
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
604
+ return value;
528
605
  }
529
606
  function checkPositionals(given, names) {
530
607
  const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
@@ -756,22 +833,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
756
833
  }
757
834
  var COMPLETE = "__complete";
758
835
  var FILES = "__files__";
759
- async function optionsOf(run) {
836
+ async function completingOf(run) {
760
837
  completion.active = true;
761
838
  try {
762
839
  await run([]);
763
840
  } catch (error) {
764
841
  if (error instanceof Completing)
765
- return error.options;
842
+ return error;
766
843
  } finally {
767
844
  completion.active = false;
768
845
  }
769
- return {};
846
+ return new Completing({});
847
+ }
848
+ function candidateLine(candidate) {
849
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
850
+ }
851
+ function positionalBeingTyped(before, { options, positionals }) {
852
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
853
+ let index = 0;
854
+ let at = 0;
855
+ while (at < before.length) {
856
+ const word = before[at];
857
+ if (word === "--") {
858
+ index += before.length - at - 1;
859
+ break;
860
+ }
861
+ if (!word.startsWith("-"))
862
+ index++;
863
+ else if (takesValue(word))
864
+ at++;
865
+ at++;
866
+ }
867
+ const last = positionals.at(-1);
868
+ if (index < positionals.length)
869
+ return positionals[index];
870
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
770
871
  }
771
872
  async function leafCandidates(run, words) {
772
- if (!(words.at(-1) ?? "").startsWith("-"))
773
- return [FILES];
774
- return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
873
+ const completing = await completingOf(run);
874
+ if ((words.at(-1) ?? "").startsWith("-"))
875
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
876
+ const flag = words.at(-2);
877
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
878
+ if (option?.type === "string") {
879
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
880
+ return values === undefined ? [FILES] : values.map(candidateLine);
881
+ }
882
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
883
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
884
+ return values === undefined ? [FILES] : values.map(candidateLine);
775
885
  }
776
886
  async function printCandidates(found) {
777
887
  for (const line of await found)
@@ -845,7 +955,7 @@ var {Glob } = globalThis.Bun;
845
955
  var SESSION_FILES = new Glob("*.json");
846
956
  var ACCOUNT_DIRS = new Glob("*/sessions");
847
957
  // package.json
848
- var version = "0.8.0";
958
+ var version = "0.9.1";
849
959
 
850
960
  // src/check.ts
851
961
  import { join as join5 } from "path";
@@ -1571,9 +1681,26 @@ var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
1571
1681
  var BUN_TEST_RECEIVED = /^Received: (.*)$/;
1572
1682
  var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
1573
1683
  var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
1684
+ var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
1685
+ var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
1686
+ var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
1687
+ var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
1688
+ var CARGO_NOISE = /^(?:\s+(?:Compiling|Finished|Checking|Fresh|Running|Blocking) |error: (?:aborting due to|could not compile)|warning: .* generated \d+ warnings?|Some errors have detailed explanations|For more information about (?:this|an) error|To learn more, run the command again)/;
1689
+ var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
1690
+ var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
1691
+ var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
1692
+ var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
1693
+ var PYTEST_E_LINE = /^E {3}(.*)$/;
1694
+ var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
1695
+ var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
1696
+ var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
1697
+ var PYTEST_FRAME = /^in \S/;
1698
+ var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
1699
+ var PYTEST_EXCEPTION_END = /[\s:]/;
1700
+ var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
1574
1701
  var NOISE = /^(?:bun test v|Errors {2}Files$|Ran \d+ tests?|note: |\s*\d+ expect\(\) calls|\s+\d+\s+\S+:\d+$|\s*\d+ errors? and \d+ warnings? potentially fixable)/;
1575
1702
  function isNoise(line) {
1576
- return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1703
+ return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, GO_NOISE, CARGO_NOISE, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1577
1704
  }
1578
1705
  var collectBunCheck = (lines, used) => {
1579
1706
  const errors = [];
@@ -1670,7 +1797,95 @@ var collectEslint = (lines, used) => {
1670
1797
  }
1671
1798
  return errors;
1672
1799
  };
1673
- var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectTsc, collectEslint];
1800
+ var collectGo = (lines, used) => {
1801
+ const errors = [];
1802
+ for (const [index, line] of lines.entries()) {
1803
+ const match = used.has(index) ? null : GO_ERROR.exec(line);
1804
+ if (match === null)
1805
+ continue;
1806
+ errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
1807
+ used.add(index);
1808
+ }
1809
+ return errors;
1810
+ };
1811
+ var collectArrowed = (lines, used) => {
1812
+ const errors = [];
1813
+ for (const [index, line] of lines.entries()) {
1814
+ const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
1815
+ const header = arrow === null ? null : lines[index - 1] ?? "";
1816
+ const cargo = header === null ? null : CARGO_HEADER.exec(header);
1817
+ const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
1818
+ if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
1819
+ continue;
1820
+ const [, file, row, column] = arrow;
1821
+ const fields = { file: file ?? "", line: Number(row), column: Number(column) };
1822
+ errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
1823
+ used.add(index - 1);
1824
+ used.add(index);
1825
+ for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
1826
+ if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
1827
+ break;
1828
+ used.add(frame);
1829
+ }
1830
+ }
1831
+ return errors;
1832
+ };
1833
+ var collectRuff = (lines, used) => {
1834
+ const errors = [];
1835
+ for (const [index, line] of lines.entries()) {
1836
+ const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
1837
+ if (match === null)
1838
+ continue;
1839
+ errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
1840
+ used.add(index);
1841
+ }
1842
+ return errors;
1843
+ };
1844
+ var collectPytest = (lines, used) => {
1845
+ const errors = [];
1846
+ const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
1847
+ const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
1848
+ if (start === -1)
1849
+ return errors;
1850
+ const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
1851
+ const stop = end === -1 ? lines.length : end;
1852
+ let message = [];
1853
+ let frame;
1854
+ for (let index = start;index < stop; index++) {
1855
+ const line = lines[index] ?? "";
1856
+ const failure = PYTEST_E_LINE.exec(line);
1857
+ if (failure !== null) {
1858
+ message.push((failure[1] ?? "").trim());
1859
+ } else {
1860
+ if (frame !== undefined && message.length > 0) {
1861
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1862
+ frame = undefined;
1863
+ }
1864
+ const location = PYTEST_LOCATION.exec(line);
1865
+ if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
1866
+ frame = { file: location[1] ?? "", line: Number(location[2]) };
1867
+ } else if (location !== null) {
1868
+ const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
1869
+ const first = message[0] ?? "";
1870
+ const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
1871
+ errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
1872
+ }
1873
+ if (PYTEST_SECTION.test(line))
1874
+ frame = undefined;
1875
+ if (line.trim() !== "")
1876
+ message = [];
1877
+ }
1878
+ used.add(index);
1879
+ }
1880
+ if (frame !== undefined && message.length > 0)
1881
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1882
+ for (let index = stop;index < lines.length; index++) {
1883
+ if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
1884
+ used.add(index);
1885
+ }
1886
+ return errors;
1887
+ };
1888
+ var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
1674
1889
  function parseErrors(output) {
1675
1890
  const lines = stripAnsi(output).split(`
1676
1891
  `);
package/dist/errs-cli.js CHANGED
@@ -14,7 +14,7 @@ import process2 from "process";
14
14
  // ../kit/src/style.ts
15
15
  import process from "process";
16
16
 
17
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
18
  function x(s) {
19
19
  let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
20
20
  if (!/^[a-f0-9]+$/.test(r))
@@ -234,7 +234,7 @@ class e {
234
234
  }
235
235
  }
236
236
 
237
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
237
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
238
  var r = 39;
239
239
  var o = 49;
240
240
  var f2 = "\x1B[";
@@ -433,8 +433,12 @@ class HelpShown extends Exit {
433
433
 
434
434
  class Completing {
435
435
  options;
436
- constructor(options) {
436
+ positionals;
437
+ candidates;
438
+ constructor(options, positionals = [], candidates = {}) {
437
439
  this.options = options;
440
+ this.positionals = positionals;
441
+ this.candidates = candidates;
438
442
  }
439
443
  }
440
444
  var completion = { active: false };
@@ -477,8 +481,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
477
481
  function optionRows(options, colors = paint(process3.stdout)) {
478
482
  const rows = Object.entries(options).map(([name, option]) => {
479
483
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
480
- const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
481
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
484
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
485
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
486
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
487
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
482
488
  });
483
489
  const width = Math.max(0, ...rows.map((row) => row.width));
484
490
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
@@ -504,14 +510,13 @@ function applyOutput(color, plain, env = process3.env) {
504
510
  function parse(args, usage, options, settings = {}) {
505
511
  const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
506
512
  const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
513
+ const listing = listed(all, settings.allowNegative === true);
507
514
  if (completion.active)
508
- throw new Completing(all);
509
- const separator = settings.rest === true ? args.indexOf("--") : -1;
510
- const own = separator === -1 ? args : args.slice(0, separator);
511
- const rest = separator === -1 ? undefined : args.slice(separator + 1);
515
+ throw new Completing(listing, settings.positionals, settings.candidates);
516
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
512
517
  let parsed;
513
518
  try {
514
- parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
519
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
515
520
  } catch (error) {
516
521
  const message = parseError(error);
517
522
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -519,12 +524,84 @@ function parse(args, usage, options, settings = {}) {
519
524
  const values = parsed.values;
520
525
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
521
526
  if (values.help === true) {
522
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
527
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
523
528
  throw new HelpShown;
524
529
  }
530
+ checkChoices(parsed.values, all);
531
+ checkConflicts(parsed.values, all);
525
532
  if (settings.positionals !== undefined)
526
533
  checkPositionals(parsed.positionals, settings.positionals);
527
- return { ...parsed, positionals: parsed.positionals, rest };
534
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
535
+ }
536
+ function splitRest(args, passes) {
537
+ const separator = passes ? args.indexOf("--") : -1;
538
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
539
+ }
540
+ function splitTrailing(args, options, count) {
541
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
542
+ let seen = 0;
543
+ if (count === 0)
544
+ return { own: args, rest: undefined };
545
+ for (let at = 0;at < args.length; at++) {
546
+ const word = args[at];
547
+ if (word === "--")
548
+ break;
549
+ if (word.startsWith("-")) {
550
+ if (takesValue(word))
551
+ at++;
552
+ continue;
553
+ }
554
+ seen++;
555
+ if (seen === count)
556
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
557
+ }
558
+ return { own: args, rest: undefined };
559
+ }
560
+ function listed(options, allowNegative) {
561
+ if (!allowNegative)
562
+ return options;
563
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
564
+ if (option.type !== "boolean" || option.negative === undefined)
565
+ return [[name, option]];
566
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
567
+ }));
568
+ }
569
+ function withBare(args, options) {
570
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
571
+ if (bare.size === 0)
572
+ return args;
573
+ const separator = args.indexOf("--");
574
+ const own = separator === -1 ? args : args.slice(0, separator);
575
+ return [...own.flatMap((arg, index) => {
576
+ const optional = bare.get(arg);
577
+ const next = own[index + 1];
578
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
579
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
580
+ }), ...separator === -1 ? [] : args.slice(separator)];
581
+ }
582
+ function checkConflicts(values, options) {
583
+ const given = (name) => values[name] !== undefined && values[name] !== false;
584
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
585
+ const other = given(name) ? conflicts.find(given) : undefined;
586
+ if (other !== undefined)
587
+ badUsage(`--${name} cannot be used with --${other}`);
588
+ }
589
+ }
590
+ function checkChoices(values, options) {
591
+ for (const [name, option] of Object.entries(options)) {
592
+ if (option.choices === undefined)
593
+ continue;
594
+ const given = values[name];
595
+ for (const value of Array.isArray(given) ? given : [given]) {
596
+ if (typeof value === "string")
597
+ oneOf(value, name, option.choices);
598
+ }
599
+ }
600
+ }
601
+ function oneOf(value, name, choices) {
602
+ if (!choices.includes(value))
603
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
604
+ return value;
528
605
  }
529
606
  function checkPositionals(given, names) {
530
607
  const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
@@ -756,22 +833,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
756
833
  }
757
834
  var COMPLETE = "__complete";
758
835
  var FILES = "__files__";
759
- async function optionsOf(run) {
836
+ async function completingOf(run) {
760
837
  completion.active = true;
761
838
  try {
762
839
  await run([]);
763
840
  } catch (error) {
764
841
  if (error instanceof Completing)
765
- return error.options;
842
+ return error;
766
843
  } finally {
767
844
  completion.active = false;
768
845
  }
769
- return {};
846
+ return new Completing({});
847
+ }
848
+ function candidateLine(candidate) {
849
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
850
+ }
851
+ function positionalBeingTyped(before, { options, positionals }) {
852
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
853
+ let index = 0;
854
+ let at = 0;
855
+ while (at < before.length) {
856
+ const word = before[at];
857
+ if (word === "--") {
858
+ index += before.length - at - 1;
859
+ break;
860
+ }
861
+ if (!word.startsWith("-"))
862
+ index++;
863
+ else if (takesValue(word))
864
+ at++;
865
+ at++;
866
+ }
867
+ const last = positionals.at(-1);
868
+ if (index < positionals.length)
869
+ return positionals[index];
870
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
770
871
  }
771
872
  async function leafCandidates(run, words) {
772
- if (!(words.at(-1) ?? "").startsWith("-"))
773
- return [FILES];
774
- return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
873
+ const completing = await completingOf(run);
874
+ if ((words.at(-1) ?? "").startsWith("-"))
875
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
876
+ const flag = words.at(-2);
877
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
878
+ if (option?.type === "string") {
879
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
880
+ return values === undefined ? [FILES] : values.map(candidateLine);
881
+ }
882
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
883
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
884
+ return values === undefined ? [FILES] : values.map(candidateLine);
775
885
  }
776
886
  async function printCandidates(found) {
777
887
  for (const line of await found)
@@ -845,7 +955,7 @@ var {Glob } = globalThis.Bun;
845
955
  var SESSION_FILES = new Glob("*.json");
846
956
  var ACCOUNT_DIRS = new Glob("*/sessions");
847
957
  // package.json
848
- var version = "0.8.0";
958
+ var version = "0.9.1";
849
959
 
850
960
  // src/errs.ts
851
961
  import { relative as relative2 } from "path";
@@ -1568,9 +1678,26 @@ var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
1568
1678
  var BUN_TEST_RECEIVED = /^Received: (.*)$/;
1569
1679
  var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
1570
1680
  var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
1681
+ var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
1682
+ var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
1683
+ var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
1684
+ var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
1685
+ var CARGO_NOISE = /^(?:\s+(?:Compiling|Finished|Checking|Fresh|Running|Blocking) |error: (?:aborting due to|could not compile)|warning: .* generated \d+ warnings?|Some errors have detailed explanations|For more information about (?:this|an) error|To learn more, run the command again)/;
1686
+ var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
1687
+ var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
1688
+ var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
1689
+ var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
1690
+ var PYTEST_E_LINE = /^E {3}(.*)$/;
1691
+ var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
1692
+ var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
1693
+ var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
1694
+ var PYTEST_FRAME = /^in \S/;
1695
+ var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
1696
+ var PYTEST_EXCEPTION_END = /[\s:]/;
1697
+ var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
1571
1698
  var NOISE = /^(?:bun test v|Errors {2}Files$|Ran \d+ tests?|note: |\s*\d+ expect\(\) calls|\s+\d+\s+\S+:\d+$|\s*\d+ errors? and \d+ warnings? potentially fixable)/;
1572
1699
  function isNoise(line) {
1573
- return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1700
+ return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, GO_NOISE, CARGO_NOISE, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1574
1701
  }
1575
1702
  var collectBunCheck = (lines, used) => {
1576
1703
  const errors = [];
@@ -1667,7 +1794,95 @@ var collectEslint = (lines, used) => {
1667
1794
  }
1668
1795
  return errors;
1669
1796
  };
1670
- var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectTsc, collectEslint];
1797
+ var collectGo = (lines, used) => {
1798
+ const errors = [];
1799
+ for (const [index, line] of lines.entries()) {
1800
+ const match = used.has(index) ? null : GO_ERROR.exec(line);
1801
+ if (match === null)
1802
+ continue;
1803
+ errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
1804
+ used.add(index);
1805
+ }
1806
+ return errors;
1807
+ };
1808
+ var collectArrowed = (lines, used) => {
1809
+ const errors = [];
1810
+ for (const [index, line] of lines.entries()) {
1811
+ const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
1812
+ const header = arrow === null ? null : lines[index - 1] ?? "";
1813
+ const cargo = header === null ? null : CARGO_HEADER.exec(header);
1814
+ const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
1815
+ if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
1816
+ continue;
1817
+ const [, file, row, column] = arrow;
1818
+ const fields = { file: file ?? "", line: Number(row), column: Number(column) };
1819
+ errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
1820
+ used.add(index - 1);
1821
+ used.add(index);
1822
+ for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
1823
+ if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
1824
+ break;
1825
+ used.add(frame);
1826
+ }
1827
+ }
1828
+ return errors;
1829
+ };
1830
+ var collectRuff = (lines, used) => {
1831
+ const errors = [];
1832
+ for (const [index, line] of lines.entries()) {
1833
+ const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
1834
+ if (match === null)
1835
+ continue;
1836
+ errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
1837
+ used.add(index);
1838
+ }
1839
+ return errors;
1840
+ };
1841
+ var collectPytest = (lines, used) => {
1842
+ const errors = [];
1843
+ const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
1844
+ const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
1845
+ if (start === -1)
1846
+ return errors;
1847
+ const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
1848
+ const stop = end === -1 ? lines.length : end;
1849
+ let message = [];
1850
+ let frame;
1851
+ for (let index = start;index < stop; index++) {
1852
+ const line = lines[index] ?? "";
1853
+ const failure = PYTEST_E_LINE.exec(line);
1854
+ if (failure !== null) {
1855
+ message.push((failure[1] ?? "").trim());
1856
+ } else {
1857
+ if (frame !== undefined && message.length > 0) {
1858
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1859
+ frame = undefined;
1860
+ }
1861
+ const location = PYTEST_LOCATION.exec(line);
1862
+ if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
1863
+ frame = { file: location[1] ?? "", line: Number(location[2]) };
1864
+ } else if (location !== null) {
1865
+ const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
1866
+ const first = message[0] ?? "";
1867
+ const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
1868
+ errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
1869
+ }
1870
+ if (PYTEST_SECTION.test(line))
1871
+ frame = undefined;
1872
+ if (line.trim() !== "")
1873
+ message = [];
1874
+ }
1875
+ used.add(index);
1876
+ }
1877
+ if (frame !== undefined && message.length > 0)
1878
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1879
+ for (let index = stop;index < lines.length; index++) {
1880
+ if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
1881
+ used.add(index);
1882
+ }
1883
+ return errors;
1884
+ };
1885
+ var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
1671
1886
  function parseErrors(output) {
1672
1887
  const lines = stripAnsi(output).split(`
1673
1888
  `);
@@ -1736,11 +1951,11 @@ var usage = `errs [options] [log]
1736
1951
  errs [options] -- <command> [args...]
1737
1952
  errs --in <service> | --host -- <command> [args...]
1738
1953
 
1739
- Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json) or php-cs-fixer log, read from the file given, from stdin (no argument or -), or from the output of the command run after --.
1954
+ Prints one \`file:line:col: message (rule)\` line per error found in a tsc, tsgo, vue-tsc, bun check, eslint, keslint, bun test, vitest, playwright (list and line reporters), phpunit, paratest, phpstan (table, raw and json), php-cs-fixer, go (build, vet), cargo (rustc), ruff (concise and full) or pytest log, read from the file given, from stdin (no argument or -), or from the output of the command run after --.
1740
1955
  The lines no format recognised are counted on stderr, never dropped silently, and a command's full output is saved to a log file whose path is printed with that count.
1741
1956
  A command runs inside the docker compose service that bind-mounts the current folder (found in compose.yml, compose.yaml or docker-compose.yml, up to the repository root), at the matching path, with its output read here; a service that is down is never started, the call fails naming it. --in picks the service, --host forces the host.
1742
1957
  Exits 0 when no error was found and the command, if any, passed, 1 when errors were found or the command failed, 2 on a usage error.
1743
- --json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer.`;
1958
+ --json prints {errors: [{tool, file, line, column, rule, severity, message, test?}], unrecognised, log?, code?}, tool one of tsc, eslint, bun check, bun test, vitest, playwright, phpunit, phpstan, php-cs-fixer, go, cargo, ruff, pytest.`;
1744
1959
  var options = {
1745
1960
  ...placeOptions,
1746
1961
  json: jsonOption()
package/dist/fix-cli.js CHANGED
@@ -14,7 +14,7 @@ import process2 from "process";
14
14
  // ../kit/src/style.ts
15
15
  import process from "process";
16
16
 
17
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
17
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
18
18
  function x(s) {
19
19
  let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
20
20
  if (!/^[a-f0-9]+$/.test(r))
@@ -234,7 +234,7 @@ class e {
234
234
  }
235
235
  }
236
236
 
237
- // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
237
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
238
238
  var r = 39;
239
239
  var o = 49;
240
240
  var f2 = "\x1B[";
@@ -433,8 +433,12 @@ class HelpShown extends Exit {
433
433
 
434
434
  class Completing {
435
435
  options;
436
- constructor(options) {
436
+ positionals;
437
+ candidates;
438
+ constructor(options, positionals = [], candidates = {}) {
437
439
  this.options = options;
440
+ this.positionals = positionals;
441
+ this.candidates = candidates;
438
442
  }
439
443
  }
440
444
  var completion = { active: false };
@@ -477,8 +481,10 @@ function exampleRows(examples, colors = paint(process3.stdout)) {
477
481
  function optionRows(options, colors = paint(process3.stdout)) {
478
482
  const rows = Object.entries(options).map(([name, option]) => {
479
483
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
480
- const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
481
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
484
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
485
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
486
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
487
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
482
488
  });
483
489
  const width = Math.max(0, ...rows.map((row) => row.width));
484
490
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
@@ -504,14 +510,13 @@ function applyOutput(color, plain, env = process3.env) {
504
510
  function parse(args, usage, options, settings = {}) {
505
511
  const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
506
512
  const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
513
+ const listing = listed(all, settings.allowNegative === true);
507
514
  if (completion.active)
508
- throw new Completing(all);
509
- const separator = settings.rest === true ? args.indexOf("--") : -1;
510
- const own = separator === -1 ? args : args.slice(0, separator);
511
- const rest = separator === -1 ? undefined : args.slice(separator + 1);
515
+ throw new Completing(listing, settings.positionals, settings.candidates);
516
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
512
517
  let parsed;
513
518
  try {
514
- parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
519
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
515
520
  } catch (error) {
516
521
  const message = parseError(error);
517
522
  throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
@@ -519,12 +524,84 @@ function parse(args, usage, options, settings = {}) {
519
524
  const values = parsed.values;
520
525
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
521
526
  if (values.help === true) {
522
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
527
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
523
528
  throw new HelpShown;
524
529
  }
530
+ checkChoices(parsed.values, all);
531
+ checkConflicts(parsed.values, all);
525
532
  if (settings.positionals !== undefined)
526
533
  checkPositionals(parsed.positionals, settings.positionals);
527
- return { ...parsed, positionals: parsed.positionals, rest };
534
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
535
+ }
536
+ function splitRest(args, passes) {
537
+ const separator = passes ? args.indexOf("--") : -1;
538
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
539
+ }
540
+ function splitTrailing(args, options, count) {
541
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
542
+ let seen = 0;
543
+ if (count === 0)
544
+ return { own: args, rest: undefined };
545
+ for (let at = 0;at < args.length; at++) {
546
+ const word = args[at];
547
+ if (word === "--")
548
+ break;
549
+ if (word.startsWith("-")) {
550
+ if (takesValue(word))
551
+ at++;
552
+ continue;
553
+ }
554
+ seen++;
555
+ if (seen === count)
556
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
557
+ }
558
+ return { own: args, rest: undefined };
559
+ }
560
+ function listed(options, allowNegative) {
561
+ if (!allowNegative)
562
+ return options;
563
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
564
+ if (option.type !== "boolean" || option.negative === undefined)
565
+ return [[name, option]];
566
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
567
+ }));
568
+ }
569
+ function withBare(args, options) {
570
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
571
+ if (bare.size === 0)
572
+ return args;
573
+ const separator = args.indexOf("--");
574
+ const own = separator === -1 ? args : args.slice(0, separator);
575
+ return [...own.flatMap((arg, index) => {
576
+ const optional = bare.get(arg);
577
+ const next = own[index + 1];
578
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
579
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
580
+ }), ...separator === -1 ? [] : args.slice(separator)];
581
+ }
582
+ function checkConflicts(values, options) {
583
+ const given = (name) => values[name] !== undefined && values[name] !== false;
584
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
585
+ const other = given(name) ? conflicts.find(given) : undefined;
586
+ if (other !== undefined)
587
+ badUsage(`--${name} cannot be used with --${other}`);
588
+ }
589
+ }
590
+ function checkChoices(values, options) {
591
+ for (const [name, option] of Object.entries(options)) {
592
+ if (option.choices === undefined)
593
+ continue;
594
+ const given = values[name];
595
+ for (const value of Array.isArray(given) ? given : [given]) {
596
+ if (typeof value === "string")
597
+ oneOf(value, name, option.choices);
598
+ }
599
+ }
600
+ }
601
+ function oneOf(value, name, choices) {
602
+ if (!choices.includes(value))
603
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
604
+ return value;
528
605
  }
529
606
  function checkPositionals(given, names) {
530
607
  const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
@@ -756,22 +833,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
756
833
  }
757
834
  var COMPLETE = "__complete";
758
835
  var FILES = "__files__";
759
- async function optionsOf(run) {
836
+ async function completingOf(run) {
760
837
  completion.active = true;
761
838
  try {
762
839
  await run([]);
763
840
  } catch (error) {
764
841
  if (error instanceof Completing)
765
- return error.options;
842
+ return error;
766
843
  } finally {
767
844
  completion.active = false;
768
845
  }
769
- return {};
846
+ return new Completing({});
847
+ }
848
+ function candidateLine(candidate) {
849
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
850
+ }
851
+ function positionalBeingTyped(before, { options, positionals }) {
852
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
853
+ let index = 0;
854
+ let at = 0;
855
+ while (at < before.length) {
856
+ const word = before[at];
857
+ if (word === "--") {
858
+ index += before.length - at - 1;
859
+ break;
860
+ }
861
+ if (!word.startsWith("-"))
862
+ index++;
863
+ else if (takesValue(word))
864
+ at++;
865
+ at++;
866
+ }
867
+ const last = positionals.at(-1);
868
+ if (index < positionals.length)
869
+ return positionals[index];
870
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
770
871
  }
771
872
  async function leafCandidates(run, words) {
772
- if (!(words.at(-1) ?? "").startsWith("-"))
773
- return [FILES];
774
- return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
873
+ const completing = await completingOf(run);
874
+ if ((words.at(-1) ?? "").startsWith("-"))
875
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
876
+ const flag = words.at(-2);
877
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
878
+ if (option?.type === "string") {
879
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
880
+ return values === undefined ? [FILES] : values.map(candidateLine);
881
+ }
882
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
883
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
884
+ return values === undefined ? [FILES] : values.map(candidateLine);
775
885
  }
776
886
  async function printCandidates(found) {
777
887
  for (const line of await found)
@@ -845,7 +955,7 @@ var {Glob } = globalThis.Bun;
845
955
  var SESSION_FILES = new Glob("*.json");
846
956
  var ACCOUNT_DIRS = new Glob("*/sessions");
847
957
  // package.json
848
- var version = "0.8.0";
958
+ var version = "0.9.1";
849
959
 
850
960
  // src/fix.ts
851
961
  import { existsSync as existsSync2, statSync } from "fs";
@@ -1600,9 +1710,26 @@ var BUN_TEST_EXPECTED = /^Expected: (.*)$/;
1600
1710
  var BUN_TEST_RECEIVED = /^Received: (.*)$/;
1601
1711
  var BUN_TEST_FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
1602
1712
  var BUN_TEST_FILE = /^\S+\.test\.[jt]sx?:$/;
1713
+ var GO_ERROR = /^\s*(?:vet: )?(\S+\.go):(\d+):(?:(\d+):)? (.+)$/;
1714
+ var GO_NOISE = /^# \S+(?: \[\S+\])?$/;
1715
+ var ARROW = /^\s*--> (.+?):(\d+):(\d+)$/;
1716
+ var CARGO_HEADER = /^(error|warning)(?:\[(\w+)\])?: (.*)$/;
1717
+ var CARGO_NOISE = /^(?:\s+(?:Compiling|Finished|Checking|Fresh|Running|Blocking) |error: (?:aborting due to|could not compile)|warning: .* generated \d+ warnings?|Some errors have detailed explanations|For more information about (?:this|an) error|To learn more, run the command again)/;
1718
+ var RUFF_CONCISE = /^(\S+\.pyi?):(\d+):(\d+): ([A-Z]+\d+) (?:\[\*\] )?(.*)$/;
1719
+ var RUFF_HEADER = /^([A-Z]{1,5}\d{1,4}) (?:\[\*\] )?(.+)$/;
1720
+ var RUFF_NOISE = /^(?:Found \d+ errors?\.|\[\*\] \d+ fixable|No fixes available|All checks passed|help: |\s*(?:\|\s*)?$)/;
1721
+ var PYTEST_LOCATION = /^(\S+\.py):(\d+): (\S.*)$/;
1722
+ var PYTEST_E_LINE = /^E {3}(.*)$/;
1723
+ var PYTEST_BANNER = /^={3,} (.*?) ={3,}$/;
1724
+ var PYTEST_FAILURES = new Set(["FAILURES", "ERRORS"]);
1725
+ var PYTEST_SUMMARY_LINE = /^(?:FAILED|ERROR) \S/;
1726
+ var PYTEST_FRAME = /^in \S/;
1727
+ var PYTEST_SECTION = /^_{3,} .* _{3,}$/;
1728
+ var PYTEST_EXCEPTION_END = /[\s:]/;
1729
+ var PYTEST_NOISE = /^(?:platform |rootdir: |collected |plugins: |configfile: |cachedir: |\S+\.pyi? [.FEsxXR]+ +\[ *\d+%\]$|\S+\.py:\d+: $)/;
1603
1730
  var NOISE = /^(?:bun test v|Errors {2}Files$|Ran \d+ tests?|note: |\s*\d+ expect\(\) calls|\s+\d+\s+\S+:\d+$|\s*\d+ errors? and \d+ warnings? potentially fixable)/;
1604
1731
  function isNoise(line) {
1605
- return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1732
+ return line.trim() === "" || [NOISE, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_SUMMARY, ESLINT_SUMMARY, BOUNDARY, BASH_ECHO, GO_NOISE, CARGO_NOISE, RUFF_NOISE, PYTEST_NOISE, PYTEST_BANNER, ...PHP_NOISE, ...E2E_NOISE].some((pattern) => pattern.test(line));
1606
1733
  }
1607
1734
  var collectBunCheck = (lines, used) => {
1608
1735
  const errors = [];
@@ -1699,7 +1826,95 @@ var collectEslint = (lines, used) => {
1699
1826
  }
1700
1827
  return errors;
1701
1828
  };
1702
- var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectTsc, collectEslint];
1829
+ var collectGo = (lines, used) => {
1830
+ const errors = [];
1831
+ for (const [index, line] of lines.entries()) {
1832
+ const match = used.has(index) ? null : GO_ERROR.exec(line);
1833
+ if (match === null)
1834
+ continue;
1835
+ errors.push({ tool: "go", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3] ?? 0), severity: "error", message: match[4] ?? "" });
1836
+ used.add(index);
1837
+ }
1838
+ return errors;
1839
+ };
1840
+ var collectArrowed = (lines, used) => {
1841
+ const errors = [];
1842
+ for (const [index, line] of lines.entries()) {
1843
+ const arrow = used.has(index) || index === 0 ? null : ARROW.exec(line);
1844
+ const header = arrow === null ? null : lines[index - 1] ?? "";
1845
+ const cargo = header === null ? null : CARGO_HEADER.exec(header);
1846
+ const ruff = header === null || cargo !== null ? null : RUFF_HEADER.exec(header);
1847
+ if (arrow === null || cargo === null && ruff === null || used.has(index - 1))
1848
+ continue;
1849
+ const [, file, row, column] = arrow;
1850
+ const fields = { file: file ?? "", line: Number(row), column: Number(column) };
1851
+ errors.push(cargo === null ? { tool: "ruff", ...fields, rule: ruff?.[1], severity: "error", message: ruff?.[2] ?? "" } : { tool: "cargo", ...fields, rule: cargo[2], severity: cargo[1] === "warning" ? "warning" : "error", message: cargo[3] ?? "" });
1852
+ used.add(index - 1);
1853
+ used.add(index);
1854
+ for (let frame = index + 1;frame < lines.length && (lines[frame] ?? "").trim() !== ""; frame++) {
1855
+ if (CARGO_HEADER.test(lines[frame] ?? "") || RUFF_HEADER.test(lines[frame] ?? ""))
1856
+ break;
1857
+ used.add(frame);
1858
+ }
1859
+ }
1860
+ return errors;
1861
+ };
1862
+ var collectRuff = (lines, used) => {
1863
+ const errors = [];
1864
+ for (const [index, line] of lines.entries()) {
1865
+ const match = used.has(index) ? null : RUFF_CONCISE.exec(line);
1866
+ if (match === null)
1867
+ continue;
1868
+ errors.push({ tool: "ruff", file: match[1] ?? "", line: Number(match[2]), column: Number(match[3]), rule: match[4], severity: "error", message: match[5] ?? "" });
1869
+ used.add(index);
1870
+ }
1871
+ return errors;
1872
+ };
1873
+ var collectPytest = (lines, used) => {
1874
+ const errors = [];
1875
+ const title = (line) => PYTEST_BANNER.exec(line ?? "")?.[1];
1876
+ const start = lines.findIndex((line) => PYTEST_FAILURES.has(title(line) ?? ""));
1877
+ if (start === -1)
1878
+ return errors;
1879
+ const end = lines.findIndex((line, index) => index > start && title(line) !== undefined && !PYTEST_FAILURES.has(title(line) ?? ""));
1880
+ const stop = end === -1 ? lines.length : end;
1881
+ let message = [];
1882
+ let frame;
1883
+ for (let index = start;index < stop; index++) {
1884
+ const line = lines[index] ?? "";
1885
+ const failure = PYTEST_E_LINE.exec(line);
1886
+ if (failure !== null) {
1887
+ message.push((failure[1] ?? "").trim());
1888
+ } else {
1889
+ if (frame !== undefined && message.length > 0) {
1890
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1891
+ frame = undefined;
1892
+ }
1893
+ const location = PYTEST_LOCATION.exec(line);
1894
+ if (location !== null && PYTEST_FRAME.test(location[3] ?? "")) {
1895
+ frame = { file: location[1] ?? "", line: Number(location[2]) };
1896
+ } else if (location !== null) {
1897
+ const [exception = ""] = (location[3] ?? "").split(PYTEST_EXCEPTION_END);
1898
+ const first = message[0] ?? "";
1899
+ const text = first === "" || first.startsWith(exception) ? first || (location[3] ?? "") : `${location[3] ?? ""}: ${first}`;
1900
+ errors.push({ tool: "pytest", file: location[1] ?? "", line: Number(location[2]), column: 0, severity: "error", message: text });
1901
+ }
1902
+ if (PYTEST_SECTION.test(line))
1903
+ frame = undefined;
1904
+ if (line.trim() !== "")
1905
+ message = [];
1906
+ }
1907
+ used.add(index);
1908
+ }
1909
+ if (frame !== undefined && message.length > 0)
1910
+ errors.push({ tool: "pytest", ...frame, column: 0, severity: "error", message: message[0] ?? "" });
1911
+ for (let index = stop;index < lines.length; index++) {
1912
+ if (PYTEST_SUMMARY_LINE.test(lines[index] ?? ""))
1913
+ used.add(index);
1914
+ }
1915
+ return errors;
1916
+ };
1917
+ var COLLECTORS = [collectBunCheck, collectBunTest, collectVitest, collectPlaywright, collectPhpunit, collectPhpstan, collectCsFixer, collectPytest, collectArrowed, collectRuff, collectGo, collectTsc, collectEslint];
1703
1918
  function parseErrors(output) {
1704
1919
  const lines = stripAnsi(output).split(`
1705
1920
  `);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-check",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.9.1",
5
5
  "description": "check, fix and errs: run a repo's check, typecheck, lint and test steps or its fixers, inside its docker compose service when one mounts the folder, showing only what failed with each full output saved to a file, and turn tsc, eslint, bun test, vitest, playwright, phpunit, phpstan and php-cs-fixer logs into file:line:col errors.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -29,6 +29,6 @@
29
29
  "build": "$npm_execpath build src/cli.ts src/fix-cli.ts src/errs-cli.ts --target bun --outdir dist"
30
30
  },
31
31
  "devDependencies": {
32
- "@kaynooo/cli-kit": "0.15.0"
32
+ "@kaynooo/cli-kit": "0.19.0"
33
33
  }
34
34
  }