Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for missing or duplicate newlines at the end of files #23166

Merged
merged 3 commits into from
Jul 19, 2024

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented May 22, 2024

Solved Problem

When checking changes I realized people do commit missing or duplicate newlines every now and then. This seems like a non-issue and only leads to problems later on when some tooling doesn't work because the files are not POSIX compliant or whitespace checks fail in the middle of a merge. Manual passes like #22476 end up not enforcing the rules.

Solution

  • Add an automatic check for one single newline at the end of every file that is checked into the repository.

Changelog Entry

Style: Automate enforcing one single newline at the end of each file

Alternatives

Ideally, this would also run through with make format but I don't add it because I feel it adds too much delay and hence prolongs the pre-commit hook. Better to have it ran in CI than not at all but maybe someone knows how to make the check more efficient such that the runtime is insignificant during commits.

Test coverage

I tested locally that it triggers with:

  • All the existing missing newlines and duplicate newlines
  • Just one of the two checks
  • Just one duplicate newline in a file

Context

Inspiration:

  1. https://stackoverflow.com/a/54348931
  2. https://stackoverflow.com/a/31829703/6326048

@MaEtUgR MaEtUgR added Admin: Cleanup (housekeeping) 🧹 Tools Sub-tools used within PX4 ecosystem (scripts, etc) labels May 22, 2024
@MaEtUgR MaEtUgR requested a review from dagar May 22, 2024 12:43
@MaEtUgR MaEtUgR self-assigned this May 22, 2024
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 22, 2024

@MaEtUgR MaEtUgR marked this pull request as ready for review May 22, 2024 13:13
@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 22, 2024

The check passes after the fixes
image

@MaEtUgR
Copy link
Member Author

MaEtUgR commented May 22, 2024

Hmm, e.g. SITL offboard, px4_fmu-v6xrt, MAVROS rover mission CI is also failing on main. There are quite some to look through 👀

@MaEtUgR MaEtUgR force-pushed the maetugr/fix-newlines branch from de5f9b1 to 4c6f0fe Compare May 28, 2024 13:47
@github-actions github-actions bot added the stale label Jun 28, 2024
@MaEtUgR MaEtUgR force-pushed the maetugr/fix-newlines branch from 4c6f0fe to 2867100 Compare July 17, 2024 15:37
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jul 17, 2024

I rebased the pr, this would have caught more newline issues since I opened the pr:
image

e.g. https://github.com/PX4/PX4-Autopilot/pull/22904/files#r1681278804

@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-sync-q-a-july-17-2024/39749/1

@MaEtUgR MaEtUgR merged commit f2bca92 into main Jul 19, 2024
93 of 95 checks passed
@MaEtUgR MaEtUgR deleted the maetugr/fix-newlines branch July 19, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin: Cleanup (housekeeping) 🧹 stale Tools Sub-tools used within PX4 ecosystem (scripts, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants