From b856c0ba9c564050cf0449d2b34d21f56c9862ae Mon Sep 17 00:00:00 2001 From: Christoph Bachhuber Date: Sat, 18 Jan 2020 14:53:45 +0100 Subject: [PATCH] Add cpplint to CI (#400) * Add cpplint config file * Add cpplint to CI * Add checks * Add docker container tag * Unindent container As suggested in code review Co-Authored-By: Henry Schreiner * Fix cpplint issues * Fix clang-format * Include and fix modern cpplint runtime/int * Include and fix cpplint build/include_order * Revert "Include and fix cpplint build/include_order" This reverts commit bddb6a2d6744c5397f387ccd03416a1ec5e29862. * Update explanation, sort alphabetically * Implement suggestion from code review Co-Authored-By: Henry Schreiner * Include cstdint header, prefix its symbols with std:: * Forgot std:: Co-authored-by: Henry Schreiner --- CPPLINT.cfg | 14 ++++++++++++++ azure-pipelines.yml | 9 ++++++++- examples/subcom_in_files/subcommand_a.hpp | 1 + include/CLI/App.hpp | 4 +--- include/CLI/Timer.hpp | 7 ++++--- include/CLI/TypeTools.hpp | 9 +++++---- include/CLI/Validators.hpp | 2 +- 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 CPPLINT.cfg diff --git a/CPPLINT.cfg b/CPPLINT.cfg new file mode 100644 index 00000000..0b5f205f --- /dev/null +++ b/CPPLINT.cfg @@ -0,0 +1,14 @@ +set noparent +linelength=120 # As in .clang-format + +# Non-used filters +filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers +filter=-readability/nolint # Conficts with clang-tidy +filter=-runtime/references # Requires fundamental change of API, don't see need for this +filter=-whitespace/blank_line # Unnecessarily strict with blank lines that otherwise help with readability +filter=-whitespace/parens,-whitespace/braces # Conflict with clang-format + +# Filters to be included in future +filter=-whitespace/indent,-whitespace/comments,-readability/braces,-build/include_what_you_use +filter=-legal/copyright # Remove this line after Version 1.9 + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bd4e4269..d01a2406 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,6 +31,14 @@ jobs: - script: git diff --exit-code --color displayName: Check tidy +- job: CppLint + pool: + vmImage: 'ubuntu-latest' + container: sharaku/cpplint:latest + steps: + - bash: cpplint --counting=detailed --recursive examples include/CLI + displayName: Checking against google style guide + # TODO: Fix macOS error and windows warning in c++17 mode - job: Native strategy: @@ -97,4 +105,3 @@ jobs: - template: .ci/azure-cmake.yml - template: .ci/azure-build.yml - template: .ci/azure-test.yml - diff --git a/examples/subcom_in_files/subcommand_a.hpp b/examples/subcom_in_files/subcommand_a.hpp index 90625650..f05d6bf6 100644 --- a/examples/subcom_in_files/subcommand_a.hpp +++ b/examples/subcom_in_files/subcommand_a.hpp @@ -1,3 +1,4 @@ +#pragma once // =================================================================== // subcommand_a.hpp // =================================================================== diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 5c616378..16e78ee6 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -2657,9 +2657,7 @@ class App { auto res = op->get_flag_value(arg_name, value); op->add_result(res); parse_order_.push_back(op.get()); - } - // --this=value - else if(!value.empty()) { + } else if(!value.empty()) { // --this=value op->add_result(value, result_count); parse_order_.push_back(op.get()); collected += result_count; diff --git a/include/CLI/Timer.hpp b/include/CLI/Timer.hpp index 683839d0..cc2ba8b3 100644 --- a/include/CLI/Timer.hpp +++ b/include/CLI/Timer.hpp @@ -10,7 +10,7 @@ #endif #include -#include +#include // NOLINT(build/c++11) #include #include #include @@ -87,8 +87,9 @@ class Timer { /// This prints out a time string from a time std::string make_time_str(double time) const { auto print_it = [](double x, std::string unit) { - std::array buffer; - std::snprintf(buffer.data(), 50, "%.5g", x); + const unsigned int buffer_length = 50; + std::array buffer; + std::snprintf(buffer.data(), buffer_length, "%.5g", x); return buffer.data() + std::string(" ") + unit; }; diff --git a/include/CLI/TypeTools.hpp b/include/CLI/TypeTools.hpp index 3438e573..fd4542a6 100644 --- a/include/CLI/TypeTools.hpp +++ b/include/CLI/TypeTools.hpp @@ -4,6 +4,7 @@ // file LICENSE or https://github.com/CLIUtils/CLI11 for details. #include "StringTools.hpp" +#include #include #include #include @@ -595,9 +596,9 @@ template (output_ll); - return n == input.size() && static_cast(output) == output_ll; + return n == input.size() && static_cast(output) == output_ll; } catch(const std::invalid_argument &) { return false; } catch(const std::out_of_range &) { @@ -614,9 +615,9 @@ bool lexical_cast(const std::string &input, T &output) { try { std::size_t n = 0; - unsigned long long output_ll = std::stoull(input, &n, 0); + std::uint64_t output_ll = std::stoull(input, &n, 0); output = static_cast(output_ll); - return n == input.size() && static_cast(output) == output_ll; + return n == input.size() && static_cast(output) == output_ll; } catch(const std::invalid_argument &) { return false; } catch(const std::out_of_range &) { diff --git a/include/CLI/Validators.hpp b/include/CLI/Validators.hpp index 90dfed65..937f9c27 100644 --- a/include/CLI/Validators.hpp +++ b/include/CLI/Validators.hpp @@ -35,7 +35,7 @@ #endif #if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 -#include +#include // NOLINT(build/include) #else #include #include