Hercules icon indicating copy to clipboard operation
Hercules copied to clipboard

Code formatting with clang-format

Open ghost opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

We are all aware of how hercules source code doesn't follow a consistent code style format, because it is old and lots of people already contributed to it. But now we are already in 2022 and we have plenty of tools to make formatting easier, so my suggestion is that we add clang-format to hercules source, or at very least apply it once.

You can get an idea of how the changes will look like here in this commit: https://github.com/HerculesWS/Hercules/commit/5a392851d643a1eff8439338a405c69c05b52981#diff-883d0abbee797807e33ccba4fe4d012fe04c286b2c231270e212116b07276ac9

Describe the solution you'd like

clang-format

Suggested configuration

(most similar of what our code already looks like)

# Format Style Options - Created with Clang Power Tools
---
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignEscapedNewlines: DontAlign
AllowShortCaseLabelsOnASingleLine: true
BreakBeforeBraces: Mozilla
BreakConstructorInitializers: AfterColon
BreakStringLiterals: false
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
...

Of course it needs to be fine tuned, for example:

  • add clang-format to github workflows
  • ignoring 3rdparty folder
  • review #define and #pragma changes (they are 99% likely to be wrong and break compilation)

but yeah, code looks fine after all these changes

ghost avatar Apr 13 '22 21:04 ghost

how to deal with git blame: https://tekin.co.uk/2020/09/ignore-linting-and-formatting-commits-when-running-git-blame

EPuncker avatar Apr 15 '22 02:04 EPuncker