Skip to content

Add clang-format check to CI#1683

Merged
aheejin merged 7 commits intoWebAssembly:mainfrom
aheejin:clang_format_ci
Aug 6, 2021
Merged

Add clang-format check to CI#1683
aheejin merged 7 commits intoWebAssembly:mainfrom
aheejin:clang_format_ci

Conversation

@aheejin
Copy link
Copy Markdown
Member

@aheejin aheejin commented Jun 27, 2021

This adds clang-format check to the CI. This only checks the diff so it
doesn't affect the other parts of the codebase. Also generated files in
src/prebuilt/ directories are excluded from the check. A new
src/prebuilt/.clang-format is added to disable the check in the
directory.

scripts/clang-format-diff.sh is copied from the same file we are using in
Binaryen.

Two clang-format errors are added to test if CI correctly errors out;
one within a normal source file in src/, and the other in src/prebuilt.
The latter should not be shown in the error, because the directory is
excluded. The errors will be removed before merging.

aheejin added 3 commits June 26, 2021 20:23
This adds clang-format check to the CI. This only checks the diff so it
doesn't affect the other parts of the codebase. Also generated files in
src/prebuilt/ directories are excluded from the check. A new
src/prebuilt/.clang-format is added to disable the check in the
directory.

scripts/clang-format-diff.sh is copied from the same file we are using in
Binaryen.

Two clang-format errors are added to test if CI correctly errors out;
one within a normal source file in src/, and the other in src/prebuilt.
The latter should not be shown in the error, because the directory is
excluded.
@aheejin aheejin marked this pull request as draft June 27, 2021 03:30
@aheejin
Copy link
Copy Markdown
Member Author

aheejin commented Jun 27, 2021

It looks the CI correct displays the clang-format error I introduced: https://github.com/WebAssembly/wabt/pull/1683/checks?check_run_id=2923646482

@aheejin aheejin requested review from binji and sbc100 June 27, 2021 03:50
@aheejin aheejin marked this pull request as ready for review June 27, 2021 03:50
aheejin added a commit to aheejin/wabt that referenced this pull request Jun 27, 2021
This applies clang-format to the whole codebase.

I noticed we have .clang-format in wabt but the codebase is not very
well formatted. This kind of mass-formatting PR has fans and skeptics
because it can mess with `git blame`, but we did a similar thing in
Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in
WebAssembly/binaryen#2059) and it was not very confusing after all.
If we are going to ever format the codebase, I think it is easier to do
it in a single big PR than dozens of smaller PRs.

This does not include files in src/prebuilt, because they are generated.

This PR is mainly to listen to opinions and it is OK we end up not
merging this. (Also even if we end up merging this, I'm not sure if I am
the right person to change this many lines of code, given that I am not
a frequent contributor in this repo.)

I also added a clang-format check hook in the Github CI in WebAssembly#1683, which
I think can be less controversial, given that it only checks the diff.
aheejin added a commit to aheejin/wabt that referenced this pull request Jun 27, 2021
This applies clang-format to the whole codebase.

I noticed we have .clang-format in wabt but the codebase is not very
well formatted. This kind of mass-formatting PR has fans and skeptics
because it can mess with `git blame`, but we did a similar thing in
Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in
WebAssembly/binaryen#2059) and it was not very confusing after all.
If we are going to ever format the codebase, I think it is easier to do
it in a single big PR than dozens of smaller PRs.

This is using the existing .clang-format file in this repo, which
follows the style of Chromium. If we think this does not suit the
current formatting style, we can potentially tweak .clang-format too.
For example, I noticed the current codebase puts many `case` statements
within a single line when they are short, but the current .clang-format
does not allow that.

This does not include files in src/prebuilt, because they are generated.

This also manually fixes some comment lines, because mechanically
applying clang-format to long inline comments can look weird.

This PR is mainly to listen to opinions and it is OK we end up not
merging this. (Also even if we end up merging this, I'm not sure if I am
the right person to change this many lines of code, given that I am not
a frequent contributor in this repo.)

I also added a clang-format check hook in the Github CI in WebAssembly#1683, which
I think can be less controversial, given that it only checks the diff.
@aheejin aheejin mentioned this pull request Jun 27, 2021
Copy link
Copy Markdown
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable once we deal with issues in #1684/

@aheejin
Copy link
Copy Markdown
Member Author

aheejin commented Aug 6, 2021

@sbc100 Can you LG this?

@aheejin aheejin merged commit a92466a into WebAssembly:main Aug 6, 2021
@aheejin aheejin deleted the clang_format_ci branch August 6, 2021 04:32
aheejin added a commit that referenced this pull request Dec 21, 2021
This applies clang-format to the whole codebase.

I noticed we have .clang-format in wabt but the codebase is not very
well formatted. This kind of mass-formatting PR has fans and skeptics
because it can mess with `git blame`, but we did a similar thing in
Binaryen a few years ago (WebAssembly/binaryen#2048, which was merged in
WebAssembly/binaryen#2059) and it was not very confusing after all.
If we are ever going to format the codebase, I think it is easier to do
it in a single big PR than dozens of smaller PRs.

This is using the existing .clang-format file in this repo, which
follows the style of Chromium. If we think this does not suit the
current formatting style, we can potentially tweak .clang-format too.
For example, I noticed the current codebase puts many `case` statements
within a single line when they are short, but the current .clang-format
does not allow that.

This does not include files in src/prebuilt, because they are generated.

This also manually fixes some comment lines, because mechanically
applying clang-format to long inline comments can look weird.

I also added a clang-format check hook in the Github CI in #1683, which
I think can be less controversial, given that it only checks the diff.

---

After discussions, we ended up reverting many changes, especially
one-liner functions and switch-cases, which are too many to wrap in
`// clang-format off` and `// clang-format on`. I also considered fixing
`.clang-format` to allow those one-liners but it caused a larger churn
in other parts. So currently the codebase does not conform to
`.clang-format` 100%, but we decided it's fine.
@SoniEx2 SoniEx2 mentioned this pull request Feb 23, 2022
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