From 0c83cad70cef2a0610a168dcc98e7e03aff4606e Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 11 Nov 2017 22:09:51 -0800 Subject: [PATCH] Upgraded clang-format to 5.0 (#431) --- .clang-format | 22 ++++++- .travis.yml | 11 +++- hal/src/main/native/athena/Interrupts.cpp | 8 +-- hal/src/main/native/include/HAL/cpp/Log.h | 2 +- .../handles/IndexedClassedHandleResource.h | 5 +- .../handles/LimitedClassedHandleResource.h | 5 +- .../main/native/cpp/Commands/PIDSubsystem.cpp | 4 +- wpilibc/src/main/native/cpp/Counter.cpp | 5 +- wpilibc/src/main/native/cpp/DigitalOutput.cpp | 8 +-- .../native/cpp/InterruptableSensorBase.cpp | 2 +- .../main/native/cpp/LiveWindow/LiveWindow.cpp | 15 +++-- .../cpp/SmartDashboard/SmartDashboard.cpp | 58 +++++++++---------- .../src/FRCUserProgram/cpp/NotifierTest.cpp | 4 +- .../FRCUserProgram/cpp/PIDToleranceTest.cpp | 6 +- .../FRCUserProgram/cpp/TiltPanCameraTest.cpp | 8 +-- 15 files changed, 96 insertions(+), 67 deletions(-) diff --git a/.clang-format b/.clang-format index 98dfa4e46e..92b40492f0 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,7 @@ AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: true +AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: true @@ -32,12 +32,20 @@ BraceWrapping: BeforeCatch: false BeforeElse: false IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 @@ -45,7 +53,11 @@ Cpp11BracedListStyle: true DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH IncludeCategories: - Regex: '^<.*\.h>' Priority: 1 @@ -53,9 +65,12 @@ IncludeCategories: Priority: 2 - Regex: '.*' Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' IndentCaseLabels: true IndentWidth: 2 IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' MacroBlockEnd: '' @@ -64,6 +79,7 @@ NamespaceIndentation: None ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false +PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 @@ -73,7 +89,9 @@ PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left ReflowComments: true SortIncludes: false +SortUsingDeclarations: true SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false diff --git a/.travis.yml b/.travis.yml index 9eb5e91bc2..2f21d8960e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -sudo: false +sudo: true dist: trusty language: java @@ -10,7 +10,12 @@ addons: - g++-6 - python3 - python3-pip - - clang-format-3.8 + +before_install: + - sudo sh -c 'echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main" > /etc/apt/sources.list.d/llvm.list' + - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - + - sudo apt-get update -q || true + - sudo apt-get install clang-format-5.0 -y install: - pip3 install --user wpiformat @@ -28,6 +33,6 @@ cache: - $HOME/.gradle/wrapper/ script: - - wpiformat -y 2017 -clang 3.8 + - wpiformat -y 2017 -clang 5.0 - git --no-pager diff --exit-code HEAD # Ensure formatter made no changes - ./gradlew --no-daemon --console=plain -PskipAthena :hal:halSimSharedLibrary :wpilibc:wpilibcSharedLibrary :wpilibj:wpilibJNISharedSharedLibrary :wpilibj:jar diff --git a/hal/src/main/native/athena/Interrupts.cpp b/hal/src/main/native/athena/Interrupts.cpp index a38192192b..88be145c0d 100644 --- a/hal/src/main/native/athena/Interrupts.cpp +++ b/hal/src/main/native/athena/Interrupts.cpp @@ -178,10 +178,10 @@ double HAL_ReadInterruptRisingTimestamp(HAL_InterruptHandle interruptHandle, } /** -* Return the timestamp for the falling interrupt that occurred most recently. -* This is in the same time domain as GetClock(). -* @return Timestamp in seconds since boot. -*/ + * Return the timestamp for the falling interrupt that occurred most recently. + * This is in the same time domain as GetClock(). + * @return Timestamp in seconds since boot. + */ double HAL_ReadInterruptFallingTimestamp(HAL_InterruptHandle interruptHandle, int32_t* status) { auto anInterrupt = interruptHandles.Get(interruptHandle); diff --git a/hal/src/main/native/include/HAL/cpp/Log.h b/hal/src/main/native/include/HAL/cpp/Log.h index 705c2a9dd9..f4c6e9613e 100644 --- a/hal/src/main/native/include/HAL/cpp/Log.h +++ b/hal/src/main/native/include/HAL/cpp/Log.h @@ -96,7 +96,7 @@ typedef Log FILELog; if (level > FILELog::ReportingLevel()) \ ; \ else \ - Log().Get(level) + Log().Get(level) inline std::string NowTime() { llvm::SmallString<128> buf; diff --git a/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h b/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h index 2d3ca0f0b6..bfe03e8a68 100644 --- a/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h @@ -84,8 +84,9 @@ IndexedClassedHandleResource::Allocate( template -std::shared_ptr IndexedClassedHandleResource< - THandle, TStruct, size, enumValue>::Get(THandle handle) { +std::shared_ptr +IndexedClassedHandleResource::Get( + THandle handle) { // get handle index, and fail early if index out of range or wrong handle int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) { diff --git a/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h b/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h index ac68b36b74..e2c7eef568 100644 --- a/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h @@ -73,8 +73,9 @@ LimitedClassedHandleResource::Allocate( template -std::shared_ptr LimitedClassedHandleResource< - THandle, TStruct, size, enumValue>::Get(THandle handle) { +std::shared_ptr +LimitedClassedHandleResource::Get( + THandle handle) { // get handle index, and fail early if index out of range or wrong handle int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) { diff --git a/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp b/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp index 095c9e1fbc..d651f6abbb 100644 --- a/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp +++ b/wpilibc/src/main/native/cpp/Commands/PIDSubsystem.cpp @@ -120,8 +120,8 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d, double f, void PIDSubsystem::Enable() { m_controller->Enable(); } /** - * Disables the internal {@link PIDController}. - */ + * Disables the internal {@link PIDController}. + */ void PIDSubsystem::Disable() { m_controller->Disable(); } /** diff --git a/wpilibc/src/main/native/cpp/Counter.cpp b/wpilibc/src/main/native/cpp/Counter.cpp index 4cbbb80fba..f482ac4fde 100644 --- a/wpilibc/src/main/native/cpp/Counter.cpp +++ b/wpilibc/src/main/native/cpp/Counter.cpp @@ -116,8 +116,9 @@ Counter::Counter(const AnalogTrigger& trigger) : Counter(kTwoPulse) { */ Counter::Counter(EncodingType encodingType, DigitalSource* upSource, DigitalSource* downSource, bool inverted) - : Counter(encodingType, std::shared_ptr( - upSource, NullDeleter()), + : Counter(encodingType, + std::shared_ptr(upSource, + NullDeleter()), std::shared_ptr(downSource, NullDeleter()), inverted) {} diff --git a/wpilibc/src/main/native/cpp/DigitalOutput.cpp b/wpilibc/src/main/native/cpp/DigitalOutput.cpp index c2cddfa3c4..2e0c00d910 100644 --- a/wpilibc/src/main/native/cpp/DigitalOutput.cpp +++ b/wpilibc/src/main/native/cpp/DigitalOutput.cpp @@ -81,10 +81,10 @@ void DigitalOutput::Set(bool value) { } /** - * Gets the value being output from the Digital Output. - * - * @return the state of the digital output. - */ + * Gets the value being output from the Digital Output. + * + * @return the state of the digital output. + */ bool DigitalOutput::Get() const { if (StatusIsFatal()) return false; diff --git a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp index cccc687850..65883ea481 100644 --- a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp +++ b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp @@ -168,7 +168,7 @@ double InterruptableSensorBase::ReadRisingTimestamp() { * {@link #DigitalInput.SetUpSourceEdge} * * @return Timestamp in seconds since boot. -*/ + */ double InterruptableSensorBase::ReadFallingTimestamp() { if (StatusIsFatal()) return 0.0; wpi_assert(m_interrupt != HAL_kInvalidHandle); diff --git a/wpilibc/src/main/native/cpp/LiveWindow/LiveWindow.cpp b/wpilibc/src/main/native/cpp/LiveWindow/LiveWindow.cpp index 1442ae8250..6af46505d6 100644 --- a/wpilibc/src/main/native/cpp/LiveWindow/LiveWindow.cpp +++ b/wpilibc/src/main/native/cpp/LiveWindow/LiveWindow.cpp @@ -94,8 +94,9 @@ void LiveWindow::AddSensor(const std::string& subsystem, void LiveWindow::AddSensor(const std::string& subsystem, const std::string& name, LiveWindowSendable& component) { - AddSensor(subsystem, name, std::shared_ptr( - &component, [](LiveWindowSendable*) {})); + AddSensor(subsystem, name, + std::shared_ptr(&component, + [](LiveWindowSendable*) {})); } /** @@ -105,8 +106,9 @@ void LiveWindow::AddSensor(const std::string& subsystem, void LiveWindow::AddSensor(const std::string& subsystem, const std::string& name, LiveWindowSendable* component) { - AddSensor(subsystem, name, std::shared_ptr( - component, NullDeleter())); + AddSensor(subsystem, name, + std::shared_ptr( + component, NullDeleter())); } //@} @@ -137,8 +139,9 @@ void LiveWindow::AddActuator(const std::string& subsystem, void LiveWindow::AddActuator(const std::string& subsystem, const std::string& name, LiveWindowSendable& component) { - AddActuator(subsystem, name, std::shared_ptr( - &component, [](LiveWindowSendable*) {})); + AddActuator(subsystem, name, + std::shared_ptr(&component, + [](LiveWindowSendable*) {})); } /** diff --git a/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp b/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp index 688be42d86..8a5bfc84b0 100644 --- a/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp +++ b/wpilibc/src/main/native/cpp/SmartDashboard/SmartDashboard.cpp @@ -27,11 +27,11 @@ void SmartDashboard::init() { } /** - * Determines whether the given key is in this table. - * - * @param key the key to search for - * @return true if the table as a value assigned to the given key - */ + * Determines whether the given key is in this table. + * + * @param key the key to search for + * @return true if the table as a value assigned to the given key + */ bool SmartDashboard::ContainsKey(llvm::StringRef key) { return s_table->ContainsKey(key); } @@ -182,11 +182,11 @@ bool SmartDashboard::PutValue(llvm::StringRef keyName, } /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ + * Gets the current value in the table, setting it if it does not exist. + * @param key the key + * @param defaultValue the default value to set if key doesn't exist. + * @returns False if the table key exists with a different type + */ bool SmartDashboard::SetDefaultValue(llvm::StringRef key, std::shared_ptr defaultValue) { return s_table->GetEntry(key).SetDefaultValue(defaultValue); @@ -218,11 +218,11 @@ bool SmartDashboard::PutBoolean(llvm::StringRef keyName, bool value) { } /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ + * Gets the current value in the table, setting it if it does not exist. + * @param key the key + * @param defaultValue the default value to set if key doesn't exist. + * @returns False if the table key exists with a different type + */ bool SmartDashboard::SetDefaultBoolean(llvm::StringRef key, bool defaultValue) { return s_table->GetEntry(key).SetDefaultBoolean(defaultValue); } @@ -254,11 +254,11 @@ bool SmartDashboard::PutNumber(llvm::StringRef keyName, double value) { } /** - * Gets the current value in the table, setting it if it does not exist. - * @param key the key - * @param defaultValue the default value to set if key doesn't exist. - * @returns False if the table key exists with a different type - */ + * Gets the current value in the table, setting it if it does not exist. + * @param key the key + * @param defaultValue the default value to set if key doesn't exist. + * @returns False if the table key exists with a different type + */ bool SmartDashboard::SetDefaultNumber(llvm::StringRef key, double defaultValue) { return s_table->GetEntry(key).SetDefaultDouble(defaultValue); @@ -315,15 +315,15 @@ std::string SmartDashboard::GetString(llvm::StringRef keyName, } /** - * Put a boolean array in the table - * @param key the key to be assigned to - * @param value the value that will be assigned - * @return False if the table key already exists with a different type - * - * @note The array must be of int's rather than of bool's because - * std::vector is special-cased in C++. 0 is false, any - * non-zero value is true. - */ + * Put a boolean array in the table + * @param key the key to be assigned to + * @param value the value that will be assigned + * @return False if the table key already exists with a different type + * + * @note The array must be of int's rather than of bool's because + * std::vector is special-cased in C++. 0 is false, any + * non-zero value is true. + */ bool SmartDashboard::PutBooleanArray(llvm::StringRef key, llvm::ArrayRef value) { return s_table->GetEntry(key).SetBooleanArray(value); diff --git a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/NotifierTest.cpp b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/NotifierTest.cpp index 9a6a1fdb99..e247882845 100644 --- a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/NotifierTest.cpp +++ b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/NotifierTest.cpp @@ -34,8 +34,8 @@ TEST(NotifierTest, DISABLED_TestTimerNotifications) { Wait(10.5); llvm::outs() << "...Wait\n"; - EXPECT_EQ(10u, notifierCounter) << "Received " << notifierCounter - << " notifications in 10.5 seconds"; + EXPECT_EQ(10u, notifierCounter) + << "Received " << notifierCounter << " notifications in 10.5 seconds"; llvm::outs() << "Received " << notifierCounter << " notifications in 10.5 seconds"; diff --git a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/PIDToleranceTest.cpp b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/PIDToleranceTest.cpp index edd20762d4..01a9c111e7 100644 --- a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/PIDToleranceTest.cpp +++ b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/PIDToleranceTest.cpp @@ -86,9 +86,9 @@ TEST_F(PIDToleranceTest, Percent) { << "Error was in tolerance when it should not have been. Error was " << pid->GetAvgError(); - inp.val = setpoint + - (tolerance) / 200 * - range; // half of percent tolerance away from setpoint + inp.val = + setpoint + (tolerance) / 200 * + range; // half of percent tolerance away from setpoint Wait(1.0); EXPECT_TRUE(pid->OnTarget()) diff --git a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/TiltPanCameraTest.cpp b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/TiltPanCameraTest.cpp index 7ed7e8f806..18b40ac085 100644 --- a/wpilibcIntegrationTests/src/FRCUserProgram/cpp/TiltPanCameraTest.cpp +++ b/wpilibcIntegrationTests/src/FRCUserProgram/cpp/TiltPanCameraTest.cpp @@ -103,10 +103,10 @@ void TiltPanCameraTest::GyroAngle() { } /** - * Gets calibrated parameters from previously calibrated gyro, allocates a new - * gyro with the given parameters for center and offset, and re-runs tests on - * the new gyro. - */ + * Gets calibrated parameters from previously calibrated gyro, allocates a new + * gyro with the given parameters for center and offset, and re-runs tests on + * the new gyro. + */ void TiltPanCameraTest::GyroCalibratedParameters() { uint32_t cCenter = m_gyro->GetCenter(); double cOffset = m_gyro->GetOffset();