-
Notifications
You must be signed in to change notification settings - Fork 2k
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 a file formatting script for pre-commit #3383
base: master
Are you sure you want to change the base?
Conversation
Why do we care about this?! |
I understand that this might come across as arbitrary, but I do appreciate these properties of a text file: Lemme just state, that I am glad none of those issues exist in the main source, but are limited to the examples right now. Otherwise, working in the main source could be a pain, because you constantly modify lines you didn't touch manually, because your editor takes care of deleting trailing spaces, and normalizing newlines. After all, still arbitrary, but I do like these standardization requirements. |
I'll go over them one by one:
However, the main motivation here is to avoid annoying formatting differences when bringing BGFX into an environment which enforces these rules. For another repo's formatting checks, it is fine to exclude third-party folders, but this also affects things like IDEs. I have my IDE configured to automatically fix these problems, so if I were to edit these files, I would end up with a bunch of unexpected diffs or I would need to temporarily disable this behavior. |
What I would prefer, is to run pre-commit check and then fail CI on bad formatting. I think it's undesirable that CI modifies files. |
@bkaradzic That's what it does. The CI will fail on bad formatting. It doesn't push any commits automatically. The feature where it runs locally when making a commit, modifying the user's local files, is opt-in, so it won't happen unless users choose that. |
.github/workflows/static_checks.yml
Outdated
fetch-depth: 2 | ||
|
||
- name: Style checks via pre-commit | ||
uses: pre-commit/[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this action is in maintenance-only mode and will not be accepting new features.
generally you want to use pre-commit.ci which is faster and has more features.
From here:
https://github.com/pre-commit/action?tab=readme-ov-file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submit fixes as separate PR first.
Also beware that double whitespace at the end of line in Markdown syntax for line break. |
I don't think it does. I see the action clearly calling out to the formatting script, which rewrites files if |
Yes, it does write the files. Then, because the CI runs in a temporary VM, the changes made by CI are immediately discarded. |
Then how does it signal that the formatting is not good? I don't see it returning exit code 1 in case the file is not correctly formatted. |
Pre-commit returns
If the files are all good already:
|
So now you can rebase this PR, and run checks on current repo state, and it should pass. bindings must not cause failure, since those auto generated files. |
b32a230
to
de53f0c
Compare
Added the |
I don't want to be annoying, but really, I don't see how that happens. When files are printed as FIXED, they are in the |
@mcourteaux The return code of |
Why |
Also I don't see this actually running https://github.com/bkaradzic/bgfx/actions/runs/12251664115/job/34176731561?pr=3383 |
@bkaradzic https://github.com/bkaradzic/bgfx/actions/runs/12251664128/job/34176730710?pr=3383 As for |
@aaronfranke Thanks! The last thing is:
Why not switch to pre-commit.ci since we already know this one is discontinued? |
I haven't used pre-commit.ci before. The GitHub Action still works fine, and it says it's in maintenance mode, which is not the same as discontinued. Also, pre-commit.ci has some features that I'm not sure are desired:
Anyway, if pre-commit.ci is desired, I think it is very easy to set up. Judging from their website, the only required setup is to enable it on their website, and then for this repo, delete the |
The reason why I'm bringing up this is because I don't want to have to deal with it in case maintainer decides to stop maintaining it. |
de53f0c
to
224b88e
Compare
I updated the PR to remove |
224b88e
to
1bcd6d4
Compare
Actually it's preferable to run automatically on PR. |
Yes, that's what the pre-commit.ci website lets you do, run it automatically on each PR. |
This PR adds a script for file formatting, set up to be used with pre-commit, and formats the files in this repo using the script.
pre-commit
viapip install pre-commit
. Thenpre-commit run --all-files
in the repo to run.pre-commit install
in the repo.static_checks.yml
file, the formatting script runs automatically on PRs via GitHub Actions CI checks.The script ensures text files do not have trailing spaces, do not have BOM, do not have carriage returns, and are terminated with one
\n
character to ensure text files are POSIX-compliant.I excluded
3rdparty/
,*.bin.h
, and*.ttf.h
files from formatting because3rdparty/
is third-party code and the headers are serialized text files which intentionally contain trailing spaces in the comments.