Skip to content

Add render-first lint step for chezmoi templates - #57

Merged
gtbuchanan merged 1 commit into
mainfrom
add-template-linting
Jul 3, 2026
Merged

Add render-first lint step for chezmoi templates#57
gtbuchanan merged 1 commit into
mainfrom
add-template-linting

Conversation

@gtbuchanan

@gtbuchanan gtbuchanan commented Jul 2, 2026

Copy link
Copy Markdown
Owner

What

Adds an hk render-templates step that renders every changed *.tmpl through chezmoi execute-template, failing on template syntax and undefined-ref errors. The shell and eslint steps exclude *.tmpl (their parsers choke on {{ }}), so source templates were unlinted. This validates that templates render — not that the rendered output passes a type-specific lint.

CI config generation

chezmoi execute-template needs the config data that chezmoi init normally generates, which CI doesn't have. scripts/lint-templates.sh regenerates it from .chezmoi.yaml.tmpl into a throwaway file and renders against it, so the check behaves the same locally and in CI. chezmoi is added to mise.toml so CI can install it.

Scope

A render picks one conditional branch, so only one representative hosttype/OS variation is exercised. Linting rendered output through per-type tools was prototyped but dropped — it only ever covers the rendered variation.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@gtbuchanan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b92a4070-b6e2-45e4-ba62-d38b70323aff

📥 Commits

Reviewing files that changed from the base of the PR and between 1acf1fd and eb75058.

⛔ Files ignored due to path filters (2)
  • hk.pkl is excluded by !**/*.pkl
  • mise.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • AGENTS.md
  • mise.toml
  • scripts/lint-templates.sh
📝 Walkthrough

Walkthrough

Adds a new shell script scripts/lint-templates.sh to validate chezmoi template rendering, pins a chezmoi version in mise.toml to support this and CI template rendering, and documents the new scripts/ directory in AGENTS.md.

Changes

Template Lint Tooling

Layer / File(s) Summary
Lint script implementation
scripts/lint-templates.sh
New POSIX shell script that regenerates a chezmoi config from home/.chezmoi.yaml.tmpl, renders provided templates (handling init-only templates specially), tracks failures, and exits non-zero on any render error.
Tooling and documentation support
mise.toml, AGENTS.md
Pins chezmoi = "2.70.5" in [tools] with comments explaining its use for hk render-templates and CI, and documents the new scripts/ directory in the repo structure docs.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: a render-first lint step for chezmoi templates.
Description check ✅ Passed The description is directly related to the template rendering lint step and CI support changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

Warning

Review ran into problems

🔥 Problems

Linked repositories: Your configuration references 1 linked repositories, but your current plan allows 0. Analyzed ``, skipped gtbuchanan/tooling.


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

Comment @coderabbitai help to get the list of available commands.

@gtbuchanan
gtbuchanan force-pushed the add-template-linting branch 2 times, most recently from 82a85e4 to 1acf1fd Compare July 2, 2026 23:52
@gtbuchanan
gtbuchanan marked this pull request as ready for review July 2, 2026 23:53

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/lint-templates.sh`:
- Around line 13-16: The hosttype prompt text is duplicated between the lint
script and the chezmoi template, which can drift and break promptChoice
matching. Update the logic in scripts/lint-templates.sh around hosttype_prompt
to derive the prompt text at runtime from home/.chezmoi.yaml.tmpl instead of
hardcoding it, so the value always stays in sync and avoids a silent
--promptChoice fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d642c496-c052-4b49-a20d-351589b25586

📥 Commits

Reviewing files that changed from the base of the PR and between e405b2d and 1acf1fd.

⛔ Files ignored due to path filters (2)
  • hk.pkl is excluded by !**/*.pkl
  • mise.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • AGENTS.md
  • mise.toml
  • scripts/lint-templates.sh
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
AGENTS.md

📄 CodeRabbit inference engine (CLAUDE.md)

AGENTS.md: Document agent responsibilities and capabilities in AGENTS.md
Maintain AGENTS.md as the source of truth for agent configuration and behavior documentation

Files:

  • AGENTS.md
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: Never edit deployed files directly (for example `~/.gitconfig`, `~/.config/AGENTS.md`, or `~/.claude/settings.json`); edit the corresponding source files under `home/` and deploy with `chezmoi apply`.
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: Always pass `--no-tty` to `chezmoi apply` so interactive prompts fail instead of blocking.
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: Never run `chezmoi apply --force` without targets; if `--force` is needed, scope it to specific target path(s).
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: When editing shared templates that feed multiple outputs, use bare `chezmoi apply` so all outputs regenerate.
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: To preview changes without applying them, use `chezmoi diff`.
Learnt from: CR
Repo: gtbuchanan/dotfiles

Timestamp: 2026-07-02T23:53:38.989Z
Learning: To force a rerun of a `run_onchange_*` script, delete its `entryState` entry keyed by the rendered script destination path and then run `chezmoi apply`.
🔇 Additional comments (4)
scripts/lint-templates.sh (2)

1-36: LGTM!


38-67: LGTM!

mise.toml (1)

38-40: LGTM!

AGENTS.md (1)

103-103: LGTM!

Comment thread scripts/lint-templates.sh Outdated
The shell and eslint steps exclude *.tmpl, so templates were
unlinted. Add an hk render-templates step that renders each through
`chezmoi execute-template`, failing on syntax and undefined-ref
errors.

CI has no `chezmoi init` config, so scripts/lint-templates.sh
regenerates one from .chezmoi.yaml.tmpl and renders against it. Adds
chezmoi to mise.toml so the step resolves in CI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gtbuchanan
gtbuchanan force-pushed the add-template-linting branch from 1acf1fd to eb75058 Compare July 3, 2026 00:05
@gtbuchanan
gtbuchanan merged commit 1d103c1 into main Jul 3, 2026
2 checks passed
@gtbuchanan
gtbuchanan deleted the add-template-linting branch July 3, 2026 00:07
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