-
Notifications
You must be signed in to change notification settings - Fork 261
Add GitHub action to clear whitespace #5145
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
Conversation
Eh eh. I have an elisp script for cleaning things up, if you need help 😅 |
|
@giordano I see that the action just checks but not actually clears the whitespaces. |
|
You literally just answered before I asked.. |
|
Feel free to share the script or just run it on the branch? |
|
can we just run this script automatically? |
|
Yeah... That'd be ideal. Like as part of the GitHub Action? |
|
For the record the code I used is (dolist (file (directory-files-recursively "/path/to/Oceananigans" "\\.\\(jl\\|md\\|sh\\)$"))
(when (file-regular-p file)
(with-temp-buffer
(insert-file-contents file)
;; Force LF line ending
(set-buffer-file-coding-system 'unix)
;; Add final newline in case it's missing. If it's
;; extra it'll be cleaned up later.
(goto-char (point-max))
(insert "\n")
;; Replace non-breaking spaces
(save-excursion
(goto-char (point-min))
(while (search-forward " " nil t)
(replace-match " " nil t)))
;; Untabify
(untabify (point-min) (point-max))
;; Clean up all trailing whitespaces
(delete-trailing-whitespace)
(write-region (point-min) (point-max) file))))but not sure how to use it here, installing Emacs on the CI job is doable ( |
|
Let's leave it as is for now: |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5145 +/- ##
=======================================
Coverage 73.19% 73.19%
=======================================
Files 390 390
Lines 21847 21847
=======================================
Hits 15991 15991
Misses 5856 5856
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
But the action will block PRs that violate the whitespace criterion. Without the script, it's not that easy to clear this failing test? |
It's technically non-blocking, but will have a red mark on PRs, yes.
I'd argue it takes active effort (or an LLM, they're somehow bad at the basic code formatting) to leave trailing whitespaces in hundreds of lines in a single PR. Most PRs will be clean, or have 1-2 lines which are easy to fix (the inline comments in the files changed tab will make it easy to see them). I think a more effective approach is to a pre-commit hook, which resolves the most egregious issues at commit time for people who enable it. People who don't...will have to deal with the extra whitespaces themselves. |
Maybe I am the only one sloppy enough to have the issue. I think that I matter though 🥺 I'm not sure LLMs generate it. I sometimes get whitespace when I edit code through the github editor. I agree it is not a huge slowdown, but it is a slowdown nonetheless, especially if CI is expensive, it could delay merging by eg 90 min (2x the waiting time for CI) |
|
I can work on a simple bash-based pre-commit hook to resolve the main issues (trailing white spaces on every line, non-breaking spaces, etc., those are easy to deal with |
Every time I used Cursor I had to remove dozens of stupid trailing whitespaces, especially in blocks separated by blank lines, like some_code(x)
# <-- This is a blank line, but Claude/Cursor _loves_ adding spaces here
some_other_code(y)Just by looking at the most recent failures of this check in Julia I quickly found https://github.com/JuliaLang/julia/actions/runs/20860074414/job/59937155255?pr=60621, which points to JuliaLang/julia@3ed531c#diff-5d5447f22a990c432721925eba28246028db844bd834cb358235c865f0558659, which, guess what, was created by Claude. |
Could we add an instruction in AGENTS.md about that? |
|
I think it would be easy to add an instruction to remove trailing whitespace to AGENTS.md. We could also put the elisp script itself in the AGENTS.md. |
* refs/remotes/origin/FPivot: Add GitHub action to clear whitespace (CliMA#5145)
|
I agree that the whitespace action is kind of annoying, I seem to always add whitespace but cannot find it! Would it be possible to implement a bot that commits to the PR the whitespace change when called (maybe through comments in the PR)? Or would it be very difficult to implement? |
|
No, the script I shared above is elisp, you need Emacs to run it. I'll try to prepare a simple pre-commit hook to clean up the main things, I believe that's more useful than a workflow (again, I don't think it's nice for workflows to modify source code in PRs, it also feels like a potential security issue, and I suspect it wouldn't work for PRs from forks) |
|
@glwagner @simonesilvestri BTW, if you use VS Code or derivatives (which includes Cursor) you can also make your editor automatically trim trailing whitespace, see https://stackoverflow.com/a/53663494 or https://stackoverflow.com/a/30884298. That's basically what I do as well, just with a different editor. |
following the steps of NumericalEarth/Breeze.jl#406