Skip to content

chore: Update clang-format and prettier with pre-commit#5709

Merged
bthomee merged 16 commits intodevelopfrom
bthomee/format
Aug 22, 2025
Merged

chore: Update clang-format and prettier with pre-commit#5709
bthomee merged 16 commits intodevelopfrom
bthomee/format

Conversation

@bthomee
Copy link
Collaborator

@bthomee bthomee commented Aug 21, 2025

High Level Overview of Change

The change updates how clang-format is called in CI and locally, and adds prettier to the pre-commit hook. Proto files are now also formatted, while external files are excluded.

Context of Change

This PR was inspired by #5665, which enabled prettier as a pre-commit hook, and updated the clang-format to move some common stanzas out of language-specific sections. The current changes do the same, but removes Javascript as a language (since we have no such files) and Json (since Prettier formats them), while adding Proto (since we do have such files).

Finally, there is no hosted pre-commit hook for prettier anymore, so installing it locally is therefore the most straightforward option. For consistency, this PR also makes the change to clang-format. This PR provides instructions on how to install the hooks locally, including to ensure their versions match what is actually used in CI.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

@bthomee bthomee requested a review from Bronek August 21, 2025 13:17
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.7%. Comparing base (fb89213) to head (88add0e).
⚠️ Report is 12 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5709     +/-   ##
=========================================
- Coverage     78.8%   78.7%   -0.1%     
=========================================
  Files          814     814             
  Lines        71305   71639    +334     
  Branches      8351    8446     +95     
=========================================
+ Hits         56196   56354    +158     
- Misses       15109   15285    +176     

see 202 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Then, run the following command to install the git hook scripts:
# - `pre-commit install`
# You can run all configured hooks against all files with:
# - `pre-commit run --all-files`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this command:

pre-commit run --from-ref develop --to-ref HEAD

--all-files usually reformats the external files, which we don't want

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I see you fixed that, it'll still be much more efficient

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the comment in this file to match the above command? Usually the --all-files takes much longer and isn't necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments say:

# You can run all configured hooks against all files with:
# - `pre-commit run --all-files`
# To manually run a specific hook, use:
# - `pre-commit run <hook_id> --all-files`
# To run the hooks against only the files changed in the current commit, use:
# - `pre-commit run`

I don't see what's wrong - it specifically has a comment about the command that does not include --all-files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're referring to the --from-ref and --to-ref flags, I added commits to the PR containing them and they failed with fatal: ambiguous argument 'develop..HEAD': unknown revision or path not in the working tree., so I don't want to include a command that may or may not work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that was some CI issue rather than a problem with the CLI. But if you're not sure, we can leave it out.

@Bronek
Copy link
Collaborator

Bronek commented Aug 21, 2025

I am little worried about missing the commit which changes .proto from .git-blame-ignore-revs. I also think that we should add the merge commit of #5657 to the same file.

