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

Add clang-format style for the Apache Celix project #508

Closed
pnoltes opened this issue Apr 3, 2023 · 0 comments · Fixed by #544
Closed

Add clang-format style for the Apache Celix project #508

pnoltes opened this issue Apr 3, 2023 · 0 comments · Fixed by #544
Assignees
Labels
project/style Project wide coding guide style
Milestone

Comments

@pnoltes
Copy link
Contributor

pnoltes commented Apr 3, 2023

Currently Apache Celix has a mix of styles in its code base, ideally this should be align to a single and clear coding style.

A first step could be to introduce a clang-format style supported with some cmake / shell support to apply the clang-format.

For example, something like the following clang-format can be used as starting point:

#.clang-format
Language: Cpp
BasedOnStyle: Google
PointerAlignment: Left
DerivePointerAlignment: false
InsertBraces: true
AlignEscapedNewlines: Right
UseTab: Never
IndentWidth: 4

And a small shell command or cmake command can be created to apply the format to all Apache Celix c, h, cc and cpp files:

find bundles -iname "*.h" -exec clang-format -i {} \; 
find bundles -iname "*.c" -exec clang-format -i {} \; 
find bundles -iname "*.cc" -exec clang-format -i {} \; 
find bundles -iname "*.cpp" -exec clang-format -i {} \; 
find libs -iname "*.h" -exec clang-format -i {} \; 
find libs -iname "*.c" -exec clang-format -i {} \; 
find libs -iname "*.cc" -exec clang-format -i {} \; 
find libs -iname "*.cpp" -exec clang-format -i {} \; 

A shell command to only apply the format to git staged files can also be created, something like:

git diff --name-only --cached --diff-filter=d -- '*.h' | xargs -I {} clang-format -i {}
git diff --name-only --cached --diff-filter=d -- '*.c' | xargs -I {} clang-format -i {}
git diff --name-only --cached --diff-filter=d -- '*.cc' | xargs -I {} clang-format -i {}
git diff --name-only --cached --diff-filter=d -- '*.cpp' | xargs -I {} clang-format -i {}

The creating of the .clang-format file and the applying of format should be separate pull requests.

@pnoltes pnoltes added the project/style Project wide coding guide style label Apr 3, 2023
pnoltes added a commit that referenced this issue May 6, 2023
@pnoltes pnoltes added this to the 2.4.0 milestone May 6, 2023
@pnoltes pnoltes linked a pull request May 13, 2023 that will close this issue
@pnoltes pnoltes self-assigned this May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project/style Project wide coding guide style
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant