From a77c6ff3a268faad8d9b9452080dc91e2733297a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 10 Jun 2021 11:13:09 -0700 Subject: [PATCH] [build] Upgrade clang-format and clang-tidy (NFC) (#3422) --- .github/workflows/cmake.yml | 2 +- .github/workflows/lint-format.yml | 20 +++++++++++++------ .../main/native/cpp/jni/CameraServerJNI.cpp | 2 +- cscore/src/main/native/include/cscore_raw.h | 2 +- .../src/main/native/include/cscore_raw_cv.h | 2 ++ .../src/main/native/windows/UsbCameraImpl.cpp | 9 ++++++--- .../src/main/native/windows/UsbCameraImpl.h | 2 +- hal/src/main/native/athena/CTREPCM.cpp | 5 +++-- .../main/native/athena/FRCDriverStation.cpp | 3 ++- hal/src/main/native/athena/Notifier.cpp | 6 ++++-- .../native/cpp/jni/simulation/SimulatorJNI.h | 2 +- hal/src/main/native/sim/ErrorsInternal.h | 6 +++--- hal/src/main/native/sim/Interrupts.cpp | 2 +- ntcore/src/main/native/cpp/Dispatcher.h | 2 +- ntcore/src/main/native/cpp/Message.h | 2 +- .../src/main/native/cpp/NetworkConnection.h | 5 ++--- ntcore/src/main/native/cpp/RpcServer.h | 2 +- ntcore/src/main/native/cpp/Storage.h | 2 +- ntcore/src/main/native/cpp/Storage_load.cpp | 2 +- .../include/networktables/NetworkTableValue.h | 2 +- ntcore/src/test/native/cpp/ValueTest.cpp | 2 +- .../src/clockTest/cpp/clockTest.cpp | 2 +- .../src/gyro/headers/gyro.h | 2 +- .../native/directx11/wpigui_directx11.cpp | 3 ++- wpilibc/src/main/native/cppcs/RobotBase.cpp | 2 +- .../frc/shuffleboard/SendableCameraWrapper.h | 4 ++-- .../src/main/native/cpp/TestEnvironment.cpp | 2 +- .../main/native/include/wpi/CallbackManager.h | 2 +- .../main/native/include/wpi/function_ref.h | 15 +++++++------- 29 files changed, 66 insertions(+), 48 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index acbd830bd6..030d5a62f3 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -10,7 +10,7 @@ jobs: include: - os: ubuntu-latest name: Linux - container: wpilib/roborio-cross-ubuntu:2020-20.04 + container: wpilib/roborio-cross-ubuntu:2021-20.04 flags: "" - os: macos-latest name: macOS diff --git a/.github/workflows/lint-format.yml b/.github/workflows/lint-format.yml index 6b2bc85d05..1194deba20 100644 --- a/.github/workflows/lint-format.yml +++ b/.github/workflows/lint-format.yml @@ -22,17 +22,17 @@ jobs: with: python-version: 3.8 - name: Install clang-format - run: sudo apt-get update -q && sudo apt-get install -y clang-format-10 + run: sudo apt-get update -q && sudo apt-get install -y clang-format-12 - name: Install wpiformat run: pip3 install wpiformat - name: Run - run: wpiformat -clang 10 + run: wpiformat -clang 12 - name: Check Output run: git --no-pager diff --exit-code HEAD tidy: name: "clang-tidy" runs-on: ubuntu-latest - container: wpilib/roborio-cross-ubuntu:2020-20.04 + container: wpilib/roborio-cross-ubuntu:2021-20.04 steps: - uses: actions/checkout@v2 - name: Fetch all history and metadata @@ -40,8 +40,16 @@ jobs: git fetch --prune --unshallow git checkout -b pr git branch -f main origin/main - - name: Install clang-format and clang-tidy - run: sudo apt-get update -q && sudo apt-get install -y clang-format-10 clang-tidy-10 python3.8 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install clang-tidy + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 12 + sudo apt-get install -y clang-tidy-12 - name: Install wpiformat run: pip3 install wpiformat - name: Create compile_commands.json @@ -49,4 +57,4 @@ jobs: - name: List changed files run: wpiformat -list-changed-files - name: Run clang-tidy - run: wpiformat -clang 10 -no-format -tidy-changed -compile-commands=build-cmake + run: wpiformat -clang 12 -no-format -tidy-changed -compile-commands=build-cmake diff --git a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp index 8b648f8b14..b99d322599 100644 --- a/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp +++ b/cscore/src/main/native/cpp/jni/CameraServerJNI.cpp @@ -2154,7 +2154,7 @@ struct LogMessage { std::string m_msg; }; -typedef JSingletonCallbackManager LoggerJNI; +using LoggerJNI = JSingletonCallbackManager; } // namespace diff --git a/cscore/src/main/native/include/cscore_raw.h b/cscore/src/main/native/include/cscore_raw.h index b52962855c..adb9649727 100644 --- a/cscore/src/main/native/include/cscore_raw.h +++ b/cscore/src/main/native/include/cscore_raw.h @@ -14,7 +14,7 @@ /** * Raw Frame */ -typedef struct CS_RawFrame { +typedef struct CS_RawFrame { // NOLINT char* data; int dataLength; int pixelFormat; diff --git a/cscore/src/main/native/include/cscore_raw_cv.h b/cscore/src/main/native/include/cscore_raw_cv.h index defd239857..88c94a1642 100644 --- a/cscore/src/main/native/include/cscore_raw_cv.h +++ b/cscore/src/main/native/include/cscore_raw_cv.h @@ -9,6 +9,8 @@ #error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file" #endif +#include + #include "cscore_raw.h" namespace cs { diff --git a/cscore/src/main/native/windows/UsbCameraImpl.cpp b/cscore/src/main/native/windows/UsbCameraImpl.cpp index 082057ccc7..1a3b23044a 100644 --- a/cscore/src/main/native/windows/UsbCameraImpl.cpp +++ b/cscore/src/main/native/windows/UsbCameraImpl.cpp @@ -533,8 +533,9 @@ bool UsbCameraImpl::CacheProperties(CS_Status* status) const { auto result = m_messagePump->SendWindowMessage( WaitForStartupMessage, nullptr, nullptr); *status = result; - if (*status != CS_OK) + if (*status != CS_OK) { return false; + } if (!m_properties_cached) { *status = CS_SOURCE_IS_DISCONNECTED; return false; @@ -883,10 +884,12 @@ CS_StatusValue UsbCameraImpl::DeviceCmdSetMode( } bool UsbCameraImpl::DeviceStreamOn() { - if (m_streaming) + if (m_streaming) { return false; - if (!m_deviceValid) + } + if (!m_deviceValid) { return false; + } m_streaming = true; m_sourceReader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, NULL, NULL, NULL); diff --git a/cscore/src/main/native/windows/UsbCameraImpl.h b/cscore/src/main/native/windows/UsbCameraImpl.h index d770b7b5b8..ea6c104351 100644 --- a/cscore/src/main/native/windows/UsbCameraImpl.h +++ b/cscore/src/main/native/windows/UsbCameraImpl.h @@ -45,7 +45,7 @@ class UsbCameraImpl : public SourceImpl, Telemetry& telemetry, int deviceId); ~UsbCameraImpl() override; - void Start(); + void Start() override; // Property functions void SetProperty(int property, int value, CS_Status* status) override; diff --git a/hal/src/main/native/athena/CTREPCM.cpp b/hal/src/main/native/athena/CTREPCM.cpp index 07aa48e1cc..84c06203c2 100644 --- a/hal/src/main/native/athena/CTREPCM.cpp +++ b/hal/src/main/native/athena/CTREPCM.cpp @@ -389,8 +389,9 @@ void HAL_SetCTREPCMOneShotDuration(HAL_CTREPCMHandle handle, int32_t index, } std::scoped_lock lock{pcm->lock}; - pcm->oneShot.sol10MsPerUnit[index] = (std::min)( - static_cast(durMs) / 10, static_cast(0xFF)); + pcm->oneShot.sol10MsPerUnit[index] = + (std::min)(static_cast(durMs) / 10, + static_cast(0xFF)); HAL_WriteCANPacketRepeating(pcm->canHandle, pcm->oneShot.sol10MsPerUnit, 8, Control2, SendPeriod, status); } diff --git a/hal/src/main/native/athena/FRCDriverStation.cpp b/hal/src/main/native/athena/FRCDriverStation.cpp index d32bf7acaf..bce631ff54 100644 --- a/hal/src/main/native/athena/FRCDriverStation.cpp +++ b/hal/src/main/native/athena/FRCDriverStation.cpp @@ -158,8 +158,9 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode, auto curTime = std::chrono::steady_clock::now(); int i; for (i = 0; i < KEEP_MSGS; ++i) { - if (prevMsg[i] == details) + if (prevMsg[i] == details) { break; + } } int retval = 0; if (i == KEEP_MSGS || (curTime - prevMsgTime[i]) >= std::chrono::seconds(1)) { diff --git a/hal/src/main/native/athena/Notifier.cpp b/hal/src/main/native/athena/Notifier.cpp index 2069e69da4..a74718a41e 100644 --- a/hal/src/main/native/athena/Notifier.cpp +++ b/hal/src/main/native/athena/Notifier.cpp @@ -76,10 +76,12 @@ static void alarmCallback() { // process all notifiers notifierHandles->ForEach([&](HAL_NotifierHandle handle, Notifier* notifier) { - if (notifier->triggerTime == UINT64_MAX) + if (notifier->triggerTime == UINT64_MAX) { return; - if (currentTime == 0) + } + if (currentTime == 0) { currentTime = HAL_GetFPGATime(&status); + } std::unique_lock lock(notifier->mutex); if (notifier->triggerTime < currentTime) { notifier->triggerTime = UINT64_MAX; diff --git a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h index 38e074330f..3e71acdb38 100644 --- a/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h +++ b/hal/src/main/native/cpp/jni/simulation/SimulatorJNI.h @@ -7,7 +7,7 @@ #include "hal/Types.h" #include "jni.h" -typedef HAL_Handle SIM_JniHandle; +using SIM_JniHandle = HAL_Handle; // NOLINT namespace hal::sim { JavaVM* GetJVM(); diff --git a/hal/src/main/native/sim/ErrorsInternal.h b/hal/src/main/native/sim/ErrorsInternal.h index eb2bf8c3d2..42d15606ad 100644 --- a/hal/src/main/native/sim/ErrorsInternal.h +++ b/hal/src/main/native/sim/ErrorsInternal.h @@ -6,7 +6,7 @@ #include -typedef enum { +enum CTR_Code { CTR_OKAY, // No Error - Function executed as expected CTR_RxTimeout, // CAN frame has not been received within specified period of // time. @@ -17,7 +17,7 @@ typedef enum { CTR_SigNotUpdated, // Have not received an value response for signal. CTR_BufferFull, // Caller attempted to insert data into a buffer that is // full. -} CTR_Code; +}; // VISA Error #define _VI_ERROR (-2147483647L - 1) @@ -108,7 +108,7 @@ typedef enum { * Represents the resulting status of a function call through its return value. * 0 is success, negative values are errors, and positive values are warnings. */ -typedef int32_t NiFpga_Status; // NOLINT +using NiFpga_Status = int32_t; // NOLINT /** * No errors or warnings. diff --git a/hal/src/main/native/sim/Interrupts.cpp b/hal/src/main/native/sim/Interrupts.cpp index 3772ab039d..8abf02ff75 100644 --- a/hal/src/main/native/sim/Interrupts.cpp +++ b/hal/src/main/native/sim/Interrupts.cpp @@ -60,7 +60,7 @@ struct SynchronousWaitData { static LimitedHandleResource* interruptHandles; -typedef HAL_Handle SynchronousWaitDataHandle; +using SynchronousWaitDataHandle = HAL_Handle; static UnlimitedHandleResource* synchronousInterruptHandles; diff --git a/ntcore/src/main/native/cpp/Dispatcher.h b/ntcore/src/main/native/cpp/Dispatcher.h index a2a742531e..51b8ec7059 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.h +++ b/ntcore/src/main/native/cpp/Dispatcher.h @@ -37,7 +37,7 @@ class DispatcherBase : public IDispatcher { friend class DispatcherTest; public: - typedef std::function()> Connector; + using Connector = std::function()>; DispatcherBase(IStorage& storage, IConnectionNotifier& notifier, wpi::Logger& logger); diff --git a/ntcore/src/main/native/cpp/Message.h b/ntcore/src/main/native/cpp/Message.h index 53e8aac487..ec34a75fc3 100644 --- a/ntcore/src/main/native/cpp/Message.h +++ b/ntcore/src/main/native/cpp/Message.h @@ -37,7 +37,7 @@ class Message { kExecuteRpc = 0x20, kRpcResponse = 0x21 }; - typedef std::function GetEntryTypeFunc; + using GetEntryTypeFunc = std::function; Message() = default; Message(MsgType type, const private_init&) : m_type(type) {} diff --git a/ntcore/src/main/native/cpp/NetworkConnection.h b/ntcore/src/main/native/cpp/NetworkConnection.h index e023320caf..59f18ff2d7 100644 --- a/ntcore/src/main/native/cpp/NetworkConnection.h +++ b/ntcore/src/main/native/cpp/NetworkConnection.h @@ -36,11 +36,10 @@ class IConnectionNotifier; class NetworkConnection : public INetworkConnection { public: - typedef std::function()> get_msg, - std::function>)> send_msgs)> - HandshakeFunc; + std::function>)> send_msgs)>; using ProcessIncomingFunc = std::function, NetworkConnection*)>; using Outgoing = std::vector>; diff --git a/ntcore/src/main/native/cpp/RpcServer.h b/ntcore/src/main/native/cpp/RpcServer.h index 4b830620f4..dbf2154ea8 100644 --- a/ntcore/src/main/native/cpp/RpcServer.h +++ b/ntcore/src/main/native/cpp/RpcServer.h @@ -19,7 +19,7 @@ namespace nt { namespace impl { -typedef std::pair RpcIdPair; +using RpcIdPair = std::pair; struct RpcNotifierData : public RpcAnswer { RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, std::string_view name_, diff --git a/ntcore/src/main/native/cpp/Storage.h b/ntcore/src/main/native/cpp/Storage.h index add675ebfd..f49c071340 100644 --- a/ntcore/src/main/native/cpp/Storage.h +++ b/ntcore/src/main/native/cpp/Storage.h @@ -197,7 +197,7 @@ class Storage : public IStorage { unsigned int rpc_call_uid{0}; }; - typedef wpi::StringMap EntriesMap; + using EntriesMap = wpi::StringMap; using IdMap = std::vector; using LocalMap = std::vector>; using RpcIdPair = std::pair; diff --git a/ntcore/src/main/native/cpp/Storage_load.cpp b/ntcore/src/main/native/cpp/Storage_load.cpp index fdc80a4334..11bbb0ed78 100644 --- a/ntcore/src/main/native/cpp/Storage_load.cpp +++ b/ntcore/src/main/native/cpp/Storage_load.cpp @@ -21,7 +21,7 @@ namespace { class LoadPersistentImpl { public: - typedef std::pair> Entry; + using Entry = std::pair>; using WarnFunc = std::function; LoadPersistentImpl(wpi::raw_istream& is, WarnFunc warn) diff --git a/ntcore/src/main/native/include/networktables/NetworkTableValue.h b/ntcore/src/main/native/include/networktables/NetworkTableValue.h index c8f73a19f3..fcb9cb59e0 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableValue.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableValue.h @@ -486,7 +486,7 @@ inline bool operator!=(const Value& lhs, const Value& rhs) { * NetworkTable Value alias for similarity with Java. * @ingroup ntcore_cpp_api */ -typedef Value NetworkTableValue; +using NetworkTableValue = Value; } // namespace nt diff --git a/ntcore/src/test/native/cpp/ValueTest.cpp b/ntcore/src/test/native/cpp/ValueTest.cpp index d28611cd56..fbfb647388 100644 --- a/ntcore/src/test/native/cpp/ValueTest.cpp +++ b/ntcore/src/test/native/cpp/ValueTest.cpp @@ -26,7 +26,7 @@ namespace nt { class ValueTest : public ::testing::Test {}; -typedef ValueTest ValueDeathTest; +using ValueDeathTest = ValueTest; TEST_F(ValueTest, ConstructEmpty) { Value v; diff --git a/simulation/frc_gazebo_plugins/src/clockTest/cpp/clockTest.cpp b/simulation/frc_gazebo_plugins/src/clockTest/cpp/clockTest.cpp index 7590d304aa..7d5f99afb9 100644 --- a/simulation/frc_gazebo_plugins/src/clockTest/cpp/clockTest.cpp +++ b/simulation/frc_gazebo_plugins/src/clockTest/cpp/clockTest.cpp @@ -22,7 +22,7 @@ void cb(gazebo::msgs::ConstFloat64Ptr& msg) { latest_time = msg->data(); } -TEST(ClockTests, test_clock) { +TEST(ClockTests, TestClock) { gazebo::physics::WorldPtr world; ASSERT_TRUE(library); diff --git a/simulation/frc_gazebo_plugins/src/gyro/headers/gyro.h b/simulation/frc_gazebo_plugins/src/gyro/headers/gyro.h index c26d525b61..adc332b4c3 100644 --- a/simulation/frc_gazebo_plugins/src/gyro/headers/gyro.h +++ b/simulation/frc_gazebo_plugins/src/gyro/headers/gyro.h @@ -13,7 +13,7 @@ #include "simulation/gz_msgs/msgs.h" /// \brief The axis about which to measure rotation. -typedef enum { Roll /*X*/, Pitch /*Y*/, Yaw /*Z*/ } ROTATION; +enum ROTATION { Roll /*X*/, Pitch /*Y*/, Yaw /*Z*/ }; /** * \brief Plugin for reading the speed and relative angle of a link. diff --git a/wpigui/src/main/native/directx11/wpigui_directx11.cpp b/wpigui/src/main/native/directx11/wpigui_directx11.cpp index 26e153a17c..771a2edc8f 100644 --- a/wpigui/src/main/native/directx11/wpigui_directx11.cpp +++ b/wpigui/src/main/native/directx11/wpigui_directx11.cpp @@ -243,8 +243,9 @@ void gui::DeleteTexture(ImTextureID texture) { if (!gPlatformValid) { return; } - if (texture) + if (texture) { static_cast(texture)->Release(); + } } } // namespace wpi diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index ab8bf896e1..baf4dc7456 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -24,7 +24,7 @@ #include "frc/livewindow/LiveWindow.h" #include "frc/smartdashboard/SmartDashboard.h" -typedef void (*SetCameraServerSharedFP)(frc::CameraServerShared* shared); +using SetCameraServerSharedFP = void (*)(frc::CameraServerShared*); using namespace frc; diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h b/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h index e5b0c62ea1..f3c7c5659c 100644 --- a/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h +++ b/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h @@ -14,8 +14,8 @@ namespace cs { class VideoSource; } // namespace cs -typedef int CS_Handle; -typedef CS_Handle CS_Source; +using CS_Handle = int; // NOLINT +using CS_Source = CS_Handle; // NOLINT #endif #include "frc/smartdashboard/Sendable.h" diff --git a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp index 1b7048decc..56fce2fba6 100644 --- a/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp +++ b/wpilibcIntegrationTests/src/main/native/cpp/TestEnvironment.cpp @@ -59,7 +59,7 @@ class TestEnvironment : public testing::Environment { } } - ~TestEnvironment() { m_mockDS.Stop(); } + ~TestEnvironment() override { m_mockDS.Stop(); } }; testing::Environment* const environment = diff --git a/wpiutil/src/main/native/include/wpi/CallbackManager.h b/wpiutil/src/main/native/include/wpi/CallbackManager.h index 4f1d952afe..c94321d50a 100644 --- a/wpiutil/src/main/native/include/wpi/CallbackManager.h +++ b/wpiutil/src/main/native/include/wpi/CallbackManager.h @@ -49,7 +49,7 @@ template class CallbackThread : public wpi::SafeThread { public: - typedef TUserInfo UserInfo; + using UserInfo = TUserInfo; using NotifierData = TNotifierData; using ListenerData = TListenerData; diff --git a/wpiutil/src/main/native/include/wpi/function_ref.h b/wpiutil/src/main/native/include/wpi/function_ref.h index 05654153d1..868c164fd2 100644 --- a/wpiutil/src/main/native/include/wpi/function_ref.h +++ b/wpiutil/src/main/native/include/wpi/function_ref.h @@ -37,19 +37,20 @@ class function_ref { template static Ret callback_fn(intptr_t callable, Params... params) { - return (*reinterpret_cast(callable))( - std::forward(params)...); + return (*reinterpret_cast(callable))(std::forward( + params)...); } public: function_ref() = default; - function_ref(std::nullptr_t) {} + /*implicit*/ function_ref(std::nullptr_t) {} // NOLINT template - function_ref(Callable&& callable, - typename std::enable_if< - !std::is_same::type, - function_ref>::value>::type* = nullptr) + /*implicit*/ function_ref( // NOLINT + Callable&& callable, + typename std::enable_if< + !std::is_same::type, + function_ref>::value>::type* = nullptr) : callback(callback_fn::type>), callable(reinterpret_cast(&callable)) {}