Open hiroMTB opened 7 months ago
hello @hiroMTB!
since last year there is a .clang-format file in the repository. it follows pretty well the previous formatting, with a little bit more spaces around some markers.
about auto-formatting, there was sort of a "soft decision" made not to blanket the git history with a "clang-format" white-space commits, but to reformat when a file needs a change (the commits being squashed, it can be performed as a separate commit in for the PR review, but it will no show up in the final history/blame (and the whitespace exclusion in git works relatively well to not register as "changes")).
also sometimes macros and "nicely indented data tables" are better to exclude from clang-format, which means a manual review is always preferable after a reformat.
there are different ways to apply the formatting; the git clang-format
is one, and I use this automator approach on Xcode.
Wow! Thank you for your detailed explanation. I will try clang-format and automator.
if we rely on manual review, probably we will keep seeing indent errors for future. But I can understand your point too. Maybe we can arrange "format party" every monthš¤£
it would be great to format the entire core in one PR, but this has the potential to break a lot of PRs. I think it is ok if it is right before the next release
oh! I see, good point! Btw, how do the other big C++ projects manage this issue? Maintainers do it manually?
well when I looked last year nothing clear was found, and I subscribed here https://github.com/NVIDIA/stdexec/issues/905 thinking that when @ericniebler figures it out we can evaluate their choices...
clang-format is definitely the way.
However it does not explicitly support A Style. We can override this by adding a .clang-format file in root directory with some custom settings to make it more A Style:
---
Language: Cpp
# Based on Google style as a starting point
BasedOnStyle: Google
# Indentation width
IndentWidth: 4
# Use spaces instead of tabs for indentation
UseTab: Never
# Brace wrapping
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
# Column limit
ColumnLimit: 80
# Pointer and reference alignment
PointerAlignment: Left
# Includes sorting
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^".*'
Priority: 0
IncludeBlocks: Regroup
# Control the alignment of assignments
AlignConsecutiveAssignments: true
# Control the alignment of declarations
AlignConsecutiveDeclarations: true
I found quite lots of indent errors like below. Those are only part of it. Is there a way to auto-formating code before PR or each commit?
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/3d/of3dPrimitives.cpp#L111-L113
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/3d/of3dPrimitives.cpp#L170-L179
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/app/ofAppGlutWindow.cpp#L30-L46
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/app/ofAppGLFWWindow.cpp#L76-L81
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/app/ofAppGLFWWindow.cpp#L383-L389
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/app/ofAppNoWindow.cpp#L32-L41
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/app/ofAppNoWindow.h#L37-L43
https://github.com/openframeworks/openFrameworks/blob/2b8cab27d5b2dfc85be6cffc5119dce3d609f79c/libs/openFrameworks/graphics/of3dGraphics.cpp#L13-L18