Commit b856c0ba9c564050cf0449d2b34d21f56c9862ae
Committed by
Henry Schreiner
1 parent
93c90d1d
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 <HenrySchreinerIII@gmail.com> * 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 <HenrySchreinerIII@gmail.com> * Include cstdint header, prefix its symbols with std:: * Forgot std:: Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
Showing
7 changed files
with
34 additions
and
12 deletions
CPPLINT.cfg
0 → 100644
| 1 | +set noparent | ||
| 2 | +linelength=120 # As in .clang-format | ||
| 3 | + | ||
| 4 | +# Non-used filters | ||
| 5 | +filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers | ||
| 6 | +filter=-readability/nolint # Conficts with clang-tidy | ||
| 7 | +filter=-runtime/references # Requires fundamental change of API, don't see need for this | ||
| 8 | +filter=-whitespace/blank_line # Unnecessarily strict with blank lines that otherwise help with readability | ||
| 9 | +filter=-whitespace/parens,-whitespace/braces # Conflict with clang-format | ||
| 10 | + | ||
| 11 | +# Filters to be included in future | ||
| 12 | +filter=-whitespace/indent,-whitespace/comments,-readability/braces,-build/include_what_you_use | ||
| 13 | +filter=-legal/copyright # Remove this line after Version 1.9 | ||
| 14 | + |
azure-pipelines.yml
| @@ -31,6 +31,14 @@ jobs: | @@ -31,6 +31,14 @@ jobs: | ||
| 31 | - script: git diff --exit-code --color | 31 | - script: git diff --exit-code --color |
| 32 | displayName: Check tidy | 32 | displayName: Check tidy |
| 33 | 33 | ||
| 34 | +- job: CppLint | ||
| 35 | + pool: | ||
| 36 | + vmImage: 'ubuntu-latest' | ||
| 37 | + container: sharaku/cpplint:latest | ||
| 38 | + steps: | ||
| 39 | + - bash: cpplint --counting=detailed --recursive examples include/CLI | ||
| 40 | + displayName: Checking against google style guide | ||
| 41 | + | ||
| 34 | # TODO: Fix macOS error and windows warning in c++17 mode | 42 | # TODO: Fix macOS error and windows warning in c++17 mode |
| 35 | - job: Native | 43 | - job: Native |
| 36 | strategy: | 44 | strategy: |
| @@ -97,4 +105,3 @@ jobs: | @@ -97,4 +105,3 @@ jobs: | ||
| 97 | - template: .ci/azure-cmake.yml | 105 | - template: .ci/azure-cmake.yml |
| 98 | - template: .ci/azure-build.yml | 106 | - template: .ci/azure-build.yml |
| 99 | - template: .ci/azure-test.yml | 107 | - template: .ci/azure-test.yml |
| 100 | - |
examples/subcom_in_files/subcommand_a.hpp
| 1 | +#pragma once | ||
| 1 | // =================================================================== | 2 | // =================================================================== |
| 2 | // subcommand_a.hpp | 3 | // subcommand_a.hpp |
| 3 | // =================================================================== | 4 | // =================================================================== |
include/CLI/App.hpp
| @@ -2657,9 +2657,7 @@ class App { | @@ -2657,9 +2657,7 @@ class App { | ||
| 2657 | auto res = op->get_flag_value(arg_name, value); | 2657 | auto res = op->get_flag_value(arg_name, value); |
| 2658 | op->add_result(res); | 2658 | op->add_result(res); |
| 2659 | parse_order_.push_back(op.get()); | 2659 | parse_order_.push_back(op.get()); |
| 2660 | - } | ||
| 2661 | - // --this=value | ||
| 2662 | - else if(!value.empty()) { | 2660 | + } else if(!value.empty()) { // --this=value |
| 2663 | op->add_result(value, result_count); | 2661 | op->add_result(value, result_count); |
| 2664 | parse_order_.push_back(op.get()); | 2662 | parse_order_.push_back(op.get()); |
| 2665 | collected += result_count; | 2663 | collected += result_count; |
include/CLI/Timer.hpp
| @@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
| 10 | #endif | 10 | #endif |
| 11 | 11 | ||
| 12 | #include <array> | 12 | #include <array> |
| 13 | -#include <chrono> | 13 | +#include <chrono> // NOLINT(build/c++11) |
| 14 | #include <functional> | 14 | #include <functional> |
| 15 | #include <iostream> | 15 | #include <iostream> |
| 16 | #include <string> | 16 | #include <string> |
| @@ -87,8 +87,9 @@ class Timer { | @@ -87,8 +87,9 @@ class Timer { | ||
| 87 | /// This prints out a time string from a time | 87 | /// This prints out a time string from a time |
| 88 | std::string make_time_str(double time) const { | 88 | std::string make_time_str(double time) const { |
| 89 | auto print_it = [](double x, std::string unit) { | 89 | auto print_it = [](double x, std::string unit) { |
| 90 | - std::array<char, 50> buffer; | ||
| 91 | - std::snprintf(buffer.data(), 50, "%.5g", x); | 90 | + const unsigned int buffer_length = 50; |
| 91 | + std::array<char, buffer_length> buffer; | ||
| 92 | + std::snprintf(buffer.data(), buffer_length, "%.5g", x); | ||
| 92 | return buffer.data() + std::string(" ") + unit; | 93 | return buffer.data() + std::string(" ") + unit; |
| 93 | }; | 94 | }; |
| 94 | 95 |
include/CLI/TypeTools.hpp
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | // file LICENSE or https://github.com/CLIUtils/CLI11 for details. | 4 | // file LICENSE or https://github.com/CLIUtils/CLI11 for details. |
| 5 | 5 | ||
| 6 | #include "StringTools.hpp" | 6 | #include "StringTools.hpp" |
| 7 | +#include <cstdint> | ||
| 7 | #include <exception> | 8 | #include <exception> |
| 8 | #include <memory> | 9 | #include <memory> |
| 9 | #include <string> | 10 | #include <string> |
| @@ -595,9 +596,9 @@ template <typename T, | @@ -595,9 +596,9 @@ template <typename T, | ||
| 595 | bool lexical_cast(const std::string &input, T &output) { | 596 | bool lexical_cast(const std::string &input, T &output) { |
| 596 | try { | 597 | try { |
| 597 | std::size_t n = 0; | 598 | std::size_t n = 0; |
| 598 | - long long output_ll = std::stoll(input, &n, 0); | 599 | + std::int64_t output_ll = std::stoll(input, &n, 0); |
| 599 | output = static_cast<T>(output_ll); | 600 | output = static_cast<T>(output_ll); |
| 600 | - return n == input.size() && static_cast<long long>(output) == output_ll; | 601 | + return n == input.size() && static_cast<std::int64_t>(output) == output_ll; |
| 601 | } catch(const std::invalid_argument &) { | 602 | } catch(const std::invalid_argument &) { |
| 602 | return false; | 603 | return false; |
| 603 | } catch(const std::out_of_range &) { | 604 | } catch(const std::out_of_range &) { |
| @@ -614,9 +615,9 @@ bool lexical_cast(const std::string &input, T &output) { | @@ -614,9 +615,9 @@ bool lexical_cast(const std::string &input, T &output) { | ||
| 614 | 615 | ||
| 615 | try { | 616 | try { |
| 616 | std::size_t n = 0; | 617 | std::size_t n = 0; |
| 617 | - unsigned long long output_ll = std::stoull(input, &n, 0); | 618 | + std::uint64_t output_ll = std::stoull(input, &n, 0); |
| 618 | output = static_cast<T>(output_ll); | 619 | output = static_cast<T>(output_ll); |
| 619 | - return n == input.size() && static_cast<unsigned long long>(output) == output_ll; | 620 | + return n == input.size() && static_cast<std::uint64_t>(output) == output_ll; |
| 620 | } catch(const std::invalid_argument &) { | 621 | } catch(const std::invalid_argument &) { |
| 621 | return false; | 622 | return false; |
| 622 | } catch(const std::out_of_range &) { | 623 | } catch(const std::out_of_range &) { |
include/CLI/Validators.hpp
| @@ -35,7 +35,7 @@ | @@ -35,7 +35,7 @@ | ||
| 35 | #endif | 35 | #endif |
| 36 | 36 | ||
| 37 | #if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 | 37 | #if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 |
| 38 | -#include <filesystem> | 38 | +#include <filesystem> // NOLINT(build/include) |
| 39 | #else | 39 | #else |
| 40 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
| 41 | #include <sys/types.h> | 41 | #include <sys/types.h> |