[build] Upgrade clang-format and clang-tidy (NFC) (#3422)

This commit is contained in:
Tyler Veness
2021-06-10 11:13:09 -07:00
committed by GitHub
parent 099fde97d5
commit a77c6ff3a2
29 changed files with 66 additions and 48 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -2154,7 +2154,7 @@ struct LogMessage {
std::string m_msg;
};
typedef JSingletonCallbackManager<LogMessage> LoggerJNI;
using LoggerJNI = JSingletonCallbackManager<LogMessage>;
} // namespace

View File

@@ -14,7 +14,7 @@
/**
* Raw Frame
*/
typedef struct CS_RawFrame {
typedef struct CS_RawFrame { // NOLINT
char* data;
int dataLength;
int pixelFormat;

View File

@@ -9,6 +9,8 @@
#error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file"
#endif
#include <opencv2/core/mat.hpp>
#include "cscore_raw.h"
namespace cs {

View File

@@ -533,8 +533,9 @@ bool UsbCameraImpl::CacheProperties(CS_Status* status) const {
auto result = m_messagePump->SendWindowMessage<CS_Status>(
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);

View File

@@ -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;

View File

@@ -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<uint32_t>(durMs) / 10, static_cast<uint32_t>(0xFF));
pcm->oneShot.sol10MsPerUnit[index] =
(std::min)(static_cast<uint32_t>(durMs) / 10,
static_cast<uint32_t>(0xFF));
HAL_WriteCANPacketRepeating(pcm->canHandle, pcm->oneShot.sol10MsPerUnit, 8,
Control2, SendPeriod, status);
}

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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();

View File

@@ -6,7 +6,7 @@
#include <stdint.h>
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.

View File

@@ -60,7 +60,7 @@ struct SynchronousWaitData {
static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
HAL_HandleEnum::Interrupt>* interruptHandles;
typedef HAL_Handle SynchronousWaitDataHandle;
using SynchronousWaitDataHandle = HAL_Handle;
static UnlimitedHandleResource<SynchronousWaitDataHandle, SynchronousWaitData,
HAL_HandleEnum::Vendor>*
synchronousInterruptHandles;

View File

@@ -37,7 +37,7 @@ class DispatcherBase : public IDispatcher {
friend class DispatcherTest;
public:
typedef std::function<std::unique_ptr<wpi::NetworkStream>()> Connector;
using Connector = std::function<std::unique_ptr<wpi::NetworkStream>()>;
DispatcherBase(IStorage& storage, IConnectionNotifier& notifier,
wpi::Logger& logger);

View File

@@ -37,7 +37,7 @@ class Message {
kExecuteRpc = 0x20,
kRpcResponse = 0x21
};
typedef std::function<NT_Type(unsigned int id)> GetEntryTypeFunc;
using GetEntryTypeFunc = std::function<NT_Type(unsigned int id)>;
Message() = default;
Message(MsgType type, const private_init&) : m_type(type) {}

View File

@@ -36,11 +36,10 @@ class IConnectionNotifier;
class NetworkConnection : public INetworkConnection {
public:
typedef std::function<bool(
using HandshakeFunc = std::function<bool(
NetworkConnection& conn,
std::function<std::shared_ptr<Message>()> get_msg,
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs)>
HandshakeFunc;
std::function<void(wpi::span<std::shared_ptr<Message>>)> send_msgs)>;
using ProcessIncomingFunc =
std::function<void(std::shared_ptr<Message>, NetworkConnection*)>;
using Outgoing = std::vector<std::shared_ptr<Message>>;

View File

@@ -19,7 +19,7 @@ namespace nt {
namespace impl {
typedef std::pair<unsigned int, unsigned int> RpcIdPair;
using RpcIdPair = std::pair<unsigned int, unsigned int>;
struct RpcNotifierData : public RpcAnswer {
RpcNotifierData(NT_Entry entry_, NT_RpcCall call_, std::string_view name_,

View File

@@ -197,7 +197,7 @@ class Storage : public IStorage {
unsigned int rpc_call_uid{0};
};
typedef wpi::StringMap<Entry*> EntriesMap;
using EntriesMap = wpi::StringMap<Entry*>;
using IdMap = std::vector<Entry*>;
using LocalMap = std::vector<std::unique_ptr<Entry>>;
using RpcIdPair = std::pair<unsigned int, unsigned int>;

View File

@@ -21,7 +21,7 @@ namespace {
class LoadPersistentImpl {
public:
typedef std::pair<std::string, std::shared_ptr<Value>> Entry;
using Entry = std::pair<std::string, std::shared_ptr<Value>>;
using WarnFunc = std::function<void(size_t, const char*)>;
LoadPersistentImpl(wpi::raw_istream& is, WarnFunc warn)

View File

@@ -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

View File

@@ -26,7 +26,7 @@ namespace nt {
class ValueTest : public ::testing::Test {};
typedef ValueTest ValueDeathTest;
using ValueDeathTest = ValueTest;
TEST_F(ValueTest, ConstructEmpty) {
Value v;

View File

@@ -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);

View File

@@ -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.

View File

@@ -243,8 +243,9 @@ void gui::DeleteTexture(ImTextureID texture) {
if (!gPlatformValid) {
return;
}
if (texture)
if (texture) {
static_cast<ID3D11ShaderResourceView*>(texture)->Release();
}
}
} // namespace wpi

View File

@@ -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;

View File

@@ -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"

View File

@@ -59,7 +59,7 @@ class TestEnvironment : public testing::Environment {
}
}
~TestEnvironment() { m_mockDS.Stop(); }
~TestEnvironment() override { m_mockDS.Stop(); }
};
testing::Environment* const environment =

View File

@@ -49,7 +49,7 @@ template <typename Derived, typename TUserInfo,
typename TNotifierData = TUserInfo>
class CallbackThread : public wpi::SafeThread {
public:
typedef TUserInfo UserInfo;
using UserInfo = TUserInfo;
using NotifierData = TNotifierData;
using ListenerData = TListenerData;

View File

@@ -37,19 +37,20 @@ class function_ref<Ret(Params...)> {
template <typename Callable>
static Ret callback_fn(intptr_t callable, Params... params) {
return (*reinterpret_cast<Callable*>(callable))(
std::forward<Params>(params)...);
return (*reinterpret_cast<Callable*>(callable))(std::forward<Params>(
params)...);
}
public:
function_ref() = default;
function_ref(std::nullptr_t) {}
/*implicit*/ function_ref(std::nullptr_t) {} // NOLINT
template <typename Callable>
function_ref(Callable&& callable,
typename std::enable_if<
!std::is_same<typename std::remove_reference<Callable>::type,
function_ref>::value>::type* = nullptr)
/*implicit*/ function_ref( // NOLINT
Callable&& callable,
typename std::enable_if<
!std::is_same<typename std::remove_reference<Callable>::type,
function_ref>::value>::type* = nullptr)
: callback(callback_fn<typename std::remove_reference<Callable>::type>),
callable(reinterpret_cast<intptr_t>(&callable)) {}