Skip to content

fix: scaffolded files end with single trailing newline#306

Merged
ichoosetoaccept merged 1 commit intomainfrom
ismart/eof-fix-trailing-newlines
Apr 16, 2026
Merged

fix: scaffolded files end with single trailing newline#306
ichoosetoaccept merged 1 commit intomainfrom
ismart/eof-fix-trailing-newlines

Conversation

@ichoosetoaccept
Copy link
Copy Markdown
Member

@ichoosetoaccept ichoosetoaccept commented Apr 16, 2026

Summary

  • Strip a redundant blank line from project/README.md.jinja, project/.github/actionlint.yaml.jinja and project/{{_copier_conf.answers_file}}.jinja so the rendered files end with a single trailing newline (matches end-of-file-fixer).
  • Exclude the empty actionlint.yaml from the scaffold when use_blacksmith_runners is false.

Why

Without these fixes, the end-of-file-fixer prek hook auto-rewrites scaffolded files on the very first commit, which forces an extra git add && git commit cycle for every new project. Surfaces as part of the broader DOT-491 fresh-scaffold investigation but warrants its own PR.

Test plan

  • poe test — green
  • Generate fresh project, confirm no files are touched by end-of-file-fixer on first commit

- README.md.jinja: use {%- endif %} so the trailing if-block doesn't add a redundant newline
- {{_copier_conf.answers_file}}.jinja: use {{ ... -}} to strip the redundant newline after to_nice_yaml output
- .github/actionlint.yaml.jinja: tighten if/endif whitespace control to remove leading blank line
- copier.yml: exclude .github/actionlint.yaml when use_blacksmith_runners is false (no point shipping empty config)

Each scaffolded file now passes prek's end-of-file-fixer hook on first commit.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR fixes trailing-newline issues across three template files (README.md.jinja, actionlint.yaml.jinja, {{_copier_conf.answers_file}}.jinja) using targeted Jinja2 whitespace-stripping operators ({%- -%} and -}}), and adds a _exclude rule to copier.yml so .github/actionlint.yaml is never generated as an empty file when use_blacksmith_runners is false. Each change is minimal and correct for its context.

Confidence Score: 5/5

Safe to merge — all changes are precise Jinja2 whitespace-control fixes with no logic regressions.

All four changes are narrow, well-targeted whitespace fixes (strip operators and an _exclude rule) that align with Copier/Jinja2 conventions and the keep_trailing_newline: true envop. No P0 or P1 findings were identified.

No files require special attention.

Important Files Changed

Filename Overview
copier.yml Adds _exclude rule to suppress actionlint.yaml generation when use_blacksmith_runners is false; consistent with the existing exclusion patterns.
project/.github/actionlint.yaml.jinja Adds -%} to the opening if tag to strip the post-tag newline, eliminating the leading blank line in the generated YAML when use_blacksmith_runners is true.
project/README.md.jinja Changes {% endif %} to {%- endif %} to strip the trailing newline before the tag, ensuring the generated README ends with exactly one newline.
project/{{_copier_conf.answers_file}}.jinja Adds -}} to the to_nice_yaml expression to strip the trailing template newline, keeping only the newline embedded in to_nice_yaml output for a single EOF newline.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[copier copy / update] --> B{use_blacksmith_runners?}
    B -- false --> C[_exclude: skip actionlint.yaml generation]
    B -- true --> D[Render actionlint.yaml.jinja]
    D --> E["'{%- if use_blacksmith_runners -%}' strips leading + trailing newline"]
    E --> F[self-hosted-runner labels content]
    F --> G["'{%- endif %}' strips pre-tag newline"]
    G --> H[keep_trailing_newline preserves final newline]
    H --> I[actionlint.yaml: clean single trailing newline]
    A --> J[Render README.md.jinja]
    J --> K{use_ci and github.com?}
    K -- true --> L[Branch protection section rendered]
    L --> M["'{%- endif %}' strips pre-tag newline → single EOF newline"]
    K -- false --> N["'{%- endif %}' strips any whitespace → single EOF newline"]
    A --> O["Render answers_file.jinja"]
    O --> P["{{ _copier_answers | to_nice_yaml -}}"]
    P --> Q["'-}}' strips template trailing newline; to_nice_yaml provides its own newline"]
    Q --> R[answers file: clean single trailing newline]
Loading

Reviews (1): Last reviewed commit: "fix: scaffolded files end with single tr..." | Re-trigger Greptile

@ichoosetoaccept ichoosetoaccept merged commit c071edb into main Apr 16, 2026
6 checks passed
@ichoosetoaccept ichoosetoaccept deleted the ismart/eof-fix-trailing-newlines branch April 16, 2026 20:21
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