Skip to content
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

Move style checks to pre-commit #103

Merged
merged 4 commits into from
Mar 27, 2023
Merged

Conversation

ahans
Copy link
Contributor

@ahans ahans commented Mar 26, 2023

This is roughly what I had in mind. It allows you to maintain only .pre-commit-config.yaml for all style checks. The GH action runs it in CI, manually you can just pre-commit run [--all] and don't have to manage tools or anything manually. It's all taken care of by pre-commit.

Just putting this up to show what I was talking about. No need to merge this if you don't like it.

Also adds a check for cmake-format.
.github/workflows/pre-commit.yml Outdated Show resolved Hide resolved
.github/workflows/pre-commit.yml Show resolved Hide resolved
.github/workflows/pre-commit.yml Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v14.0.0'
rev: v16.0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

This I'd keep 14, just because is the default version of Ubuntu 22.04, it might break with newer versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, will revert it then.

.pre-commit-config.yaml Show resolved Hide resolved
cpp/kiss_icp/3rdparty/sophus/sophus.cmake Show resolved Hide resolved
@nachovizzo
Copy link
Collaborator

How does a failure case look like? Is it clear if the failure is on black or any formatter? Would you mind providing a screenshot or something similar

@nachovizzo nachovizzo marked this pull request as ready for review March 27, 2023 19:16
@nachovizzo
Copy link
Collaborator

@ahans sorry I just merged main again into this branch. I keep accidentally pushing the damn button 😂. I still can't believe I can merge stuff into your private repo 😱. Sorry I did it twice 😔

@ahans
Copy link
Contributor Author

ahans commented Mar 27, 2023

How does a failure case look like? Is it clear if the failure is on black or any formatter? Would you mind providing a screenshot or something similar

Here's an example where I messed up the formatting of some Python file:

image

It checks and fixes in one go, so next time I run it everything would be green again. That's something I disliked at first. I would have preferred some "check only" mode. But having used it for a while it's actually not an issue at all in my workflow. For most file types I have some "format on change" enabled anyways, but occasionally it does happen that something does not get formatted properly. Then I see that the "pre-commit" stage in CI is red and I want to run "fix" locally anyways. Really can't think of a reason why I would want a "check" only. It would always be followed by a "fix" anyways.

@ahans
Copy link
Contributor Author

ahans commented Mar 27, 2023

@ahans sorry I just merged main again into this branch. I keep accidentally pushing the damn button joy. I still can't believe I can merge stuff into your private repo scream. Sorry I did it twice pensive

No worries, I left the option checked that allows you (or any other maintainer) to make edits. I think it's fairly reasonable. Otherwise you would have to rely on me for everything (or copy my branch into your own and open up another PR).

@nachovizzo
Copy link
Collaborator

@ahans sorry I just merged main again into this branch. I keep accidentally pushing the damn button joy. I still can't believe I can merge stuff into your private repo scream. Sorry I did it twice pensive

No worries, I left the option checked that allows you (or any other maintainer) to make edits. I think it's fairly reasonable. Otherwise you would have to rely on me for everything (or copy my branch into your own and open up another PR).

Deswegen! Now I get it. Much easier to work like this. Thanks!

@nachovizzo
Copy link
Collaborator

How does a failure case look like? Is it clear if the failure is on black or any formatter? Would you mind providing a screenshot or something similar

Here's an example where I messed up the formatting of some Python file:

image

It checks and fixes in one go, so next time I run it everything would be green again. That's something I disliked at first. I would have preferred some "check only" mode. But having used it for a while it's actually not an issue at all in my workflow. For most file types I have some "format on change" enabled anyways, but occasionally it does happen that something does not get formatted properly. Then I see that the "pre-commit" stage in CI is red and I want to run "fix" locally anyways. Really can't think of a reason why I would want a "check" only. It would always be followed by a "fix" anyways.

If you do git commit locally, it will stop without changing the code. Assuming you've installed the hook pre-commit install Which I find terrific.

@nachovizzo
Copy link
Collaborator

I think is ready to merge @ahans . If you agree let me know because I need to change some config on the GH side

@ahans
Copy link
Contributor Author

ahans commented Mar 27, 2023

If you do git commit locally, it will stop without changing the code. Assuming you've installed the hook pre-commit install Which I find terrific.

I've never run pre-commit install. Been always a bit skeptical about git hooks. Maybe I should try it out! ;-)

I think is ready to merge @ahans . If you agree let me know because I need to change some config on the GH side

I reverted the clang-format version now and also changed the config for when to run the workflow to match the other ones. So yes, from my end I would say it's ready.

@ahans
Copy link
Contributor Author

ahans commented Mar 27, 2023

I also rebased onto latest main and dropped your merge commit. Just make sure to squash the two fixups into the one commit. But I think that happens automatically anyway.

@nachovizzo
Copy link
Collaborator

I also rebased onto latest main and dropped your merge commit. Just make sure to squash the two fixups into the one commit. But I think that happens automatically anyway.

yup, cuz I squash and merge always anyways

@nachovizzo nachovizzo merged commit f1e8a84 into PRBonn:main Mar 27, 2023
9 checks passed
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.

None yet

2 participants