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

Adopting a clang-format #812

Merged
merged 3 commits into from
Nov 1, 2024
Merged

Conversation

Coeur
Copy link
Contributor

@Coeur Coeur commented Nov 1, 2024

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:

  • mz_os_posix.c lines 274-278
  • mz_strm.c line 379
  • mz_strm.h line 102
  • mz_strm_buf.c line 57
  • mz_strm_mem.c line 214
  • mz_strm_pkcrypt.c line 165
  • mz_zip.c line 2783

--

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
Copy link
Member

nmoinvaz commented Nov 1, 2024

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 Coeur marked this pull request as ready for review November 1, 2024 22:19
@Coeur
Copy link
Contributor Author

Coeur commented Nov 1, 2024

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

@nmoinvaz
Copy link
Member

nmoinvaz commented Nov 1, 2024

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
Copy link
Contributor Author

Coeur commented Nov 1, 2024

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.

@nmoinvaz nmoinvaz enabled auto-merge (rebase) November 1, 2024 23:10
@nmoinvaz nmoinvaz merged commit d164b07 into zlib-ng:develop Nov 1, 2024
28 checks passed
@Coeur Coeur deleted the coeur/clang-format branch November 1, 2024 23:17
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.

2 participants