mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 20:23:55 +00:00
Refactor clang-tidy (#389)
* Make CI fail with readability-container-size-empty flag * Make CI fail with cppcoreguidelines-owning-memory flag * Add all google checks, exclude specific ones * Apply clang-tidy fixes * Make timer constructors explicit * Add check for unscoped namespaces * Replace unscoped namespace by using-declaration * Replace unscoped namespace by using-declaration
This commit is contained in:
parent
8570ffb564
commit
efbdd604af
41
.clang-tidy
41
.clang-tidy
@ -1,8 +1,35 @@
|
|||||||
#Checks: '*,-clang-analyzer-alpha.*'
|
# Checks that will be implemented in future PRs:
|
||||||
#Checks: '-*,google-readability-casting,llvm-namespace-comment,performance-unnecessary-value-param,llvm-include-order,misc-throw-by-value-catch-by-reference,readability-container-size-empty,google-runtime-references,modernize*'
|
# performance-unnecessary-value-param, hints to ~110 issues. Be careful with implementing the suggested changes of this one, as auto-fixes may break the code
|
||||||
Checks: '-*,llvm-namespace-comment,readability-container-size-empty,misc-throw-by-value-catch-by-reference,modernize*,google-readability-casting'
|
|
||||||
HeaderFilterRegex: '.*hpp'
|
FormatStyle: file
|
||||||
CheckOptions:
|
|
||||||
- key: readability-braces-around-statements.ShortStatementLines
|
Checks: '
|
||||||
value: '1'
|
-*,
|
||||||
|
google-*,
|
||||||
|
-google-runtime-int,
|
||||||
|
-google-runtime-references,
|
||||||
|
llvm-include-order,
|
||||||
|
llvm-namespace-comment,
|
||||||
|
misc-throw-by-value-catch-by-reference,
|
||||||
|
modernize*,
|
||||||
|
readability-container-size-empty,
|
||||||
|
'
|
||||||
|
|
||||||
|
WarningsAsErrors: '
|
||||||
|
-*,
|
||||||
|
google-*,
|
||||||
|
-google-runtime-int,
|
||||||
|
-google-runtime-references,
|
||||||
|
llvm-include-order,
|
||||||
|
llvm-namespace-comment,
|
||||||
|
misc-throw-by-value-catch-by-reference,
|
||||||
|
modernize*,
|
||||||
|
readability-container-size-empty,
|
||||||
|
'
|
||||||
|
|
||||||
|
HeaderFilterRegex: '.*hpp'
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
- key: google-readability-braces-around-statements.ShortStatementLines
|
||||||
|
value: '3'
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ int main(int argc, char **argv) {
|
|||||||
CLI11_PARSE(app, argc, argv);
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
|
||||||
// CLI11's built in enum streaming can be used outside CLI11 like this:
|
// CLI11's built in enum streaming can be used outside CLI11 like this:
|
||||||
using namespace CLI::enums;
|
using CLI::enums::operator<<;
|
||||||
std::cout << "Enum received: " << level << std::endl;
|
std::cout << "Enum received: " << level << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -34,7 +34,7 @@ int main(int argc, char **argv) {
|
|||||||
CLI11_PARSE(app, argc, argv);
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
|
||||||
// CLI11's built in enum streaming can be used outside CLI11 like this:
|
// CLI11's built in enum streaming can be used outside CLI11 like this:
|
||||||
using namespace CLI::enums;
|
using CLI::enums::operator<<;
|
||||||
std::cout << "Enum received: " << level << std::endl;
|
std::cout << "Enum received: " << level << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2416,10 +2416,11 @@ class App {
|
|||||||
|
|
||||||
/// Count the required remaining positional arguments
|
/// Count the required remaining positional arguments
|
||||||
bool _has_remaining_positionals() const {
|
bool _has_remaining_positionals() const {
|
||||||
for(const Option_p &opt : options_)
|
for(const Option_p &opt : options_) {
|
||||||
if(opt->get_positional() && ((static_cast<int>(opt->count()) < opt->get_items_expected_min()))) {
|
if(opt->get_positional() && ((static_cast<int>(opt->count()) < opt->get_items_expected_min()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const App *subcom : subcommands)
|
for(const App *subcom : subcommands) {
|
||||||
if(!subcom->get_name().empty()) {
|
if(!subcom->get_name().empty()) {
|
||||||
if(subcom->get_configurable() && app->got_subcommand(subcom)) {
|
if(subcom->get_configurable() && app->got_subcommand(subcom)) {
|
||||||
if(!prefix.empty() || app->get_parent() == nullptr) {
|
if(!prefix.empty() || app->get_parent() == nullptr) {
|
||||||
@ -333,6 +333,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
|
|||||||
out << to_config(subcom, default_also, write_description, prefix + subcom->get_name() + ".");
|
out << to_config(subcom, default_also, write_description, prefix + subcom->get_name() + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
@ -216,16 +216,18 @@ class RequiredError : public ParseError {
|
|||||||
Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) {
|
Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) {
|
||||||
if((min_option == 1) && (max_option == 1) && (used == 0))
|
if((min_option == 1) && (max_option == 1) && (used == 0))
|
||||||
return RequiredError("Exactly 1 option from [" + option_list + "]");
|
return RequiredError("Exactly 1 option from [" + option_list + "]");
|
||||||
if((min_option == 1) && (max_option == 1) && (used > 1))
|
if((min_option == 1) && (max_option == 1) && (used > 1)) {
|
||||||
return RequiredError("Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) +
|
return RequiredError("Exactly 1 option from [" + option_list + "] is required and " + std::to_string(used) +
|
||||||
" were given",
|
" were given",
|
||||||
ExitCodes::RequiredError);
|
ExitCodes::RequiredError);
|
||||||
|
}
|
||||||
if((min_option == 1) && (used == 0))
|
if((min_option == 1) && (used == 0))
|
||||||
return RequiredError("At least 1 option from [" + option_list + "]");
|
return RequiredError("At least 1 option from [" + option_list + "]");
|
||||||
if(used < min_option)
|
if(used < min_option) {
|
||||||
return RequiredError("Requires at least " + std::to_string(min_option) + " options used and only " +
|
return RequiredError("Requires at least " + std::to_string(min_option) + " options used and only " +
|
||||||
std::to_string(used) + "were given from [" + option_list + "]",
|
std::to_string(used) + "were given from [" + option_list + "]",
|
||||||
ExitCodes::RequiredError);
|
ExitCodes::RequiredError);
|
||||||
|
}
|
||||||
if(max_option == 1)
|
if(max_option == 1)
|
||||||
return RequiredError("Requires at most 1 options be given from [" + option_list + "]",
|
return RequiredError("Requires at most 1 options be given from [" + option_list + "]",
|
||||||
ExitCodes::RequiredError);
|
ExitCodes::RequiredError);
|
||||||
|
@ -28,7 +28,7 @@ std::ostream &operator<<(std::ostream &in, const T &item) {
|
|||||||
} // namespace enums
|
} // namespace enums
|
||||||
|
|
||||||
/// Export to CLI namespace
|
/// Export to CLI namespace
|
||||||
using namespace enums;
|
using enums::operator<<;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
/// a constant defining an expected max vector size defined to be a big number that could be multiplied by 4 and not
|
/// a constant defining an expected max vector size defined to be a big number that could be multiplied by 4 and not
|
||||||
|
@ -54,7 +54,7 @@ class Timer {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// Standard constructor, can set title and print function
|
/// Standard constructor, can set title and print function
|
||||||
Timer(std::string title = "Timer", time_print_t time_print = Simple)
|
explicit Timer(std::string title = "Timer", time_print_t time_print = Simple)
|
||||||
: title_(std::move(title)), time_print_(std::move(time_print)), start_(clock::now()) {}
|
: title_(std::move(title)), time_print_(std::move(time_print)), start_(clock::now()) {}
|
||||||
|
|
||||||
/// Time a function by running it multiple times. Target time is the len to target.
|
/// Time a function by running it multiple times. Target time is the len to target.
|
||||||
@ -117,7 +117,7 @@ class Timer {
|
|||||||
class AutoTimer : public Timer {
|
class AutoTimer : public Timer {
|
||||||
public:
|
public:
|
||||||
/// Reimplementing the constructor is required in GCC 4.7
|
/// Reimplementing the constructor is required in GCC 4.7
|
||||||
AutoTimer(std::string title = "Timer", time_print_t time_print = Simple) : Timer(title, time_print) {}
|
explicit AutoTimer(std::string title = "Timer", time_print_t time_print = Simple) : Timer(title, time_print) {}
|
||||||
// GCC 4.7 does not support using inheriting constructors.
|
// GCC 4.7 does not support using inheriting constructors.
|
||||||
|
|
||||||
/// This destructor prints the string
|
/// This destructor prints the string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user