Skip to content

docs: Add documentation on how to run clang-format correctly on any machine w/ docker

I have a kratsg/clang-format docker image that is CI friendly and can be used to do all this work for anyone who needs clang-format. You could probably swap out your CI to use this docker image and trivially run it without needing to rely on the base image. This is how someone can run it on their computer locally

$ docker run -v $PWD:/workdir kratsg/clang-format -r ./src/ ./arduino/ --extensions c,h,cpp,hpp,cxx,hxx,ino
--- ./src/libChiller/HuberChiller.cpp	(original)
+++ ./src/libChiller/HuberChiller.cpp	(reformatted)
@@ -5,10 +5,10 @@
 HuberChiller::~HuberChiller() {}
 
 void HuberChiller::init() {
-  const std::string& termination = m_com->termination();
-  m_com->setTermination("\r");
-  m_identity = command("[M01V07C6");
-  m_com->setTermination(termination);
+    const std::string& termination = m_com->termination();
+    m_com->setTermination("\r");
+    m_identity = command("[M01V07C6");
+    m_com->setTermination(termination);
 }
 
 std::string HuberChiller::command(const std::string& cmd) {
@@ -16,7 +16,7 @@
     // The send commands always begin with "[M01", answers always with "[S01",
     // followed by the command qualifier "V" (Verify), "L" (Limits) or "G"
     // (General)
-    if (cmd.rfind("[M01") == 0){
+    if (cmd.rfind("[M01") == 0) {
         if (response.rfind("[S01") != 0) {
             logger(logDEBUG)
                 << __PRETTY_FUNCTION__

and can also have it automatically format in-place via something like

docker run -v $PWD:/workdir kratsg/clang-format -r ./src/ ./arduino/ --extensions c,h,cpp,hpp,cxx,hxx,ino -i

with the addition of the -i flag. ./cc @dantrim .