Skip to content

fix: report blocked rules and range info in JSON output#152

Merged
rhuanbarreto merged 2 commits into
mainfrom
fix/json-output-blocked-rules
Mar 23, 2026
Merged

fix: report blocked rules and range info in JSON output#152
rhuanbarreto merged 2 commits into
mainfrom
fix/json-output-blocked-rules

Conversation

@rhuanbarreto

@rhuanbarreto rhuanbarreto commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Blocked rule files (security scanner violations, missing companion files) are now included in JSON output as RuleResult entries with status: "error" instead of throwing and producing no JSON
  • All violations (security scan and normal ADR rules) now support endLine/endColumn for precise expression highlighting in editors
  • Missing companion .rules.ts files point the diagnostic at the rules: true line in the ADR markdown

Problem

Before this fix, archgate check --json with a blocked rule file would log errors to stderr and exit with no JSON on stdout — breaking editor integrations that expect valid JSON regardless of rule errors.

Changes

File Change
src/engine/loader.ts Return LoadResult discriminated union (loaded / blocked) instead of throwing; blockedToRuleResult() converter; find rules: true line for missing companion diagnostic
src/engine/runner.ts Accept LoadResult[], convert blocked entries to error RuleResults before running loaded rules
src/engine/rule-scanner.ts Report endLine/endColumn from AST node locations
src/engine/reporter.ts Include endLine/endColumn in JSON output
src/formats/rules.ts Add endLine?/endColumn? to ViolationDetail
src/helpers/rules-shim.ts Add endLine?/endColumn? to ambient ViolationDetail type (for rule authors)
src/commands/check.ts Adapt to LoadResult[] return type
src/engine/context.ts Adapt to LoadResult[] return type
tests/ Update tests: blocked rules return results instead of throwing

JSON output examples

Blocked rule (security scanner):

{
  "adrId": "DATA-017",
  "ruleId": "security-scan",
  "status": "error",
  "error": "ADR DATA-017: rule file blocked by security scanner (1 violation)",
  "violations": [{
    "message": "Bun.spawn() is blocked in rule files.",
    "file": ".archgate/adrs/DATA-017-schema-migration-management.rules.ts",
    "line": 12, "endLine": 12, "endColumn": 23,
    "severity": "error"
  }]
}

Missing companion file:

{
  "adrId": "BE-003",
  "ruleId": "security-scan",
  "status": "error",
  "violations": [{
    "message": "No companion .rules.ts file found. Create BE-003-foo.rules.ts or set rules: false.",
    "file": ".archgate/adrs/BE-003-foo.md",
    "line": 4, "endLine": 4, "endColumn": 11,
    "severity": "error"
  }]
}

Test plan

  • archgate check --json with a blocked rule outputs valid JSON with status: "error"
  • Security violations include file, line, endLine, endColumn
  • Missing companion file points at rules: true line in the ADR markdown
  • Normal rule violations can optionally include endLine/endColumn
  • Exit code is 2 for rule errors, 1 for violations, 0 for pass
  • All existing tests pass (updated for new return types)

🤖 Generated with Claude Code

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 23, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: c64bea3
Status: ✅  Deploy successful!
Preview URL: https://0af8fc57.archgate-cli.pages.dev
Branch Preview URL: https://fix-json-output-blocked-rule.archgate-cli.pages.dev

View logs

@rhuanbarreto rhuanbarreto force-pushed the fix/json-output-blocked-rules branch 4 times, most recently from 327cdd5 to c1fff6e Compare March 23, 2026 15:27
@rhuanbarreto rhuanbarreto changed the title fix: include blocked rules in JSON output fix: report blocked rules and range info in JSON output Mar 23, 2026
When a rule file is blocked by the security scanner, the CLI now
includes it in the JSON output as a RuleResult with status "error"
instead of throwing and producing no JSON.

Violations include file, line, endLine, and endColumn so editors
can highlight the exact blocked expression (e.g., Bun.spawn()).
Normal ADR rule violations can also report endLine/endColumn for
precise range highlighting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rhuanbarreto rhuanbarreto force-pushed the fix/json-output-blocked-rules branch from c1fff6e to d1e4795 Compare March 23, 2026 15:37
@rhuanbarreto rhuanbarreto merged commit 0acb40d into main Mar 23, 2026
9 checks passed
@rhuanbarreto rhuanbarreto deleted the fix/json-output-blocked-rules branch March 23, 2026 15:43
@github-actions github-actions Bot mentioned this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant