fix: report blocked rules and range info in JSON output#152
Merged
Conversation
Deploying archgate-cli with
|
| 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 |
327cdd5 to
c1fff6e
Compare
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>
c1fff6e to
d1e4795
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RuleResultentries withstatus: "error"instead of throwing and producing no JSONendLine/endColumnfor precise expression highlighting in editors.rules.tsfiles point the diagnostic at therules: trueline in the ADR markdownProblem
Before this fix,
archgate check --jsonwith 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
src/engine/loader.tsLoadResultdiscriminated union (loaded/blocked) instead of throwing;blockedToRuleResult()converter; findrules: trueline for missing companion diagnosticsrc/engine/runner.tsLoadResult[], convert blocked entries to errorRuleResults before running loaded rulessrc/engine/rule-scanner.tsendLine/endColumnfrom AST node locationssrc/engine/reporter.tsendLine/endColumnin JSON outputsrc/formats/rules.tsendLine?/endColumn?toViolationDetailsrc/helpers/rules-shim.tsendLine?/endColumn?to ambientViolationDetailtype (for rule authors)src/commands/check.tsLoadResult[]return typesrc/engine/context.tsLoadResult[]return typetests/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 --jsonwith a blocked rule outputs valid JSON withstatus: "error"rules: trueline in the ADR markdown🤖 Generated with Claude Code