Skip to content

feat: add no-duplicate-instructions rule - #8

Open
nzakas wants to merge 4 commits into
rule/no-cd-in-runfrom
rule/no-duplicate-instructions
Open

nzakas wants to merge 4 commits into
rule/no-cd-in-runfrom
rule/no-duplicate-instructions

Conversation

@nzakas

@nzakas nzakas commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Adds docker/no-duplicate-instructions, which mirrors hadolint DL4003 and DL4004: only the last CMD, ENTRYPOINT, or HEALTHCHECK in a stage takes effect.

Behavior

  • Reports every CMD, ENTRYPOINT, and HEALTHCHECK that is followed by another instruction with the same keyword in the same build stage.
  • The last occurrence, which is the one Docker uses, is not reported.
  • Stages of a multi-stage build are checked independently.
  • No autofix.
  • Recommended config: "error".

Registration

The rule is registered in src/index.ts (the rules map and the recommended config), the rule list in src/index.spec.ts, and the README's Rules table.

Documentation

Adds docs/rules/no-duplicate-instructions.md with the standard sections: description, background, rule details with incorrect and correct examples, options, when not to use it, and prior art. The rule's meta.docs.url points at that file.

Testing

  • 9 RuleTester cases.
  • 5 documentation checks from tests/rule-docs.test.ts.

136 tests total; build, lint, and format checks pass.

🤖 Generated with Claude Code


Stack created with GitHub Stacks CLI • Give Feedback 💬

Summary by CodeRabbit

  • New Features
    • Added a recommended lint rule that flags earlier CMD, ENTRYPOINT, or HEALTHCHECK instructions when duplicates appear within the same Docker build stage. The final instruction of each type is not flagged, and checks are handled separately for each stage.
  • Documentation
    • Added rule guidance, examples, configuration options, severity recommendations, and related Hadolint checks. The rules table also documents the rule’s association with DL4003 and DL4004.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The plugin adds no-duplicate-instructions to detect repeated CMD, ENTRYPOINT, and HEALTHCHECK instructions within each build stage. The rule reports each occurrence except the last for its instruction type and is enabled as an error in the recommended configuration.

Changes: Duplicate instruction rule

Layer / File(s) Summary
Stage-scoped duplicate detection
src/rules/no-duplicate-instructions.ts, src/rules/no-duplicate-instructions.spec.ts
The rule checks CMD, ENTRYPOINT, and HEALTHCHECK instructions separately in each build stage. It reports all but the last occurrence of each type. Tests cover valid cases, duplicates, and multiple stages.
Plugin registration and documentation
src/index.ts, src/index.spec.ts, README.md, docs/rules/no-duplicate-instructions.md
The plugin registers the rule and enables it as an error in the recommended configuration. The rule list and documentation describe the rule and its behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: Minimal · previous review 16827

This adds a new lint rule that reports earlier duplicate CMD, ENTRYPOINT or HEALTHCHECK instructions in a build stage. It has no autofix, is documented and registered, and I found no actionable merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: add no-duplicate-instructions rule" matches the main change. The PR adds the docker/no-duplicate-instructions rule, its implementation, tests, docs, and registration in the plugin and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat: add no-duplicate-instructions rule" matches the main change. The PR adds the docker/no-duplicate-instructions rule, its implementation, tests, docs, and registration in the plugin and recommended config. The title is short, specific, and uses the conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 508ba1a1-eb7a-4995-a92a-d628f62c41ca
Commits

Reviewing files that changed from the base of the PR and between 8d87141 and 168274a.

Files selected for processing: 1

  • README.md
Files skipped from review as they are similar to previous changes: 1

  • README.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@nzakas
nzakas added this pull request to stack #16 November 10, 2026 22:35
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 0988a55 to e51e230 Compare November 10, 2026 23:17
@nzakas
nzakas requested a balanced review from Copilot November 11, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The documented CMD example contains an unsupported trailing comment that becomes part of the instruction, preventing it from launching node worker.js as intended.

1 open issue
What changed in this PR

Adds docker/no-duplicate-instructions to detect overridden CMD, ENTRYPOINT, and HEALTHCHECK instructions within each Docker build stage.

Changes:

  • Reports all but the last occurrence of each tracked instruction, without autofixes.
  • Registers the rule and enables it as an error in the recommended configuration.
  • Adds rule tests, documentation, and a README entry.
File Description
src/​rules/​no-duplicate-instructions.ts Implements stage-scoped duplicate detection.
src/​rules/​no-duplicate-instructions.spec.ts Tests duplicate reporting and stage isolation.
src/​index.ts Registers and enables the rule in the recommended configuration.
src/​index.spec.ts Adds the rule to registration expectations.
README.md Lists the new rule and its recommended severity.
docs/​rules/​no-duplicate-instructions.md Documents behavior, examples, and prior art.

Review effort: Balanced

Comment thread docs/rules/no-duplicate-instructions.md Resolved
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from a7fb730 to d77dd65 Compare November 11, 2026 15:35
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch 3 times, most recently from fe1e218 to 9243528 Compare November 17, 2026 16:00
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 9243528 to 8012acb Compare November 18, 2026 15:47
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 8012acb to 827f9c7 Compare November 19, 2026 17:18
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 827f9c7 to 8d87141 Compare November 19, 2026 17:21
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 8d87141 to 168274a Compare November 20, 2026 15:47
nzakas and others added 4 commits November 23, 2026 14:05
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Dockerfile instructions do not support trailing comments, so the comment
became part of the CMD arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nzakas
nzakas force-pushed the rule/no-duplicate-instructions branch from 168274a to 4c4912a Compare November 23, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants