clang-format: copy latest and re-format

clang-format-16 has some backwards incompatible changes that require
additional settings for best compatibility and re-running the formatter.
Copy the latest .clang-format from the docs repository and reformat the
repository.

Change-Id: I267a17e007b99caed10aef060e7dd9a0bcc5fc2e
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index ea71ad6..d92a3f1 100644
--- a/.clang-format
+++ b/.clang-format
@@ -5,22 +5,24 @@
 AlignAfterOpenBracket: Align
 AlignConsecutiveAssignments: false
 AlignConsecutiveDeclarations: false
-AlignEscapedNewlinesLeft: false
-AlignOperands:   true
-AlignTrailingComments: true
+AlignEscapedNewlines: Right
+AlignOperands:  Align
+AlignTrailingComments:
+  Kind: Always
+  OverEmptyLines: 1
 AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
+AllowShortBlocksOnASingleLine: Empty
 AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
+AllowShortFunctionsOnASingleLine: Empty
 AllowShortIfStatementsOnASingleLine: false
 AllowShortLoopsOnASingleLine: false
-AlwaysBreakAfterDefinitionReturnType: None
 AlwaysBreakAfterReturnType: None
 AlwaysBreakBeforeMultilineStrings: false
-AlwaysBreakTemplateDeclarations: true
+AlwaysBreakTemplateDeclarations: Yes
 BinPackArguments: true
 BinPackParameters: true
 BraceWrapping:
+  AfterCaseLabel:  true
   AfterClass:      true
   AfterControlStatement: true
   AfterEnum:       true
@@ -29,19 +31,28 @@
   AfterObjCDeclaration: true
   AfterStruct:     true
   AfterUnion:      true
+  AfterExternBlock: true
   BeforeCatch:     true
   BeforeElse:      true
   IndentBraces:    false
+  SplitEmptyFunction:   false
+  SplitEmptyRecord:     false
+  SplitEmptyNamespace:  false
+BreakAfterAttributes: Never
 BreakBeforeBinaryOperators: None
 BreakBeforeBraces: Custom
 BreakBeforeTernaryOperators: true
 BreakConstructorInitializers: AfterColon
+BreakInheritanceList: AfterColon
+BreakStringLiterals: false
 ColumnLimit:     80
 CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: false
 ConstructorInitializerAllOnOneLineOrOnePerLine: false
 ConstructorInitializerIndentWidth: 4
 ContinuationIndentWidth: 4
 Cpp11BracedListStyle: true
+DeriveLineEnding: false
 DerivePointerAlignment: false
 PointerAlignment: Left
 DisableFormat:   false
@@ -51,21 +62,29 @@
 IncludeBlocks: Regroup
 IncludeCategories:
   - Regex:           '^[<"](gtest|gmock)'
-    Priority:        5
+    Priority:        7
   - Regex:           '^"config.h"'
     Priority:        -1
-  - Regex:           '^".*\.hpp"'
+  - Regex:           '^".*\.h"'
     Priority:        1
-  - Regex:           '^<.*\.h>'
+  - Regex:           '^".*\.hpp"'
     Priority:        2
-  - Regex:           '^<.*'
+  - Regex:           '^<.*\.h>'
     Priority:        3
-  - Regex:           '.*'
+  - Regex:           '^<.*\.hpp>'
     Priority:        4
+  - Regex:           '^<.*'
+    Priority:        5
+  - Regex:           '.*'
+    Priority:        6
 IndentCaseLabels: true
+IndentRequiresClause: true
 IndentWidth:     4
 IndentWrappedFunctionNames: true
-KeepEmptyLinesAtTheStartOfBlocks: true
+InsertNewlineAtEOF: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: OuterScope
+LineEnding: LF
 MacroBlockBegin: ''
 MacroBlockEnd:   ''
 MaxEmptyLinesToKeep: 1
@@ -73,18 +92,29 @@
 ObjCBlockIndentWidth: 2
 ObjCSpaceAfterProperty: false
 ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 25
 PenaltyBreakBeforeFirstCallParameter: 19
 PenaltyBreakComment: 300
 PenaltyBreakFirstLessLess: 120
 PenaltyBreakString: 1000
 PenaltyExcessCharacter: 1000000
 PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+QualifierAlignment: Left
+ReferenceAlignment: Left
 ReflowComments:  true
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: Keyword
 SortIncludes:    true
 SortUsingDeclarations: true
 SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
 SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
 SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
 SpaceInEmptyParentheses: false
 SpacesBeforeTrailingComments: 1
 SpacesInAngles:  false
@@ -92,7 +122,7 @@
 SpacesInCStyleCastParentheses: false
 SpacesInParentheses: false
 SpacesInSquareBrackets: false
-Standard:        Cpp11
+Standard:        Latest
 TabWidth:        4
 UseTab:          Never
 ...
diff --git a/average.cpp b/average.cpp
index c5864bd..7b12d70 100644
--- a/average.cpp
+++ b/average.cpp
@@ -43,9 +43,9 @@
     // (a2*i2-a1*i1)/(i2-i1) =
     // (a2*(i1+delta)-a1*i1)/delta =
     // (a2-a1)(i1/delta)+a2
-    value =
-        (curAverage - preAverage) * (static_cast<double>(preInterval) / delta) +
-        curAverage;
+    value = (curAverage - preAverage) *
+                (static_cast<double>(preInterval) / delta) +
+            curAverage;
 
     return value;
 }
diff --git a/average.hpp b/average.hpp
index 5474065..cf2afd3 100644
--- a/average.hpp
+++ b/average.hpp
@@ -68,4 +68,4 @@
   private:
     /** @brief Store the previous average sensor map */
     averageMap _previousAverageMap;
-};
\ No newline at end of file
+};
diff --git a/fan_pwm.cpp b/fan_pwm.cpp
index 91ba57d..253515d 100644
--- a/fan_pwm.cpp
+++ b/fan_pwm.cpp
@@ -8,11 +8,12 @@
 
 #include <fmt/format.h>
 
-#include <filesystem>
 #include <phosphor-logging/elog-errors.hpp>
-#include <string>
 #include <xyz/openbmc_project/Control/Device/error.hpp>
 
+#include <filesystem>
+#include <string>
+
 using namespace phosphor::logging;
 
 namespace hwmon
@@ -38,8 +39,8 @@
             xyz::openbmc_project::Control::Device::WriteFailure::
                 CALLOUT_DEVICE_PATH(_devPath.c_str()));
 
-        auto file =
-            sysfs::make_sysfs_path(_ioAccess->path(), _type, _id, empty);
+        auto file = sysfs::make_sysfs_path(_ioAccess->path(), _type, _id,
+                                           empty);
 
         log<level::INFO>(fmt::format("Failing sysfs file: {} errno: {}", file,
                                      e.code().value())
diff --git a/gpio_handle.cpp b/gpio_handle.cpp
index d99a031..a4f6115 100644
--- a/gpio_handle.cpp
+++ b/gpio_handle.cpp
@@ -1,10 +1,11 @@
 #include "gpio_handle.hpp"
 
-#include <cstdlib>
 #include <gpioplus/chip.hpp>
 #include <gpioplus/handle.hpp>
-#include <memory>
 #include <phosphor-logging/log.hpp>
+
+#include <cstdlib>
+#include <memory>
 #include <string>
 
 namespace gpio
diff --git a/gpio_handle.hpp b/gpio_handle.hpp
index f48a34d..924efe8 100644
--- a/gpio_handle.hpp
+++ b/gpio_handle.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <gpioplus/handle.hpp>
+
 #include <memory>
 #include <string>
 
diff --git a/hwmonio.cpp b/hwmonio.cpp
index 8f0acf2..851ad9d 100644
--- a/hwmonio.cpp
+++ b/hwmonio.cpp
@@ -107,8 +107,7 @@
 
 HwmonIO::HwmonIO(const std::string& path, const FileSystemInterface* intf) :
     _p(path), _intf(intf)
-{
-}
+{}
 
 int64_t HwmonIO::read(const std::string& type, const std::string& id,
                       const std::string& sensor, size_t retries,
diff --git a/mainloop.cpp b/mainloop.cpp
index f205003..9327e6d 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -31,17 +31,18 @@
 
 #include <fmt/format.h>
 
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Sensor/Device/error.hpp>
+
 #include <cassert>
 #include <cstdlib>
 #include <functional>
 #include <future>
 #include <iostream>
 #include <memory>
-#include <phosphor-logging/elog-errors.hpp>
 #include <sstream>
 #include <string>
 #include <unordered_set>
-#include <xyz/openbmc_project/Sensor/Device/error.hpp>
 
 using namespace phosphor::logging;
 
@@ -215,8 +216,8 @@
     const auto& [sensorSysfsType, sensorSysfsNum] = sensorSetKey;
 
     /* Note: The sensor objects all share the same ioAccess object. */
-    auto sensorObj =
-        std::make_unique<sensor::Sensor>(sensorSetKey, _ioAccess, _devPath);
+    auto sensorObj = std::make_unique<sensor::Sensor>(sensorSetKey, _ioAccess,
+                                                      _devPath);
 
     // Get list of return codes for removing sensors on device
     auto devRmRCs = env::getEnv("REMOVERCS");
@@ -251,8 +252,7 @@
             }
         }
         catch (const std::invalid_argument&)
