From f683743ca6727d003a30c998ca617e31d9523e3d Mon Sep 17 00:00:00 2001 From: Derek Argueta Date: Mon, 8 Jul 2019 09:44:36 -0700 Subject: [PATCH] Fix clang-tidy (#7475) Signed-off-by: Derek Argueta --- .clang-tidy | 4 ++-- ci/run_clang_tidy.sh | 6 ++++++ source/common/grpc/common.cc | 2 +- source/common/stats/thread_local_store.cc | 2 +- source/common/upstream/outlier_detection_impl.cc | 2 +- test/common/protobuf/utility_test.cc | 2 +- .../quic_listeners/quiche/platform/quic_platform_test.cc | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index d58e0a8be486..0692d1c459ee 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,8 +5,8 @@ Checks: 'abseil-*, modernize-*, performance-*, readability-braces-around-statements, - readability-container-size-empty' - readability-redundant-*, + readability-container-size-empty, + readability-redundant-*' #TODO(lizan): grow this list, fix possible warnings and make more checks as error WarningsAsErrors: 'abseil-duration-*, diff --git a/ci/run_clang_tidy.sh b/ci/run_clang_tidy.sh index 8adbbd5089d8..dc0e8aead732 100755 --- a/ci/run_clang_tidy.sh +++ b/ci/run_clang_tidy.sh @@ -2,6 +2,12 @@ set -e +# Quick syntax check of .clang-tidy using PyYAML. +if ! python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < .clang-tidy > /dev/null; then + echo ".clang-tidy has a syntax error" + exit 1 +fi + echo "Generating compilation database..." cp -f .bazelrc .bazelrc.bak diff --git a/source/common/grpc/common.cc b/source/common/grpc/common.cc index d70c86ba5343..2683044b715c 100644 --- a/source/common/grpc/common.cc +++ b/source/common/grpc/common.cc @@ -54,7 +54,7 @@ absl::optional Common::getGrpcStatus(const Http::HeaderMap& uint64_t grpc_status_code; if (!grpc_status_header || grpc_status_header->value().empty()) { - return absl::optional(); + return {}; } if (!absl::SimpleAtoi(grpc_status_header->value().getStringView(), &grpc_status_code) || grpc_status_code > Status::GrpcStatus::MaximumValid) { diff --git a/source/common/stats/thread_local_store.cc b/source/common/stats/thread_local_store.cc index 91603ad79083..6de61634cd10 100644 --- a/source/common/stats/thread_local_store.cc +++ b/source/common/stats/thread_local_store.cc @@ -368,7 +368,7 @@ ThreadLocalStoreImpl::ScopeImpl::findStatLockHeld( return absl::nullopt; } - return std::cref(*iter->second.get()); + return std::cref(*iter->second); } Counter& ThreadLocalStoreImpl::ScopeImpl::counterFromStatName(StatName name) { diff --git a/source/common/upstream/outlier_detection_impl.cc b/source/common/upstream/outlier_detection_impl.cc index 948cbb1f361f..0d0efa147366 100644 --- a/source/common/upstream/outlier_detection_impl.cc +++ b/source/common/upstream/outlier_detection_impl.cc @@ -710,7 +710,7 @@ SuccessRateAccumulatorBucket* SuccessRateAccumulator::updateCurrentWriter() { absl::optional SuccessRateAccumulator::getSuccessRate(uint64_t success_rate_request_volume) { if (backup_success_rate_bucket_->total_request_counter_ < success_rate_request_volume) { - return absl::optional(); + return {}; } return {backup_success_rate_bucket_->success_request_counter_ * 100.0 / diff --git a/test/common/protobuf/utility_test.cc b/test/common/protobuf/utility_test.cc index 99a7dcb607fd..04fb200fc075 100644 --- a/test/common/protobuf/utility_test.cc +++ b/test/common/protobuf/utility_test.cc @@ -295,7 +295,7 @@ TEST_F(ProtobufUtilityTest, HashedValue) { EXPECT_EQ(hv1, hv2); EXPECT_NE(hv1, hv3); - HashedValue copy(hv1); + HashedValue copy(hv1); // NOLINT(performance-unnecessary-copy-initialization) EXPECT_EQ(hv1, copy); } diff --git a/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc index 529ce889c7ae..8fcb0ff33365 100644 --- a/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc +++ b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc @@ -755,7 +755,7 @@ TEST_P(QuicMemSliceTest, ConstructMemSliceFromBuffer) { quic::QuicMemSlice slice1{quic::QuicMemSliceImpl(buffer, str2.length())}; EXPECT_EQ(str.length(), buffer.length()); EXPECT_EQ(str2, std::string(slice1.data(), slice1.length())); - std::string str2_old = str2; + std::string str2_old = str2; // NOLINT(performance-unnecessary-copy-initialization) // slice1 is released, but str2 should not be affected. slice1.Reset(); EXPECT_TRUE(slice1.empty());