Skip to content

Fix rule bugs, expand rule set, add multi-file input - #4

Merged
davidgrldo merged 1 commit into
mainfrom
feat/expand-rules-and-multifile
Jul 17, 2026
Merged

Fix rule bugs, expand rule set, add multi-file input#4
davidgrldo merged 1 commit into
mainfrom
feat/expand-rules-and-multifile

Conversation

@davidgrldo

Copy link
Copy Markdown
Owner

Follow-up to a review of dockopt: three correctness fixes, an analyzer cleanup, a broader rule set, and batch (multi-file) analysis.

Bug fixes

Each has a regression test and a binary-level CI fixture contract.

  • GO002 false error — no longer fires when CGO_ENABLED=0 is set via a stage-level ENV/ARG (previously only the inline RUN form was recognized, so idiomatic Dockerfiles failed CI with an error-grade finding).
  • Here-string parse failure — bash here-strings (<<<) are no longer misparsed as heredocs (previously parse_error, exit 2).
  • GEN001 coverage gap — untagged base images (implicit :latest) are now flagged, while exempting scratch, digest-pinned images, and prior stage references.

Analyzer cleanup (behavior-preserving)

  • Removed the dead Context struct threaded through every rule.
  • Collapsed the single-implementation Rule interface + defensive copy layers into a concrete rule registry.
  • Stack is detected once per run instead of twice.

New rules

ID Severity Checks
GEN002 warn apt-get install without --no-install-recommends
GEN003 warn apt-get install without clearing /var/lib/apt/lists in the same RUN
GEN004 warn ADD <url> anti-pattern
GEN005 warn final stage running as root

JAVA001 broadened to all JDK versions/repos (openjdk, eclipse-temurin, amazoncorretto) instead of the single exact tag openjdk:17.

Multi-file input

  • Accepts N Dockerfile paths (shell globbing supported).
  • JSON output becomes JSON Lines; single-file output is byte-identical to before (backward compatible).
  • Human output gets per-file ==> path <== headers; exit code is the most severe outcome across all paths (2 > 1 > 0).

Docs & tests

  • README gains a full rules reference and a multi-file section.
  • 5 new complex fixtures (ENV-CGO clean build, here-string+heredoc, untagged base, apt anti-patterns, realistic distroless multi-stage).
  • Test count 96 → 123. gofmt/go vet clean, -race clean, fuzz clean, CI fixture contract replayed locally.

Known limitations (marked with ponytail: comments in code + noted in README)

  • Heredoc bodies aren't analyzed.
  • apt-get -y install (flag before the subcommand) isn't detected.

🤖 Generated with Claude Code

Follow-up to a review of dockopt. Three correctness fixes, an
analyzer cleanup, a broader rule set, and batch (multi-file) analysis.

Bug fixes (each with a regression test + CI fixture contract):
- GO002 no longer false-errors when CGO_ENABLED=0 is set via a
  stage-level ENV/ARG (not just inline in the RUN).
- Bash here-strings (<<<) are no longer misparsed as heredocs.
- GEN001 now flags untagged base images (implicit :latest), while
  exempting scratch, digest-pinned images, and prior stage references.

Analyzer cleanup (behavior-preserving):
- Remove the dead Context struct threaded through every rule.
- Collapse the single-implementation Rule interface and its defensive
  copy layers into a concrete rule registry.
- Detect the stack once per run instead of twice.

New rules:
- GEN002/GEN003: apt-get install without --no-install-recommends / cache cleanup.
- GEN004: ADD <url> anti-pattern.
- GEN005: final stage running as root.
- JAVA001 broadened to all JDK versions/repos (openjdk, eclipse-temurin,
  amazoncorretto) rather than the exact tag openjdk:17.

Multi-file input:
- Accept N Dockerfile paths (shell globbing supported).
- JSON output becomes JSON Lines; single-file output is unchanged.
- Human output gets per-file headers; exit code is the max across paths.

README gains a rules reference and multi-file docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@davidgrldo
davidgrldo merged commit ae4aea8 into main Jul 17, 2026
2 checks passed
@davidgrldo
davidgrldo deleted the feat/expand-rules-and-multifile branch July 17, 2026 19:14
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