-        {
-        }
+        {}
 
         // Add status interface based on _fault file being present
         sensorObj->addStatus(info);
@@ -260,9 +260,9 @@
     }
     catch (const std::system_error& e)
     {
-        auto file =
-            sysfs::make_sysfs_path(_ioAccess->path(), sensorSysfsType,
-                                   sensorSysfsNum, hwmon::entry::cinput);
+        auto file = sysfs::make_sysfs_path(_ioAccess->path(), sensorSysfsType,
+                                           sensorSysfsNum,
+                                           hwmon::entry::cinput);
 
         // Check sensorAdjusts for sensor removal RCs
         auto& sAdjusts = sensorObj->getAdjusts();
@@ -301,8 +301,8 @@
                                  std::get<sensorID>(properties), sensorValue,
                                  info, scale);
 
-    auto target =
-        addTarget<hwmon::FanSpeed>(sensorSetKey, _ioAccess, _devPath, info);
+    auto target = addTarget<hwmon::FanSpeed>(sensorSetKey, _ioAccess, _devPath,
+                                             info);
     if (target)
     {
         target->enable();
@@ -396,9 +396,9 @@
             // std::tuple<SensorSet::mapped_type,
             //            std::string(Sensor Label),
             //            ObjectInfo>
-            auto value =
-                std::make_tuple(std::move(i.second), std::move((*object).first),
-                                std::move((*object).second));
+            auto value = std::make_tuple(std::move(i.second),
+                                         std::move((*object).first),
+                                         std::move((*object).second));
 
             _state[std::move(i.first)] = std::move(value);
         }
@@ -500,8 +500,8 @@
 
                 // For sensors with attribute ASYNC_READ_TIMEOUT,
                 // spawn a thread with timeout
-                auto asyncReadTimeout =
-                    env::getEnv("ASYNC_READ_TIMEOUT", sensorSetKey);
+                auto asyncReadTimeout = env::getEnv("ASYNC_READ_TIMEOUT",
+                                                    sensorSetKey);
                 if (!asyncReadTimeout.empty())
                 {
                     std::chrono::milliseconds asyncTimeout{
@@ -515,9 +515,9 @@
                 {
                     // Retry for up to a second if device is busy
                     // or has a transient error.
-                    value =
-                        _ioAccess->read(sensorSysfsType, sensorSysfsNum, input,
-                                        hwmonio::retries, hwmonio::delay);
+                    value = _ioAccess->read(sensorSysfsType, sensorSysfsNum,
+                                            input, hwmonio::retries,
+                                            hwmonio::delay);
                 }
 
                 // Set functional property to true if we could read sensor
@@ -665,9 +665,9 @@
                     input = hwmon::entry::average;
                 }
                 // Sensor object added, erase entry from removal list
-                auto file =
-                    sysfs::make_sysfs_path(_ioAccess->path(), it->first.first,
-                                           it->first.second, input);
+                auto file = sysfs::make_sysfs_path(_ioAccess->path(),
+                                                   it->first.first,
+                                                   it->first.second, input);
 
                 log<level::INFO>("Added sensor to dbus after successful read",
                                  entry("FILE=%s", file.c_str()));
diff --git a/mainloop.hpp b/mainloop.hpp
index 468223b..cc8de94 100644
--- a/mainloop.hpp
+++ b/mainloop.hpp
@@ -8,14 +8,15 @@
 #include "sysfs.hpp"
 #include "types.hpp"
 
-#include <any>
-#include <future>
-#include <memory>
-#include <optional>
 #include <sdbusplus/server.hpp>
 #include <sdeventplus/clock.hpp>
 #include <sdeventplus/event.hpp>
 #include <sdeventplus/utility/timer.hpp>
+
+#include <any>
+#include <future>
+#include <memory>
+#include <optional>
 #include <string>
 #include <vector>
 
diff --git a/readd.cpp b/readd.cpp
index 06e7d8c..911f076 100644
--- a/readd.cpp
+++ b/readd.cpp
@@ -20,6 +20,7 @@
 #include "sysfs.hpp"
 
 #include <CLI/CLI.hpp>
+
 #include <iostream>
 #include <memory>
 
diff --git a/sensor.cpp b/sensor.cpp
index 1d031f4..e53b01c 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -10,16 +10,17 @@
 
 #include <fmt/format.h>
 
+#include <phosphor-logging/elog-errors.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Sensor/Device/error.hpp>
+
 #include <cassert>
 #include <chrono>
 #include <cmath>
 #include <cstring>
 #include <filesystem>
 #include <future>
-#include <phosphor-logging/elog-errors.hpp>
 #include <thread>
-#include <xyz/openbmc_project/Common/error.hpp>
-#include <xyz/openbmc_project/Sensor/Device/error.hpp>
 
 namespace sensor
 {
@@ -221,8 +222,8 @@
     std::string entry = hwmon::entry::fault;
 
     bool functional = true;
-    auto sysfsFullPath =
-        sysfs::make_sysfs_path(_ioAccess->path(), faultName, faultID, entry);
+    auto sysfsFullPath = sysfs::make_sysfs_path(_ioAccess->path(), faultName,
+                                                faultID, entry);
     if (fs::exists(sysfsFullPath))
     {
         _hasFaultFile = true;
@@ -313,9 +314,9 @@
     if (asyncIter == timedoutMap.end())
     {
         // If sensor not found in timedoutMap, spawn an async thread
-        asyncThread =
-            std::async(std::launch::async, &hwmonio::HwmonIOInterface::read,
-                       ioAccess, type, id, sensor, retries, delay);
+        asyncThread = std::async(std::launch::async,
+                                 &hwmonio::HwmonIOInterface::read, ioAccess,
+                                 type, id, sensor, retries, delay);
         valueIsValid = true;
     }
     else
diff --git a/sensor.hpp b/sensor.hpp
index 1fd6a70..6f7aa59 100644
--- a/sensor.hpp
+++ b/sensor.hpp
@@ -4,13 +4,14 @@
 #include "sensorset.hpp"
 #include "types.hpp"
 
+#include <gpioplus/handle.hpp>
+#include <stdplus/handle/managed.hpp>
+
 #include <cerrno>
 #include <future>
-#include <gpioplus/handle.hpp>
 #include <map>
 #include <memory>
 #include <optional>
-#include <stdplus/handle/managed.hpp>
 #include <unordered_set>
 
 namespace sensor
@@ -32,8 +33,7 @@
     AsyncSensorReadTimeOut() :
         system_error(std::error_code(ETIMEDOUT, std::system_category()),
                      "Async sensor read timed out")
-    {
-    }
+    {}
 };
 
 /** @class Sensor
diff --git a/sysfs.cpp b/sysfs.cpp
index f5b12bc..644763e 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -219,11 +219,11 @@
         }
 
         auto dir_iter = fs::directory_iterator(path);
-        auto hwmonInst = std::find_if(
-            dir_iter, end(dir_iter), [](const fs::directory_entry& d) {
-                return (d.path().filename().string().find("hwmon") !=
-                        std::string::npos);
-            });
+        auto hwmonInst = std::find_if(dir_iter, end(dir_iter),
+                                      [](const fs::directory_entry& d) {
+            return (d.path().filename().string().find("hwmon") !=
+                    std::string::npos);
+        });
         if (hwmonInst != end(dir_iter))
         {
             return hwmonInst->path();
diff --git a/targets.hpp b/targets.hpp
index a66a15b..515bf2e 100644
--- a/targets.hpp
+++ b/targets.hpp
@@ -7,12 +7,13 @@
 
 #include <fmt/format.h>
 
-#include <filesystem>
-#include <memory>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/Sensor/Device/error.hpp>
 
+#include <filesystem>
+#include <memory>
+
 enum class targetType
 {
     DEFAULT,
@@ -98,8 +99,8 @@
         entry = empty;
     }
 
-    sysfsFullPath =
-        sysfs::make_sysfs_path(ioAccess->path(), targetName, targetId, entry);
+    sysfsFullPath = sysfs::make_sysfs_path(ioAccess->path(), targetName,
+                                           targetId, entry);
     if (fs::exists(sysfsFullPath))
     {
         auto useTarget = true;
diff --git a/test/fanpwm_unittest.cpp b/test/fanpwm_unittest.cpp
index b407c7d..0c34ab2 100644
--- a/test/fanpwm_unittest.cpp
+++ b/test/fanpwm_unittest.cpp
@@ -2,6 +2,7 @@
 #include "hwmonio_mock.hpp"
 
 #include <sdbusplus/test/sdbus_mock.hpp>
+
 #include <string>
 
 #include <gmock/gmock.h>
@@ -41,9 +42,9 @@
                                                         StrEq(intf), NotNull()))
             .WillOnce(Invoke(
                 [=](sd_bus*, const char*, const char*, const char** names) {
-                    EXPECT_STREQ(property.c_str(), names[0]);
-                    return 0;
-                }));
+            EXPECT_STREQ(property.c_str(), names[0]);
+            return 0;
+            }));
     }
 
     return;
diff --git a/test/gpio_mock.hpp b/test/gpio_mock.hpp
index d1acfef..0e659f8 100644
--- a/test/gpio_mock.hpp
+++ b/test/gpio_mock.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <gpioplus/handle.hpp>
+
 #include <memory>
 #include <string>
 
diff --git a/test/hwmon_unittest.cpp b/test/hwmon_unittest.cpp
index 1c538c7..ef3ef7d 100644
--- a/test/hwmon_unittest.cpp
+++ b/test/hwmon_unittest.cpp
@@ -5,7 +5,6 @@
 
 TEST(HwmonTest, InvalidType)
 {
-
     hwmon::Attributes attrs;
     EXPECT_FALSE(hwmon::getAttributes("invalid", attrs));
 }
diff --git a/test/hwmonio_default_unittest.cpp b/test/hwmonio_default_unittest.cpp
index 233bf56..875326a 100644
--- a/test/hwmonio_default_unittest.cpp
+++ b/test/hwmonio_default_unittest.cpp
@@ -18,9 +18,7 @@
 class HwmonIOTest : public ::testing::Test
 {
   protected:
-    HwmonIOTest() : _hwmonio(_path, &_mock)
-    {
-    }
+    HwmonIOTest() : _hwmonio(_path, &_mock) {}
 
     const int64_t _value = 12;
     const std::string _path = "abcd";
diff --git a/test/sensor_unittest.cpp b/test/sensor_unittest.cpp
index 15a4807..a1026cc 100644
--- a/test/sensor_unittest.cpp
+++ b/test/sensor_unittest.cpp
@@ -4,6 +4,7 @@
 #include "sensor.hpp"
 
 #include <gpioplus/test/handle.hpp>
+
 #include <memory>
 #include <utility>
 
@@ -61,8 +62,8 @@
     EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
         .WillOnce(Return(""));
 
-    auto sensor =
-        std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
+    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
+                                                   hwmonio_mock.get(), path);
     EXPECT_FALSE(sensor == nullptr);
 }
 
@@ -98,8 +99,8 @@
     EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
         .WillOnce(Return(""));
 
-    auto sensor =
-        std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
+    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
+                                                   hwmonio_mock.get(), path);
     EXPECT_FALSE(sensor == nullptr);
 }
 
@@ -125,8 +126,8 @@
     EXPECT_CALL(env::mockEnv, get(StrEq("REMOVERCS_temp5")))
         .WillOnce(Return(""));
 
-    auto sensor =
-        std::make_unique<sensor::Sensor>(sensorKey, hwmonio_mock.get(), path);
+    auto sensor = std::make_unique<sensor::Sensor>(sensorKey,
+                                                   hwmonio_mock.get(), path);
     EXPECT_FALSE(sensor == nullptr);
 
     double startingValue = 1.0;