ci: add workflow to lint whitespace#205
Conversation
| exit_status=0 | ||
|
|
||
| # Check that each git-tracked non-binary file has no trailing whitespace. | ||
| trailing_whitespace="$(git grep --cached -I '[[:blank:]]$')" |
There was a problem hiding this comment.
This repo doesn't have any binary files, but it's generally important to include the -I option - otherwise the script can exit with an error for "trailing whitespace" in a binary file.
There is at least one action in the GitHub Marketplace that doesn't handle that correctly.
Docs for git grep: https://git-scm.com/docs/git-grep
| if [ "$(tail -c 1 "${file}" | wc -l)" -eq 0 ]; then | ||
| echo "No newline at end of file: ${file}" | ||
| exit_status=1 |
There was a problem hiding this comment.
Deliberately allows an empty file.
That doesn't matter for this repo, but we might want that feature if this script ends up running in a bunch of repos.
See #204 (comment) for context on why this might not yet be what we want. |
|
If removing one of the final newlines there does indeed affect the generated file, can we have one final newline and tweak the file generation process instead? Relying on a double final newline seems a bit fragile, since so many people configure their editor to trim whitespace. And such a change is easy to miss, if a reviewer doesn't know/remember in a year's time that this file needs a double final newline. Otherwise, I could allow-list the problematic file. But it would be nice to keep the script generic, to minimize the diff if we wanted to use it in several repos. (Alternative route that I'm trying to avoid for now: create a whitespace linting action with a customizable ignore list). |
That would be best. @SaschaMann knows the generation process best. |
The file generation process is file-agnostic and for some files it's required to append the appends without an empty line inbetween. We could add a special case for That said, if you both agree that we should special-case the file, I'm happy to go along. We'd have to add it here: org-wide-files/scripts/apply-track-config.jl Lines 42 to 47 in 8b1b6e4 |
The obvious solution for this would be to add |
Oh. Please remind me: what are our appendable files right now? And do we plan to have more?
I agree.
By "reviewer" I meant "reviewer in the
We also can't add a comment for it in the file itself like "the below double newline is deliberate, and must not be converted to a single final newline" (since I presume that comment would end up in the downstream files). Possible hack: amend this PR to add a special case for that file alone - require it to have exactly two final newlines. Is that the least bad option so far? |
You can find them in Lines 1 to 5 in 8b1b6e4
Ah sorry, I misunderstood. I thought you meant downstream repos. Codeowners would not really protect us in that case. A warning might help use realise it but I'm sure I'd ignore it after seeing it twice.
I'd be fine with either of those. I don't think it's a problem if a comment would make it downstream, as long as we add a short explanation why it can be ignored by most people. Having a custom check for it seems fine, too. |
|
We could also add it as an option to |
I see. Thanks. Aside, out of curiosity: what's the reasoning for |
The Julia track has an addendum as a precaution because the behaviour described in it is unfortunately something that actually occurs (even if I'm not aware of it happening on Exercism yet): https://github.com/exercism/julia/blob/main/CODE_OF_CONDUCT.md#addendum Ideally this should live on the site somewhere but back then Jeremy decided it should go in the track repo for now. |
This would be my preference |
|
Rebased on |
|
Okay, the other whitespace PR is merged, so a rebase should fix CI. |
|
Rebased on Can we trim it by triggering a PR in this repo, or just do it manually? |
I think manually would be fine. |
Created #216 |
|
Merged. |
Enforce that every git-tracked, non-empty text file: - has no trailing whitespace - ends in exactly one newline The script and workflow are taken from the configlet repo [1]. [1] exercism/configlet@b5908cde0901
|
Now that we have everything merged, we could trigger the sync workflow for the select few repositories that held off on merging due to the trailing whitespace. IIRC, they included |
|
Also I don't mind what we do for repos that aren't the 5 mentioned above, but there is at least also exercism/tooling-orchestrator#40 |
Enforce that every git-tracked, non-empty text file:
The script and workflow are taken from the configlet repo.
The script output and factoring can be improved, but it does at least exit non-zero when it's supposed to.
Follow-up from #204