Proposal: Replace code-formatter-helper with pre-commit#5054
Conversation
first time pre-commit with `pre-commit run -a`
Running pre-commit clang-format on all files throws: `Configuration file(s) do(es) not support Json`
There was a problem hiding this comment.
If you delete this file then it breaks my workflow. As I run it prior to committing anything.
ryanh@ryanh-TR5000:/mnt/Work/Work/work/FEXNew$ cat clang_format.sh
#!/bin/sh
sh -c "CLANG_FORMAT=clang-format-19 ./Scripts/reformat.sh . > /dev/null 2>&1"
Ensuring the user is formatting their code correctly and leaving the onus on them is desired.
There was a problem hiding this comment.
I've expected that this would happen.
There would be 2 possible solutions:
- You could change your
clang_format.shto run pre-commit instead ofreformat.shand the behaviour would be the same (in addition to also run Python formatting if required):
pre-commit(only formats changed files)pre-commit run -a(for all files)
- Install pre-commit (
pre-commit install), and every time before you commit, pre-commit and therefore clang-format are run. This is the reason pre-commit exists: not to have to run these kinds of scripts manually.
But it would be understandable if this were to change too much in trusted workflows.
That's not going to fly, we're never going to use GitHub's runners. |
Understood. I guess it would be easy to switch from GitHub runners to the self-hosted ones. Pre-commit only requires Python and installs the rest itself. Therefore, all the Python environment setup from the code-formatter-helper-workflow could be avoided. |
|
|
||
| jobs: | ||
| pre-commit: | ||
| runs-on: ubuntu-latest |
There was a problem hiding this comment.
Not sure if just changing this to:
runs-on: [self-hosted, X64]
would be enough to have it working on the self-hosted solution. I'm not familiar with the setup.
|
@pmatos should probably look at this because I don't know enough about the code formatting stuff to know if this is worth using. |
|
I must say that besides adding more dependencies on the side of FEX, I am not sure what advantages this brings. If you push failing to format, it's detected by CI. And since you can't force people to use pre-commit, you need that workflow anyway. It doesn't seem this is going to ease things in any way. Am I missing something here? |
I wouldn't call it addding more dependencies, rather replacing dependencies and reducing own maintenance burden.
Agree, but when I see a project using pre-commit, I can quickly check if this covers formatting too. I didn't know that FEX had a custom helper script, since the Scripts directory is full of other scripts too and might be overlooked. For me, I see the adoption as the only true problem/change with adapting pre-commit, and would say the pros outweigh the cons. Cons:
Pros
|
|
We appreciate the effort and interest, but we're happy with the current setup. Also please consider revisiting your use of LLMs, since many would consider throwing in AI slop as rude and unhelpful (even more so if it isn't disclosed). (others, feel free to re-open if there's a desire to integrate this) |
Okay, wow no idea where this accusation comes from now ... But hey, I've got the drift how stuff works here .. Thanks Rant mode off |
This "Pro & Con" format with bullet lists is a fairly typical style of LLM output, particularly with the boldface summary in each bullet item. You see people post such output in an attempt to be helpful, which as a maintainer is cumbersome and wasteful of our time. Apologies if I got unlucky by calling out the one comment where no LLM was actually used. LLM or not though, the current setup works for us regardless and we have no desire to change it. |
I’d like to propose migrating from
code-formatter-helperto a well-known solution: pre-commit.Thank you in advance for checking out the change. Just tell me if you need more information to open a discussion or if this is not something you are interested in. I'd love to hear some feedback ❤️
./Scripts/reformat.shwith:pre-commitfor only changed filespre-commit run -afor all existing filesWhile this is a bigger change for developers, it eliminates the need to manage and fix
code-formatter-helper.The CI is unchanged, except that it now runs on GitHub servers instead of self-hosted runners, for now.
Example outputs
To show some example outputs, I just misformatted something and ran pre-commit/tried to commit.
C++:
Python:
Additionally, it would be possible to, instead of just silently reformatting the files, show the exact line (dry-run):
clang-format.............................................................Failed - hook id: clang-format - exit code: 1 Source/Tools/LinuxEmulation/Thunks.h:14:8: error: code should be clang-formatted [-Wclang-format-violations] public: ^ isort....................................................................Passed black....................................................................Passed