checkchange 0.5.0 → 0.5.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
@@ -251,6 +251,10 @@ Some of the most useful options are:
251
251
  | `--verbose` | Show additional diagnostics | off |
252
252
  | `--auto-coverage` | Attempt automatic coverage setup | off |
253
253
 
254
+ Flags are per-command: `checkchange check --help` lists `--format`, `--base`,
255
+ `--json`; every subcommand lists its own flags. Unknown flags are rejected
256
+ with `Error: Unknown option <arg>` (exit 1) rather than silently ignored.
257
+
254
258
  The base reference is automatically detected when `--base` is not supplied.
255
259
 
256
260
  Provider configuration can be supplied explicitly or discovered from the repository.
package/dist/cli.js CHANGED
@@ -42,8 +42,9 @@ function splitValue(argv, i, name) {
42
42
  // value slot is mistaken for the flag (`check --base --version` printed the
43
43
  // version instead of resolving `--version` as the base ref). Skip value slots.
44
44
  // Mirrors how each subcommand consumes them: --base is exact-match next-slot in
45
- // parseCliArgs, --baseline/--current are exact-match next-slot in runDelta; the
46
- // other four match by prefix and take `--flag=value` (no slot) or the next slot.
45
+ // parseCliArgs (check); --baseline/--current are exact-match next-slot in
46
+ // runDelta; doctor/explain/trace take --provider-config/--crap-threshold/
47
+ // --coverage-file/--format and explain/trace also --base as inline-or-next.
47
48
  const VALUE_FLAGS_NEXT_SLOT_ONLY = new Set([
48
49
  '--base',
49
50
  '--baseline',
@@ -55,6 +56,8 @@ const VALUE_FLAGS_INLINE_OR_NEXT = [
55
56
  '--coverage-file',
56
57
  '--format',
57
58
  ];
59
+ // Allowed value flags for the two commands that share a flag set (explain/trace).
60
+ const EXPLAIN_TRACE_VALUE_FLAGS = ['--base', '--crap-threshold', '--coverage-file'];
58
61
  // One pass, two questions: the duplication was the loop, not the data.
59
62
  // A1 asks "was --version passed as a flag?"; A2 asks "is there a positional
60
63
  // argument at all?" — the dispatcher resolves any argv whose first token is
@@ -84,6 +87,28 @@ function scanArgv(args) {
84
87
  }
85
88
  return { hasVersion, hasPositional };
86
89
  }
90
+ // A3: doctor/explain/trace used to accept any stray flag silently (argv.includes
91
+ // never rejected), so `doctor --format sarif` ran as if --format were
92
+ // absent. delta/prepare-repo already reject; this makes the other three agree.
93
+ // Value slots are skipped by the loop below (same convention as scanArgv); a
94
+ // bare value flag like `--base --json` is not "Unknown option" here — the
95
+ // value parser (flagValueInlineOrNext) reports `requires a value` instead.
96
+ function assertKnownFlags(argv, allowedValueFlags, allowedBooleans) {
97
+ for (let i = 0; i < argv.length; i += 1) {
98
+ const arg = argv[i];
99
+ if (!arg.startsWith('-'))
100
+ continue; // value slot or ruleId positional
101
+ const inline = arg.includes('=');
102
+ const name = inline ? arg.slice(0, arg.indexOf('=')) : arg;
103
+ if (allowedValueFlags.includes(name)) {
104
+ if (!inline)
105
+ i += 1;
106
+ }
107
+ else if (!allowedBooleans.includes(arg)) {
108
+ throw new Error(`Unknown option ${arg}`);
109
+ }
110
+ }
111
+ }
87
112
  function parseCrapThreshold(value) {
88
113
  const parsed = parseFloat(value);
89
114
  if (!isFinite(parsed) || parsed < 0) {
@@ -340,10 +365,11 @@ const DOTNET_COVERAGE_HINT = ' or `dotnet test --collect:"XPlat Code Coverage"`
340
365
  * no analysis engine duplication.
341
366
  */
342
367
  async function runDoctor(argv) {
368
+ assertKnownFlags(argv, ['--provider-config'], ['--json', '--allow-external-config']);
343
369
  const json = argv.includes('--json');
344
- // Parse --provider-config from argv for doctor
345
- const pcIdx = argv.indexOf('--provider-config');
346
- const providerConfigPath = pcIdx !== -1 ? argv[pcIdx + 1] : undefined;
370
+ // --provider-config is inline-or-next; a bare flag now errors instead of
371
+ // silently treating the following token (e.g. --json) as a path.
372
+ const providerConfigPath = flagValueInlineOrNext(argv, '--provider-config');
347
373
  const allowExternalConfig = argv.includes('--allow-external-config');
348
374
  const { registry, source: providerSource } = initProviderConfig(providerConfigPath, allowExternalConfig);
349
375
  SUPPORTED_EXTENSIONS = new Set(registry.keys());
@@ -442,15 +468,54 @@ async function runDoctor(argv) {
442
468
  }
443
469
  }
444
470
  /**
445
- * Reads the value of a space-separated CLI flag, if present.
446
- * ponytail: shared by explain; check uses parseCliArgs (full validation).
471
+ * Reads a value-taking flag in either `--flag=value` or `--flag value` form.
472
+ * Absent flag → undefined. Present without a value (missing next slot, or the
473
+ * next slot is another flag) → throws; main maps it to `Error: ...` + exit 1.
447
474
  */
448
- function flagValue(argv, name) {
449
- const index = argv.indexOf(name);
475
+ function flagValueInlineOrNext(argv, name) {
476
+ const inlinePrefix = `${name}=`;
477
+ const index = argv.findIndex((arg) => arg === name || arg.startsWith(inlinePrefix));
450
478
  if (index === -1)
451
479
  return undefined;
480
+ const arg = argv[index];
481
+ if (arg.startsWith(inlinePrefix)) {
482
+ // `--base=` is an empty value, same as a bare flag: reject rather than
483
+ // silently default (parseCliArgs rejects empty --coverage-file the same way).
484
+ const value = arg.slice(inlinePrefix.length);
485
+ if (value === '') {
486
+ throw new Error(`${name} requires a value`);
487
+ }
488
+ return value;
489
+ }
452
490
  const value = argv[index + 1];
453
- return value === undefined || value.startsWith('-') ? undefined : value;
491
+ if (value === undefined || value.startsWith('-')) {
492
+ throw new Error(`${name} requires a value`);
493
+ }
494
+ return value;
495
+ }
496
+ /**
497
+ * Provider source for the complexity measurement: the engine-reported quality
498
+ * wins; otherwise infer it from the complexity stage capability.
499
+ */
500
+ function deriveComplexity(output) {
501
+ return (output.diagnostics?.quality?.complexity ??
502
+ (output.capabilities?.complexity === 'failed' ? 'UNAVAILABLE' : 'NATIVE'));
503
+ }
504
+ /**
505
+ * Coverage quality: the engine-reported value wins; otherwise DIRECT only when
506
+ * the coverage artifact was actually available.
507
+ */
508
+ function deriveCoverageQuality(output) {
509
+ return (output.diagnostics?.quality?.coverage ??
510
+ (output.capabilities?.coverageArtifact === 'available' ? 'DIRECT' : 'UNAVAILABLE'));
511
+ }
512
+ /** Reason the score fell back to null, from the run's status and coverage quality. */
513
+ function deriveFallback(analysisStatus, coverageQuality) {
514
+ if (analysisStatus === 'UNSUPPORTED')
515
+ return 'analysis skipped — unsupported source';
516
+ if (coverageQuality === 'DIRECT')
517
+ return 'none — coverage direct evidence used';
518
+ return 'coverage direct evidence absent — score null (INV-01: null, not 0%)';
454
519
  }
455
520
  /**
456
521
  * `explain` subcommand: prints provider/input/threshold/fallback derivation for
@@ -458,12 +523,13 @@ function flagValue(argv, name) {
458
523
  * derivation logic. Optional ruleId positional filters rule results.
459
524
  */
460
525
  async function runExplain(argv) {
526
+ assertKnownFlags(argv, EXPLAIN_TRACE_VALUE_FLAGS, ['--json']);
461
527
  const json = argv.includes('--json');
462
528
  const ruleId = argv.find((a) => !a.startsWith('-'));
463
- const rawThreshold = flagValue(argv, '--crap-threshold');
464
- const threshold = rawThreshold !== undefined ? parseFloat(rawThreshold) : 30;
465
- const baseArg = flagValue(argv, '--base');
466
- const coverageFile = flagValue(argv, '--coverage-file');
529
+ const rawThreshold = flagValueInlineOrNext(argv, '--crap-threshold');
530
+ const threshold = rawThreshold === undefined ? 30 : parseCrapThreshold(rawThreshold);
531
+ const baseArg = flagValueInlineOrNext(argv, '--base');
532
+ const coverageFile = flagValueInlineOrNext(argv, '--coverage-file');
467
533
  const base = baseArg ?? (await detectDefaultBase(false));
468
534
  if (base === null) {
469
535
  throw new Error('Cannot auto-detect base branch. Provide --base <ref> explicitly.');
@@ -472,15 +538,9 @@ async function runExplain(argv) {
472
538
  const resolvedBase = await resolveBaseRef(base);
473
539
  const { intervals } = await getChangedIntervals(resolvedBase);
474
540
  const output = await buildEvidenceOutput(resolvedBase, intervals, process.cwd(), threshold, coverageFile);
475
- const complexity = output.diagnostics?.quality?.complexity ??
476
- (output.capabilities?.complexity === 'failed' ? 'UNAVAILABLE' : 'NATIVE');
477
- const coverageQuality = output.diagnostics?.quality?.coverage ??
478
- (output.capabilities?.coverageArtifact === 'available' ? 'DIRECT' : 'UNAVAILABLE');
479
- const fallback = output.analysisStatus === 'UNSUPPORTED'
480
- ? 'analysis skipped — unsupported source'
481
- : coverageQuality === 'DIRECT'
482
- ? 'none — coverage direct evidence used'
483
- : 'coverage direct evidence absent — score null (INV-01: null, not 0%)';
541
+ const complexity = deriveComplexity(output);
542
+ const coverageQuality = deriveCoverageQuality(output);
543
+ const fallback = deriveFallback(output.analysisStatus, coverageQuality);
484
544
  const ruleResults = ruleId === undefined
485
545
  ? output.ruleResults
486
546
  : output.ruleResults.filter((r) => r.ruleId === ruleId);
@@ -518,11 +578,12 @@ async function runExplain(argv) {
518
578
  * (evidence-contract.md:341) carries no timing, so `check --json` is unchanged.
519
579
  */
520
580
  async function runTrace(argv) {
581
+ assertKnownFlags(argv, EXPLAIN_TRACE_VALUE_FLAGS, ['--json']);
521
582
  const json = argv.includes('--json');
522
- const rawThreshold = flagValue(argv, '--crap-threshold');
523
- const threshold = rawThreshold !== undefined ? parseFloat(rawThreshold) : 30;
524
- const baseArg = flagValue(argv, '--base');
525
- const coverageFile = flagValue(argv, '--coverage-file');
583
+ const rawThreshold = flagValueInlineOrNext(argv, '--crap-threshold');
584
+ const threshold = rawThreshold === undefined ? 30 : parseCrapThreshold(rawThreshold);
585
+ const baseArg = flagValueInlineOrNext(argv, '--base');
586
+ const coverageFile = flagValueInlineOrNext(argv, '--coverage-file');
526
587
  const base = baseArg ?? (await detectDefaultBase(false));
527
588
  if (base === null) {
528
589
  throw new Error('Cannot auto-detect base branch. Provide --base <ref> explicitly.');
@@ -174,10 +174,10 @@ export function vehicleRejection() {
174
174
  return lastVehicleRejection;
175
175
  }
176
176
  // The fallback parser is checkchange's OWN code (./csharpFallbackParser.ts), so
177
- // its tool is checkchange and its version is the package version — same 0.5.0
177
+ // its tool is checkchange and its version is the package version — same 0.5.1
178
178
  // the other self-provenance consts hard-code (src/crapCalc.ts:3, src/rules.ts:4).
179
179
  const FALLBACK_TOOL = 'checkchange';
180
- const FALLBACK_TOOL_VERSION = '0.5.0';
180
+ const FALLBACK_TOOL_VERSION = '0.5.1';
181
181
  // The vehicle's INSTALLED version is never probed: the rich path is
182
182
  // documented-unreachable (see SPAWN FORM above), so `dotnet-crap --version` is
183
183
  // never spawned to learn it, and no version is fabricated here. `unknown` is the
@@ -1,5 +1,5 @@
1
1
  export declare const crapCalcProvenance: {
2
2
  readonly tool: "checkchange";
3
- readonly version: "0.5.0";
3
+ readonly version: "0.5.1";
4
4
  };
5
5
  export declare function calculateCrap(cc: number, coveragePercent: number | null): number | null;
package/dist/crapCalc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Provenance for the crapCalc lineage stage. Self tool version tracks package.json
2
- // (matches existing hard-coded '0.5.0' style for the core package).
3
- export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.0' };
2
+ // (matches existing hard-coded '0.5.1' style for the core package).
3
+ export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.1' };
4
4
  export function calculateCrap(cc, coveragePercent) {
5
5
  if (coveragePercent == null) {
6
6
  return null;
@@ -31,7 +31,7 @@ export interface DiagnosticLineageEntry {
31
31
  }
32
32
  export declare const evidenceProvenance: {
33
33
  readonly tool: "checkchange";
34
- readonly version: "0.5.0";
34
+ readonly version: "0.5.1";
35
35
  };
36
36
  export interface EvidenceOutput {
37
37
  schemaVersion: string;
package/dist/evidence.js CHANGED
@@ -19,8 +19,8 @@ import * as fs from 'fs';
19
19
  import * as path from 'path';
20
20
  import { loadProviderConfig, deriveRegistry, builtinConfig, createGenericCommandProvider } from './providers/index.js';
21
21
  const requireFromEvidence = createRequire(import.meta.url);
22
- // Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.0').
23
- export const evidenceProvenance = { tool: 'checkchange', version: '0.5.0' };
22
+ // Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.1').
23
+ export const evidenceProvenance = { tool: 'checkchange', version: '0.5.1' };
24
24
  function sha256Hex(content) {
25
25
  return createHash('sha256').update(content).digest('hex');
26
26
  }
@@ -18,6 +18,9 @@ export function formatSARIF(out, opts) {
18
18
  message: { text: `${r.method} CRAP ${r.crap} > ${r.threshold} (cc ${r.cc}, cov ${r.coverage})` },
19
19
  }));
20
20
  return JSON.stringify({
21
+ // SARIF 2.1.0 top-level schema key is `$schema`; the schemastore schema
22
+ // has additionalProperties:false, so `schema` would make the doc invalid.
23
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
21
24
  version: '2.1.0',
22
25
  runs: [
23
26
  {
package/dist/git.js CHANGED
@@ -29,6 +29,12 @@ export async function resolveBaseRef(base, cwd = process.cwd(), trace) {
29
29
  throw new Error('Git executable not found');
30
30
  }
31
31
  if (result.exitCode !== 0) {
32
+ // git prints `fatal: not a git repository` when run outside a repo; surface
33
+ // that distinction instead of reporting a ref-resolution failure, which
34
+ // sends users hunting for the wrong base ref.
35
+ if (result.stderr.includes('not a git repository')) {
36
+ throw new Error('Not a git repository — run from a repo root or initialize one with `git init`.');
37
+ }
32
38
  throw new Error(`Cannot resolve base reference: ${base}`);
33
39
  }
34
40
  return result.stdout.trim();
package/dist/help.js CHANGED
@@ -216,7 +216,8 @@ Options:
216
216
  --version Print version and exit
217
217
 
218
218
  Run 'checkchange <command> --help' for command-specific help.
219
- Tip: 'checkchange <command> --help --json' for machine-readable help.`;
219
+ Tip: 'checkchange <command> --help --json' for machine-readable help.
220
+ Flags are per-command: run 'checkchange check --help' to list --format, --base, --json; every subcommand lists its own flags.`;
220
221
  function jsonTip(command) {
221
222
  return `Tip: 'checkchange ${command} --help --json' for machine-readable help.`;
222
223
  }
package/dist/rules.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ChangedFunction } from './evidence.js';
2
2
  export declare const rulesProvenance: {
3
3
  readonly tool: "checkchange";
4
- readonly version: "0.5.0";
4
+ readonly version: "0.5.1";
5
5
  };
6
6
  export interface RuleResult {
7
7
  ruleId: string;
package/dist/rules.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Provenance for the rules lineage stage. Self tool version tracks package.json.
2
- export const rulesProvenance = { tool: 'checkchange', version: '0.5.0' };
2
+ export const rulesProvenance = { tool: 'checkchange', version: '0.5.1' };
3
3
  /**
4
4
  * Evaluate changed functions against the high-CRAP rule.
5
5
  * @param changed Array of changed functions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkchange",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "packageManager": "pnpm@11.17.0",
6
6
  "type": "module",