Docker image verifying the code format with clang-format
Go to file
Adrien Leravat fe6fdfbbb5 Remove default args for run-clang-format.py
Providing '-r .' makes it unecessarly rigid for other uses
2019-06-24 11:54:19 -07:00
run-clang-format@50fc7ad73e Add original Docker image, using run-clang-format.py 2019-06-14 13:25:05 -07:00
.gitmodules Add original Docker image, using run-clang-format.py 2019-06-14 13:25:05 -07:00
Dockerfile Remove default args for run-clang-format.py 2019-06-24 11:54:19 -07:00
LICENSE Initial commit 2019-06-14 13:23:10 -07:00
README.md README.md: Fix typo in sample output 2019-06-21 15:55:09 -07:00

clang-format-checker-docker

Docker image verifying the code format with clang-format

Getting Started

The following command will mount the current working directory folder to the src working directory, and check its format

docker run --rm -v $(pwd):/src witekio/clang-format-checker

The return code will be

  • non-zero if any formatting errors are found, and printed in the standard output.
  • 0 if no issue was found
$ docker run -v $(pwd):/src --rm witekio/clang-format-checker                                      2 ↵
--- ./testCode/File.cpp	(original)
+++ ./testCode/File.cpp	(reformatted)
@@ -3,18 +3,13 @@
 
 #include "MyHeader.h"
 
-MyClass::MyClass() 
+MyClass::MyClass()
-    : arg(new Other(std::string("string"), 4))
+  : arg(new Other(std::string("string"), 4))

CI Integration

BitBucket Pipeline

The following Pipeline step will check for any style error in the src folder, and return an error if problems are found

pipelines:
  default:
    - step:
        name: Check code format
        image: witekio/clang-format-checker
        script:
          - run-clang-format.py -r src

Changing the style

The style used by clang-format can be defined by providing a .clang-format file in your source folder. For more information, see clang-format style options

Specify the files to check

Check recursively .h/.cpp files excluding vendors folder

docker run --rm -v $(pwd):/src witekio/clang-format-checker "--extensions=h,cpp --exclude vendors"

For more information, you can check run-clang-format repository

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments