Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The hook checks working-tree contents instead of staged bytes, and the newline checker accepts trailing CR bytes after LF, allowing invalid committed content to pass validation.
2 open issues
What changed in this PR
This PR moves end-of-file newline validation into PX4’s regular formatting workflow, replacing the slow shell checker with a Python implementation that supports automatic fixes.
Changes:
- Add a tail-reading newline checker with
--fix. - Integrate newline checks into formatting targets and the pre-commit hook.
- Remove the standalone newline-check target and CI matrix entry.
| File | Description |
|---|---|
Tools/astyle/pre-commit |
Invoke newline validation for staged text-file paths outside docs. |
Tools/astyle/check_newlines.sh |
Remove the previous shell checker. |
Tools/astyle/check_newlines.py |
Add faster newline validation and automatic repair. |
Makefile |
Integrate checks and fixes into formatting targets; remove check_newlines. |
.github/workflows/checks.yml |
Remove the separate newline-check matrix entry. |
Review effort: Balanced
The end of file newline check spawned two processes per tracked file and took ~85s, so it only ran as a separate CI job. Rewrite it in Python reading only the last bytes of each file (~0.3s) and add --fix to append a missing or drop duplicate newlines. Run it in make format (--fix), make check_format and the pre-commit hook (staged text files only), and drop the separate check_newlines CI job.
The hook selected the staged files but read them from the working tree, so an unstaged fix could let a bad staged version pass and an unstaged change could block a good commit. Export the staged versions with git checkout-index into a temporary directory and run both checks there.
MaEtUgR
force-pushed
the
maetugr/fast-newline-check
branch
from
November 25, 2026 17:49
106e16e to
46fbd59
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Solved Problem
The check for missing or duplicate newlines at the end of files took ~85s, so it only ran as a separate CI job and not in
make format/make check_formator the pre-commit hook. Violations were only found in CI and had to be fixed by hand.Solution
check_newlines.shascheck_newlines.py: it reads only the last bytes of each file (~0.3s for the whole tree) and adds--fix.make format(fix),make check_format(check) and the pre-commit hook (staged text files only).check_newlinesCI job, sincecheck_formatnow covers it.make check_newlinesgot obsolete.Test coverage