Skip to content

build(style): fast newline check with --fix as part of make format - #30028

Open
MaEtUgR wants to merge 2 commits into
mainfrom
maetugr/fast-newline-check
Open

MaEtUgR wants to merge 2 commits into
mainfrom
maetugr/fast-newline-check

Conversation

@MaEtUgR

@MaEtUgR MaEtUgR commented Nov 25, 2026

Copy link
Copy Markdown
Member

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_format or the pre-commit hook. Violations were only found in CI and had to be fixed by hand.

Solution

  • Rewrite check_newlines.sh as check_newlines.py: it reads only the last bytes of each file (~0.3s for the whole tree) and adds --fix.
  • Run it in make format (fix), make check_format (check) and the pre-commit hook (staged text files only).
  • Remove the separate check_newlines CI job, since check_format now covers it. make check_newlines got obsolete.

Test coverage

  • The whole tree passes.
  • Missing, duplicate, CRLF and newline-only file endings are detected and fixed correctly.
  • The pre-commit hook rejects a broken staged file and ignores staged binaries.

@MaEtUgR MaEtUgR self-assigned this Nov 25, 2026
@github-actions github-actions Bot added kind:chore Maintenance work that keeps the project healthy. scope:tools Scripts, developer tools, packaging, or setup helpers. labels Nov 25, 2026
@MaEtUgR
MaEtUgR requested a balanced review from Copilot November 25, 2026 15:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread Tools/astyle/check_newlines.py Resolved
Comment thread Tools/astyle/pre-commit Resolved
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
MaEtUgR force-pushed the maetugr/fast-newline-check branch from 106e16e to 46fbd59 Compare November 25, 2026 17:49
@MaEtUgR
MaEtUgR requested a balanced review from Copilot November 25, 2026 23:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The hook excludes renamed files from export and newline checks, allowing a staged rename that removes the final newline to pass validation.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread Tools/astyle/pre-commit Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:chore Maintenance work that keeps the project healthy. scope:tools Scripts, developer tools, packaging, or setup helpers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants