Clang Format Notes
The intention is to activate format-on-save in Visual Studio. Either use integration in Visual Studio for format-on-save, or use Clang Power Tools.
Install Clang Power Tools
-
Install plugin Clang Power Tools Plugin
-
Install LLVM 15 in Clang Power Tools
-
The version selected in GUI can be overriden by manually setting the to clang-format Set the path to clang-format in “Custom executable” for Clang Power Tools. clang-format installed by Clang Power Tools will put the executable in path similar to :
C:\Users\ruben\AppData\Roaming\ClangPowerTools\LLVM\LLVM15.0.0\bin\clang-format.exe
GitHub Action
A GitHub Action is running clang-format when changes is pushed to a branch. If clang-format issues are detected, a new PR is created.
clang-format action for ResInsight
Use with PowerShell
If you need to do apply clang format on all files, it is useful to use PowerShell
- Add clang-format to path
$env:Path += ";C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\vcpackages\"
- Powershell syntax command to apply clang-format on header/cpp files in a folder recursively. Start in ResInsight/ApplicationCode
dir -recurse -include *.cpp,*.h,*.inl | %{clang-format -fallback-style=none -i $_.FullName}
References
https://clang.llvm.org/docs/ClangFormat.html