Skip to content

Commit

Permalink
Use clang-format to format the whole codebase (#278)
Browse files Browse the repository at this point in the history
Following up on the [clang-format
discussion](#274), I
now have drafted a PR to reformat the whole code base using the
[clang-format](https://clang.llvm.org/docs/ClangFormat.html) tool with
its [LLVM
preset](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#basedonstyle).
Please have a look at the [LLVM coding
standards](https://llvm.org/docs/CodingStandards.html) for a description
of this style.

This PR does:
- Reformat the entire code base using clang-format
- Add a `.clang-format` configuration file for the project
- Add a `.git-blame-ignore-revs` file which hides the reformatting
commit from `git blame` and [GitHubs blame
web-view](https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view)
- Add a `scripts/format-all.sh` script to quickly reformat all C++
source and headers files of the project.
- Extends `devcontainer.json` to suggest installing a couple of
extensions which are useful for DPsim-related C++ & Python development
- This includes an extensions for clang-format to format files on save
- Fix a few missing includes which broke compilation after the
reformatting

This PR does NOT:
- Enforce the use of clang-format
- Performs any checks if the code is formatted

The idea I have is that we are tolerant towards violate the LLVM style
for any commits as we want to keep the barrier for new contributors as
low as possible. We dont want to drive them away because of failing
nit-pick CI checks.

Hence, we only reformat the entire code-base from time to time by hand.

And of course:

I invite all regular contributors to install the [clang-format VSCode
extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format),
so your changes are directly properly formatted when a file is saved.

(Btw. this also speeds up our own coding a lot as you will not have to
worry ever again about code formatting. Just write as you like, save the
file and everything is tidy :D)
  • Loading branch information
m-mirz authored Feb 27, 2024
2 parents e0ae9d9 + 907355a commit b17546a
Show file tree
Hide file tree
Showing 575 changed files with 66,311 additions and 59,069 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Author: Steffen Vogel <[email protected]>
# SPDX-FileCopyrightText: 2024 OPAL-RT Germany GmbH
# SPDX-License-Identifier: MPL-2.0
---
BasedOnStyle: LLVM

# Disable automatic line-breaks in comments
# as this breaks SPDX headers
ReflowComments: false
18 changes: 16 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,19 @@
"runArgs": [
"--privileged",
"--security-opt=seccomp=unconfined"
]
}
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.flake8",
"xaver.clang-format",
"llvm-vs-code-extensions.vscode-clangd",
"editorconfig.editorconfig"
]
}
}
}
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Reformat all C++ code with clang-format
d75bf1e5bee08c6bb4c648cad0d89a494732c58e
7 changes: 0 additions & 7 deletions configs/dev-dataprocessing.sh

This file was deleted.

Loading

0 comments on commit b17546a

Please sign in to comment.