wasm-opt-rs icon indicating copy to clipboard operation
wasm-opt-rs copied to clipboard

Consider formatting first-party C++ code with clang-format

Open dtolnay opened this issue 3 years ago • 2 comments

The 2 force-pushes in #102 are both because I screwed up formatting whitespace by hand. I have been spoiled by rustfmt long enough that I guess I am out of practice.

References:

  • https://clang.llvm.org/docs/ClangFormat.html
  • https://clang.llvm.org/docs/ClangFormatStyleOptions.html

I have been using clang-format in https://github.com/dtolnay/cxx and been happy with it.

The code style in shims.h is inconsistent (not to mention all the trailing whitespace) but the closest that I was able to get clang-format to match your dominant style is with the following config. Here is the resulting generated diff: https://github.com/brson/wasm-opt-rs/commit/dd382f1936252b94196afc8b701571eac6430646

AlignAfterOpenBracket: Align
AlignOperands: DontAlign
AllowAllArgumentsOnNextLine: false
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
FixNamespaceComments: false
NamespaceIndentation: All
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: false

dtolnay avatar Oct 15 '22 23:10 dtolnay

Sounds good to me. I'll probably reformat everything with the defaults. The only syntactic decision I care about is the redundant use of namespace blocks.

brson avatar Oct 17 '22 17:10 brson

Add it to the existing cargo fmt ci job

brson avatar Oct 17 '22 22:10 brson