From d8a5bdc294a21bf730faba78d906ff4278d29307 Mon Sep 17 00:00:00 2001 From: Christoph Bachhuber Date: Fri, 6 Mar 2020 06:04:59 +0100 Subject: [PATCH] Add and fix cpplint whitespace/comments (#434) * Add whitespace/comments check * Adapt spacing in clang-format * Fix cpplint whitespace/comments issues * Grammar * Do not use clang-format for comment spacing * Fix with clang-format pre-commit hook --- .clang-format | 2 +- CPPLINT.cfg | 5 +-- examples/groups.cpp | 2 +- examples/nested.cpp | 2 +- examples/simple.cpp | 2 +- examples/subcom_partitioned.cpp | 2 +- examples/subcommands.cpp | 2 +- include/CLI/App.hpp | 66 ++++++++++++++++----------------- include/CLI/Config.hpp | 4 +- include/CLI/ConfigFwd.hpp | 2 +- include/CLI/Error.hpp | 2 +- include/CLI/Formatter.hpp | 14 +++---- include/CLI/FormatterFwd.hpp | 12 +++--- include/CLI/Option.hpp | 44 +++++++++++----------- include/CLI/Split.hpp | 4 +- include/CLI/StringTools.hpp | 10 ++--- include/CLI/Timer.hpp | 4 +- include/CLI/TypeTools.hpp | 10 ++--- include/CLI/Validators.hpp | 45 +++++++++++----------- tests/AppTest.cpp | 26 ++++++------- tests/ConfigFileTest.cpp | 4 +- tests/CreationTest.cpp | 2 +- tests/HelpTest.cpp | 4 +- tests/HelpersTest.cpp | 22 +++++------ tests/NewParseTest.cpp | 12 +++--- tests/OptionGroupTest.cpp | 4 +- tests/SetTest.cpp | 22 +++++------ tests/SubcommandTest.cpp | 8 ++-- tests/TrueFalseTest.cpp | 4 +- tests/app_helper.hpp | 2 +- 30 files changed, 170 insertions(+), 174 deletions(-) diff --git a/.clang-format b/.clang-format index caaefd2d..0879ffa4 100644 --- a/.clang-format +++ b/.clang-format @@ -75,7 +75,7 @@ SortIncludes: true # SpaceBeforeAssignmentOperators: true SpaceBeforeParens: Never # SpaceInEmptyParentheses: false -# SpacesBeforeTrailingComments: 1 +SpacesBeforeTrailingComments: 2 # SpacesInAngles: false # SpacesInContainerLiterals: true # SpacesInCStyleCastParentheses: false diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 03aa6414..68227c3f 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,7 +1,7 @@ set noparent linelength=120 # As in .clang-format -# Non-used filters +# Unused filters filter=-build/include_order # Requires unusual include order that encourages creating not self-contained headers filter=-readability/nolint # Conflicts with clang-tidy filter=-runtime/references # Requires fundamental change of API, don't see need for this @@ -9,6 +9,3 @@ filter=-whitespace/blank_line # Unnecessarily strict with blank lines that othe filter=-whitespace/indent # Requires strange 3-space indent of private/protected/public markers filter=-whitespace/parens,-whitespace/braces # Conflict with clang-format -# Filters to be included in future -filter=-whitespace/comments - diff --git a/examples/groups.cpp b/examples/groups.cpp index 863976b4..22d62894 100644 --- a/examples/groups.cpp +++ b/examples/groups.cpp @@ -20,7 +20,7 @@ int main(int argc, char **argv) { int count{0}; CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important"); - double value{0.0}; // = 3.14; + double value{0.0}; // = 3.14; app.add_option("-d,--double", value, "Some Value")->group("Other"); try { diff --git a/examples/nested.cpp b/examples/nested.cpp index 7cd49367..23f42851 100644 --- a/examples/nested.cpp +++ b/examples/nested.cpp @@ -14,7 +14,7 @@ int main(int argc, char **argv) { app.add_flag("--version", "Get version"); CLI::App *cameraApp = app.add_subcommand("camera", "Configure the app camera"); - cameraApp->require_subcommand(0, 1); // 0 (default) or 1 camera + cameraApp->require_subcommand(0, 1); // 0 (default) or 1 camera std::string mvcamera_config_file = "mvcamera_config.json"; CLI::App *mvcameraApp = cameraApp->add_subcommand("mvcamera", "MatrixVision Camera Configuration"); diff --git a/examples/simple.cpp b/examples/simple.cpp index 58cf4b6c..2d465cb2 100644 --- a/examples/simple.cpp +++ b/examples/simple.cpp @@ -21,7 +21,7 @@ int main(int argc, char **argv) { int v{0}; CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times"); - double value{0.0}; // = 3.14; + double value{0.0}; // = 3.14; app.add_option("-d,--double", value, "Some Value"); CLI11_PARSE(app, argc, argv); diff --git a/examples/subcom_partitioned.cpp b/examples/subcom_partitioned.cpp index 50106781..20dd3623 100644 --- a/examples/subcom_partitioned.cpp +++ b/examples/subcom_partitioned.cpp @@ -23,7 +23,7 @@ int main(int argc, char **argv) { CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required(); CLI::App_p otherOpt = std::make_shared("Other"); - double value{0.0}; // = 3.14; + double value{0.0}; // = 3.14; otherOpt->add_option("-d,--double", value, "Some Value"); // add the subapps to the main one diff --git a/examples/subcommands.cpp b/examples/subcommands.cpp index ce71eae9..937eaeaf 100644 --- a/examples/subcommands.cpp +++ b/examples/subcommands.cpp @@ -15,7 +15,7 @@ int main(int argc, char **argv) { app.add_flag("--random", "Some random flag"); CLI::App *start = app.add_subcommand("start", "A great subcommand"); CLI::App *stop = app.add_subcommand("stop", "Do you really want to stop?"); - app.require_subcommand(); // 1 or more + app.require_subcommand(); // 1 or more std::string file; start->add_option("-f,--file", file, "File name"); diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index abc6546e..98f0b03f 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -43,12 +43,12 @@ namespace CLI { namespace detail { enum class Classifier { NONE, POSITIONAL_MARK, SHORT, LONG, WINDOWS, SUBCOMMAND, SUBCOMMAND_TERMINATOR }; struct AppFriend; -} // namespace detail +} // namespace detail namespace FailureMessage { std::string simple(const App *app, const Error &e); std::string help(const App *app, const Error &e); -} // namespace FailureMessage +} // namespace FailureMessage /// enumeration of modes of how to deal with extras in config files @@ -464,7 +464,7 @@ class App { auto *p = (parent_ != nullptr) ? _get_fallthrough_parent() : this; auto &match = _compare_subcommand_names(*this, *p); if(!match.empty()) { - ignore_case_ = false; // we are throwing so need to be exception invariant + ignore_case_ = false; // we are throwing so need to be exception invariant throw OptionAlreadyAdded("ignore case would cause subcommand name conflicts: " + match); } } @@ -586,7 +586,7 @@ class App { } } // this line should not be reached the above loop should trigger the throw - throw(OptionAlreadyAdded("added option matched existing option name")); // LCOV_EXCL_LINE + throw(OptionAlreadyAdded("added option matched existing option name")); // LCOV_EXCL_LINE } /// Add option for assigning to a variable @@ -594,11 +594,11 @@ class App { typename ConvertTo = AssignTo, enable_if_t::value, detail::enabler> = detail::dummy> Option *add_option(std::string option_name, - AssignTo &variable, ///< The variable to set + AssignTo &variable, ///< The variable to set std::string option_description = "", bool defaulted = false) { - auto fun = [&variable](const CLI::results_t &res) { // comment for spacing + auto fun = [&variable](const CLI::results_t &res) { // comment for spacing return detail::lexical_conversion(res, variable); }; @@ -619,7 +619,7 @@ class App { /// Add option for a callback of a specific type template Option *add_option_function(std::string option_name, - const std::function &func, ///< the callback to execute + const std::function &func, ///< the callback to execute std::string option_description = "") { auto fun = [func](const CLI::results_t &res) { @@ -731,7 +731,7 @@ class App { template ::value && !is_bool::value, detail::enabler> = detail::dummy> Option *add_flag(std::string flag_name, - T &flag_count, ///< A variable holding the count + T &flag_count, ///< A variable holding the count std::string flag_description = "") { flag_count = 0; CLI::callback_t fun = [&flag_count](const CLI::results_t &res) { @@ -754,7 +754,7 @@ class App { !std::is_constructible, T>::value, detail::enabler> = detail::dummy> Option *add_flag(std::string flag_name, - T &flag_result, ///< A variable holding true if passed + T &flag_result, ///< A variable holding true if passed std::string flag_description = "") { CLI::callback_t fun = [&flag_result](const CLI::results_t &res) { @@ -768,7 +768,7 @@ class App { typename T, enable_if_t, T>::value, detail::enabler> = detail::dummy> Option *add_flag(std::string flag_name, - std::vector &flag_results, ///< A vector of values with the flag results + std::vector &flag_results, ///< A vector of values with the flag results std::string flag_description = "") { CLI::callback_t fun = [&flag_results](const CLI::results_t &res) { bool retval = true; @@ -785,7 +785,7 @@ class App { /// Add option for callback that is triggered with a true flag and takes no arguments Option *add_flag_callback(std::string flag_name, - std::function function, ///< A function to call, void(void) + std::function function, ///< A function to call, void(void) std::string flag_description = "") { CLI::callback_t fun = [function](const CLI::results_t &res) { @@ -801,7 +801,7 @@ class App { /// Add option for callback with an integer value Option *add_flag_function(std::string flag_name, - std::function function, ///< A function to call, void(int) + std::function function, ///< A function to call, void(int) std::string flag_description = "") { CLI::callback_t fun = [function](const CLI::results_t &res) { @@ -817,7 +817,7 @@ class App { #ifdef CLI11_CPP14 /// Add option for callback (C++14 or better only) Option *add_flag(std::string flag_name, - std::function function, ///< A function to call, void(std::int64_t) + std::function function, ///< A function to call, void(std::int64_t) std::string flag_description = "") { return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description)); } @@ -826,8 +826,8 @@ class App { /// Add set of options (No default, temp reference, such as an inline set) DEPRECATED template Option *add_set(std::string option_name, - T &member, ///< The selected member of the set - std::set options, ///< The set of possibilities + T &member, ///< The selected member of the set + std::set options, ///< The set of possibilities std::string option_description = "") { Option *opt = add_option(option_name, member, std::move(option_description)); @@ -838,8 +838,8 @@ class App { /// Add set of options (No default, set can be changed afterwards - do not destroy the set) DEPRECATED template Option *add_mutable_set(std::string option_name, - T &member, ///< The selected member of the set - const std::set &options, ///< The set of possibilities + T &member, ///< The selected member of the set + const std::set &options, ///< The set of possibilities std::string option_description = "") { Option *opt = add_option(option_name, member, std::move(option_description)); @@ -850,8 +850,8 @@ class App { /// Add set of options (with default, static set, such as an inline set) DEPRECATED template Option *add_set(std::string option_name, - T &member, ///< The selected member of the set - std::set options, ///< The set of possibilities + T &member, ///< The selected member of the set + std::set options, ///< The set of possibilities std::string option_description, bool defaulted) { @@ -863,8 +863,8 @@ class App { /// Add set of options (with default, set can be changed afterwards - do not destroy the set) DEPRECATED template Option *add_mutable_set(std::string option_name, - T &member, ///< The selected member of the set - const std::set &options, ///< The set of possibilities + T &member, ///< The selected member of the set + const std::set &options, ///< The set of possibilities std::string option_description, bool defaulted) { @@ -932,7 +932,7 @@ class App { // Remove existing config if present if(config_ptr_ != nullptr) { remove_option(config_ptr_); - config_ptr_ = nullptr; // need to remove the config_ptr completely + config_ptr_ = nullptr; // need to remove the config_ptr completely } // Only add config if option passed @@ -1107,7 +1107,7 @@ class App { for(auto &sub : subcommands_) { cnt += sub->count_all(); } - if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called + if(!get_name().empty()) { // for named subcommands add the number of times the subcommand was called cnt += parsed_; } return cnt; @@ -1881,7 +1881,7 @@ class App { app->name_.clear(); } if(app->name_.empty()) { - app->fallthrough_ = false; // make sure fallthrough_ is false to prevent infinite loop + app->fallthrough_ = false; // make sure fallthrough_ is false to prevent infinite loop app->prefix_command_ = false; } // make sure the parent is set to be this object in preparation for parse @@ -2657,14 +2657,14 @@ class App { int max_num = op->get_items_expected_max(); // Make sure we always eat the minimum for unlimited vectors - int collected = 0; // total number of arguments collected - int result_count = 0; // local variable for number of results in a single arg string + int collected = 0; // total number of arguments collected + int result_count = 0; // local variable for number of results in a single arg string // deal with purely flag like things if(max_num == 0) { auto res = op->get_flag_value(arg_name, value); op->add_result(res); parse_order_.push_back(op.get()); - } else if(!value.empty()) { // --this=value + } else if(!value.empty()) { // --this=value op->add_result(value, result_count); parse_order_.push_back(op.get()); collected += result_count; @@ -2685,11 +2685,11 @@ class App { collected += result_count; } - if(min_num > collected) { // if we have run out of arguments and the minimum was not met + if(min_num > collected) { // if we have run out of arguments and the minimum was not met throw ArgumentMismatch::TypedAtLeast(op->get_name(), min_num, op->get_type_name()); } - if(max_num > collected || op->get_allow_extra_args()) { // we allow optional arguments + if(max_num > collected || op->get_allow_extra_args()) { // we allow optional arguments auto remreqpos = _count_remaining_positionals(true); // we have met the minimum now optionally check up to the maximum while((collected < max_num || op->get_allow_extra_args()) && !args.empty() && @@ -2866,7 +2866,7 @@ class App { throw OptionNotFound("could not locate the given Option"); } } -}; // namespace CLI +}; // namespace CLI /// Extension of App to better manage groups of options class Option_group : public App { @@ -3050,7 +3050,7 @@ inline std::string help(const App *app, const Error &e) { return header; } -} // namespace FailureMessage +} // namespace FailureMessage namespace detail { /// This class is simply to allow tests access to App's protected functions @@ -3072,6 +3072,6 @@ struct AppFriend { /// Wrap the fallthrough parent function to make sure that is working correctly static App *get_fallthrough_parent(App *app) { return app->_get_fallthrough_parent(); } }; -} // namespace detail +} // namespace detail -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/Config.hpp b/include/CLI/Config.hpp index eafb6218..488e3455 100644 --- a/include/CLI/Config.hpp +++ b/include/CLI/Config.hpp @@ -160,7 +160,7 @@ inline void checkParentSegments(std::vector &output, const std::stri output.back().parents = std::move(parents); output.back().name = "++"; } -} // namespace detail +} // namespace detail inline std::vector ConfigBase::from_config(std::istream &input) const { std::string line; @@ -343,4 +343,4 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, return out.str(); } -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/ConfigFwd.hpp b/include/CLI/ConfigFwd.hpp index 369458fd..5ef54f85 100644 --- a/include/CLI/ConfigFwd.hpp +++ b/include/CLI/ConfigFwd.hpp @@ -128,4 +128,4 @@ class ConfigTOML : public ConfigINI { valueDelimiter = '='; } }; -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/Error.hpp b/include/CLI/Error.hpp index 3323495b..0adf15c5 100644 --- a/include/CLI/Error.hpp +++ b/include/CLI/Error.hpp @@ -337,4 +337,4 @@ class OptionNotFound : public Error { /// @} -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/Formatter.hpp b/include/CLI/Formatter.hpp index 748fcb36..6ac4e4d1 100644 --- a/include/CLI/Formatter.hpp +++ b/include/CLI/Formatter.hpp @@ -44,11 +44,11 @@ inline std::string Formatter::make_groups(const App *app, AppFormatMode mode) co // Options for(const std::string &group : groups) { std::vector opts = app->get_options([app, mode, &group](const Option *opt) { - return opt->get_group() == group // Must be in the right group - && opt->nonpositional() // Must not be a positional - && (mode != AppFormatMode::Sub // If mode is Sub, then - || (app->get_help_ptr() != opt // Ignore help pointer - && app->get_help_all_ptr() != opt)); // Ignore help all pointer + return opt->get_group() == group // Must be in the right group + && opt->nonpositional() // Must not be a positional + && (mode != AppFormatMode::Sub // If mode is Sub, then + || (app->get_help_ptr() != opt // Ignore help pointer + && app->get_help_all_ptr() != opt)); // Ignore help all pointer }); if(!group.empty() && !opts.empty()) { out << make_group(group, false, opts); @@ -220,7 +220,7 @@ inline std::string Formatter::make_expanded(const App *sub) const { // Drop blank spaces std::string tmp = detail::find_and_replace(out.str(), "\n\n", "\n"); - tmp = tmp.substr(0, tmp.size() - 1); // Remove the final '\n' + tmp = tmp.substr(0, tmp.size() - 1); // Remove the final '\n' // Indent all but the first line (the name) return detail::find_and_replace(tmp, "\n", "\n ") + "\n"; @@ -278,4 +278,4 @@ inline std::string Formatter::make_option_usage(const Option *opt) const { return opt->get_required() ? out.str() : "[" + out.str() + "]"; } -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/FormatterFwd.hpp b/include/CLI/FormatterFwd.hpp index 1dda9e1c..a98a05f0 100644 --- a/include/CLI/FormatterFwd.hpp +++ b/include/CLI/FormatterFwd.hpp @@ -24,9 +24,9 @@ class App; /// the second argument. enum class AppFormatMode { - Normal, //< The normal, detailed help - All, //< A fully expanded help - Sub, //< Used when printed as part of expanded subcommand + Normal, //< The normal, detailed help + All, //< A fully expanded help + Sub, //< Used when printed as part of expanded subcommand }; /// This is the minimum requirements to run a formatter. @@ -55,7 +55,7 @@ class FormatterBase { FormatterBase(FormatterBase &&) = default; /// Adding a destructor in this form to work around bug in GCC 4.7 - virtual ~FormatterBase() noexcept {} // NOLINT(modernize-use-equals-default) + virtual ~FormatterBase() noexcept {} // NOLINT(modernize-use-equals-default) /// This is the key method that puts together help virtual std::string make_help(const App *, std::string, AppFormatMode) const = 0; @@ -100,7 +100,7 @@ class FormatterLambda final : public FormatterBase { explicit FormatterLambda(funct_t funct) : lambda_(std::move(funct)) {} /// Adding a destructor (mostly to make GCC 4.7 happy) - ~FormatterLambda() noexcept override {} // NOLINT(modernize-use-equals-default) + ~FormatterLambda() noexcept override {} // NOLINT(modernize-use-equals-default) /// This will simply call the lambda function std::string make_help(const App *app, std::string name, AppFormatMode mode) const override { @@ -177,4 +177,4 @@ class Formatter : public FormatterBase { ///@} }; -} // namespace CLI +} // namespace CLI diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index c1ab0239..2e029303 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -33,11 +33,11 @@ class App; using Option_p = std::unique_ptr