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

Clang format #416

Closed
wants to merge 2 commits into from
Closed

Clang format #416

wants to merge 2 commits into from

Conversation

rpavlik
Copy link
Contributor

@rpavlik rpavlik commented May 20, 2019

Follow-up from #414 - this is my best attempt at getting one using my typical approach of populating with the explicitly-stated preferences, then iterating through "apply to file" and "correct config causing most apparent spurious changes". There are substantial inconsistencies that mean that whatever decision I make for some of these, it will introduce changes if it were applied all-over, but since that's not on the table anyway, this should be at least something. There were also a few where clang-format couldn't quite express the subtle distinctions I saw in the existing formatting, so I picked the overall less-intrusive one.

The file is commented to help you modify it as desired.

I also added a clang-tidy config file because the contributing doc says "braces around all the things" and that's not something clang-format can do (for some reason), you have to use clang-tidy. Doing so exposed me to the reality that it's a guideline very rarely followed - but if you'd like to enforce it, that clang-tidy file is a good way to do so. Something like this, assuming you have a build tree in build/...

find src test \(-name "*.h" -o -name "*.cpp" \) -print0 | xargs --null clang-tidy-7 -p build -fix 
git add -u
git clang-format

(Can't use run-clang-tidy here because it will result in things getting multiple sets of brackets, etc. Sadly must do it single-threaded like this, or have it save out the fixes and manually choose the ones to apply.)

This would add a lot of noise to the history, etc. if applied all-over now.
Use git clang-tidy to apply it solely to your changes.
This is how you enforce the "wrap all blocks with {}, even one-liners".
Use something like this (-fix is optional):
  > run-clang-tidy-7 -p build -fix src/*.cpp src/*.h
@whitequark
Copy link
Contributor

whitequark commented May 20, 2019

I also added a clang-tidy config file because the contributing doc says "braces around all the things" and that's not something clang-format can do (for some reason), you have to use clang-tidy. Doing so exposed me to the reality that it's a guideline very rarely followed - but if you'd like to enforce it, that clang-tidy file is a good way to do so.

Thanks for investigating this. I don't think it's a very important guideline, and I appear to have significantly overestimated how often that's the case when writing CONTRIBUTING.md. So, let's just drop it instead, in CONTRIBUTING.md as well, as if I understand you correctly, that means we don't really need clang-tidy anymore without it (is that right?)

@rpavlik
Copy link
Contributor Author

rpavlik commented May 22, 2019

Well, certainly not to enforce code style. It's a decent idea to run from time to time as a linter.

@whitequark
Copy link
Contributor

I pushed the clang-format change as ffef006 and updated CONTRIBUTING.md, thank you very much. I might look into clang-tidy some time later but for now let's omit it.

@whitequark whitequark closed this May 23, 2019
@rpavlik
Copy link
Contributor Author

rpavlik commented May 23, 2019

Thanks!

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