Skip to content

chore: restore final newline in Makefiles after mbake-format#5

Merged
andrewferrier merged 1 commit into
mainfrom
copilot/adjust-precommit-hook-formatting
Jun 13, 2026
Merged

chore: restore final newline in Makefiles after mbake-format#5
andrewferrier merged 1 commit into
mainfrom
copilot/adjust-precommit-hook-formatting

Conversation

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

mbake-format strips the trailing newline from Makefiles, which causes subsequent hooks (e.g. editorconfig-checker) to fail on every run.

Changes

  • .pre-commit-config.yaml: Adds a local hook (makefile-final-newline) that runs after mbake-format/mbake-validate and appends a newline to any Makefile missing one.

The entry uses $(tail -c1 "$f") in a command substitution — which strips trailing newlines — so the condition is false when the file already ends with \n, making the hook a no-op on well-formed files:

entry: bash -c 'for f in "$@"; do [ -n "$(tail -c1 "$f")" ] && printf "\n" >> "$f"; done' --

@andrewferrier

Copy link
Copy Markdown
Owner

@copilot please keep the scope of the hook narrow, only makefiles . Also it only adds new lines when they are missing, right?

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please keep the scope of the hook narrow, only makefiles . Also it only adds new lines when they are missing, right?

Both are already the case:

  • Makefiles only: types: [makefile] restricts the hook to Makefile-type files.
  • Only when missing: [ -n "$(tail -c1 "$f")" ]$() strips trailing newlines, so if the file already ends with \n the result is empty and the condition is false; the newline is only appended when absent.

@andrewferrier andrewferrier left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@

@andrewferrier
andrewferrier marked this pull request as ready for review June 13, 2026 06:16
Copilot AI review requested due to automatic review settings June 13, 2026 06:16
@andrewferrier
andrewferrier merged commit 17406cb into main Jun 13, 2026
2 checks passed
@andrewferrier
andrewferrier deleted the copilot/adjust-precommit-hook-formatting branch June 13, 2026 06:16

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.

Pull request overview

This PR adds a post-mbake-format pre-commit step to restore the final newline in Makefiles, preventing follow-on hooks (e.g. editorconfig-checker) from failing repeatedly due to missing EOF newlines.

Changes:

  • Add a local pre-commit hook (makefile-final-newline) intended to append a newline to Makefiles that don’t end with \n.
  • Position the hook after mbake-format / mbake-validate to repair formatting side-effects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .pre-commit-config.yaml
hooks:
- id: makefile-final-newline
name: Restore final newline stripped by mbake-format
entry: bash -c 'for f in "$@"; do [ -n "$(tail -c1 "$f")" ] && printf "\n" >> "$f"; done' --
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.

3 participants