The problem with updating this file is that it requires non-linear history if anything else is being changed in the same PR. So in order to do it we should either allow non-linear history, or move only formatting changes from this PR (i.e. no workflow or formatting configuration changes) to a different PR, and then add its merge commit (and that of #5657 ) to .git-blame-ignore-revs

@bthomee
Copy link
Collaborator Author

bthomee commented Aug 21, 2025

I am little worried about missing the commit which changes .proto from .git-blame-ignore-revs. I also think that we should add the merge commit of #5657 to the same file.

The problem with updating this file is that it requires non-linear history if anything else is being changed in the same PR. So in order to do it we should either allow non-linear history, or move only formatting changes from this PR (i.e. no workflow or formatting configuration changes) to a different PR, and then add its merge commit (and that of #5657 ) to .git-blame-ignore-revs

Yes, I can move the formatting changes to a separate PR, although we will have to ignore the clang-formatting error it will generate as .clang-format currently doesn't support Proto files and will complain loudly if it sees one.

@mvadari
Copy link
Collaborator

mvadari commented Aug 21, 2025

although we will have to ignore the clang-formatting error it will generate as .clang-format currently doesn't support Proto files and will complain loudly if it sees one.

This could probably also be resolved by manually pushing 2 commits from one PR (one that actually does the changes, one that changes the configuration).

@bthomee
Copy link
Collaborator Author

bthomee commented Aug 21, 2025

although we will have to ignore the clang-formatting error it will generate as .clang-format currently doesn't support Proto files and will complain loudly if it sees one.

This could probably also be resolved by manually pushing 2 commits from one PR (one that actually does the changes, one that changes the configuration).

I already created #5711. But it does have some clang-format config changes to make it happy.

@bthomee
Copy link
Collaborator Author

bthomee commented Aug 21, 2025

Also, @Bronek, the commit from #5657 has already been added to the .git-blame-ignore-revs file, see #5675. Once #5711 gets merged, I can add its squashed commit to that file too.

@Bronek
Copy link
Collaborator

Bronek commented Aug 21, 2025

I am happy to see the progress made here, esp with #5711 and XRPLF/ci#46

@bthomee
Copy link
Collaborator Author

bthomee commented Aug 21, 2025

Updates:

  • The .* in the .prettierignore file essentially caused everything to be ignored, rather than files starting with a dot. After removing it, the CI YAML were re-formatted and there were no issues with dot-files anyway.
    • @Bronek Would you like me to pull those changes into a separate PR, and then add it to the .git-blame-ignore-revs file? I think it's not really needed because the changes are relatively minor and, with the CI refactor recently completed, should not result in confusion - I'm to blame anyway for everything related to the new CI pipelines.
  • I added the commit from chore: Reverts formatting changes to external files, adds formatting changes to proto files #5711 to .git-blame-ignore-revs in this PR.

@Bronek
Copy link
Collaborator

Bronek commented Aug 22, 2025

Updates:

  • The .* in the .prettierignore file essentially caused everything to be ignored, rather than files starting with a dot. After removing it, the CI YAML were re-formatted and there were no issues with dot-files anyway.

    • @Bronek Would you like me to pull those changes into a separate PR, and then add it to the .git-blame-ignore-revs file? I think it's not really needed because the changes are relatively minor and, with the CI refactor recently completed, should not result in confusion - I'm to blame anyway for everything related to the new CI pipelines.
  • I added the commit from chore: Reverts formatting changes to external files, adds formatting changes to proto files #5711 to .git-blame-ignore-revs in this PR.

If it's minor then I think that's fine to keep in this PR. I only wanted the separate PR #5711 because the formatting literally rewrote all .proto files (and also to revert the external changes). I do not think anything so drastic would happen again.

@bthomee bthomee mentioned this pull request Aug 22, 2025
9 tasks
@mvadari
Copy link
Collaborator

mvadari commented Aug 22, 2025

While we're at it, we may want to consider adding some of these to the list: https://github.com/pre-commit/pre-commit-hooks

@Bronek
Copy link
Collaborator

Bronek commented Aug 22, 2025

While we're at it, we may want to consider adding some of these to the list: https://github.com/pre-commit/pre-commit-hooks

@mvadari this is being prepared now: trailing-whitespace end-of-file mixed-line-ending check-merge-conflict

@mvadari
Copy link
Collaborator

mvadari commented Aug 22, 2025

While we're at it, we may want to consider adding some of these to the list: https://github.com/pre-commit/pre-commit-hooks

@mvadari this is being prepared now: trailing-whitespace end-of-file mixed-line-ending check-merge-conflict

I would also recommend check-json given the handful of JSON files in this repo.

@mvadari
Copy link
Collaborator

mvadari commented Aug 22, 2025

I was also looking at this: https://github.com/streetsidesoftware/cspell-cli

Which would cut down on the number of random PRs that just fix random typos

@Bronek
Copy link
Collaborator

Bronek commented Aug 22, 2025

check-json

@bthomee I tested that this will work

      - id: check-json
        name: check-json
        entry: check-json
        language: system
        types: [json]

... however I do not see how that is useful given the rewrite in prettier which seems to be doing more that check-json

@Bronek
Copy link
Collaborator

Bronek commented Aug 22, 2025

I was also looking at this: https://github.com/streetsidesoftware/cspell-cli

Which would cut down on the number of random PRs that just fix random typos

I would wait with this for next occasion, since I guess there would be fair amount of experimentation and churn involved. Given that there are likely to be many typoes in the codebase. 🙃

@mvadari
Copy link
Collaborator

mvadari commented Aug 22, 2025

I was also looking at this: https://github.com/streetsidesoftware/cspell-cli

Which would cut down on the number of random PRs that just fix random typos

I would wait with this for next occasion, since I guess there would be fair amount of experimentation and churn involved. Given that there are likely to be many typoes in the codebase. 🙃

Yeah, that's fair. Do you mind if I experiment with this in a separate draft PR?

@bthomee
Copy link
Collaborator Author

bthomee commented Aug 22, 2025

check-json

@bthomee I tested that this will work

      - id: check-json
        name: check-json
        entry: check-json
        language: system
        types: [json]

... however I do not see how that is useful given the rewrite in prettier which seems to be doing more that check-json

Prettier already rewrites JSON files. I modified some of the strategy matrix JSON files and then tried to get clang-format to do anything, but it wouldn't fix them, which I found odd since I earlier had to add:

Language: Json
IndentWidth: 2

to get it to stop complain about seeing a file in a format it didn't support. But since adding files: '\.(cpp|hpp|h|ipp|proto)$' it no longer complains, so I'll remove this block again.

@bthomee bthomee requested review from Bronek and mvadari August 22, 2025 14:47
@bthomee bthomee enabled auto-merge (squash) August 22, 2025 16:42
@bthomee bthomee merged commit c14ce95 into develop Aug 22, 2025
44 of 45 checks passed
@bthomee bthomee deleted the bthomee/format branch August 22, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants