zlib-ng / minizip-ng

Fork of the popular zip manipulation library found in the zlib distribution.
Other
1.25k stars 434 forks source link

Adopting a clang-format #812

Closed Coeur closed 3 weeks ago

Coeur commented 3 weeks ago

This is my attempt to define rules which are matching the existing code style as close as possible. The rule definitions are available at: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

And you can run such command to apply the corrections:

clang-format -i **/*.{c,h}

The result isn't perfect, hence why it's just a draft. Although I'm clueless about how to do better.

--

We could independently cherry-pick the "good" fixes, like:

--

A viable alternative to clang-format would be Uncrustify which has more options: https://github.com/uncrustify/uncrustify/blob/master/documentation/htdocs/default.cfg

nmoinvaz commented 3 weeks ago

We use clang-format at work and start with the Google style.

What do you think of this:

---
BasedOnStyle: Google

AccessModifierOffset: -2
AlignConsecutiveMacros: AcrossEmptyLines
AlignOperands: DontAlign
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
ColumnLimit: 120
DerivePointerAlignment: false
IndentCaseLabels: false
IndentWidth: 4
InsertNewlineAtEOF: true
IndentPPDirectives: AfterHash
PointerAlignment: Right
PPIndentWidth: 2
SortIncludes: Never
Coeur commented 3 weeks ago

I've taken your proposal, but I kept the consecutive alignments, which is already in use and more readable.

nmoinvaz commented 3 weeks ago

I'm a fan of the alignment in structs but not alignment of variable declarations in functions and I don't think there is a way to do one and not the other with clang-format.

Coeur commented 3 weeks ago

OK, well, fine for me. I won't apply the clang-format changes myself: I'll let you do it, as you're the prime contributor of most affected lines of code.