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:
Christoph Bachhuber 2020-01-08 23:32:30 +01:00 committed by Henry Schreiner
parent 8570ffb564
commit efbdd604af
8 changed files with 47 additions and 16 deletions

View File

@ -1,8 +1,35 @@
#Checks: '*,-clang-analyzer-alpha.*'
#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*'
Checks: '-*,llvm-namespace-comment,readability-container-size-empty,misc-throw-by-value-catch-by-reference,modernize*,google-readability-casting'
HeaderFilterRegex: '.*hpp'
CheckOptions:
- key: readability-braces-around-statements.ShortStatementLines
value: '1'
# Checks that will be implemented in future PRs:
# 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
FormatStyle: file
Checks: '
-*,
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'

View File

@ -18,7 +18,7 @@ int main(int argc, char **argv) {
CLI11_PARSE(app, argc, argv);
// 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;
return 0;

View File

@ -34,7 +34,7 @@ int main(int argc, char **argv) {
CLI11_PARSE(app, argc, argv);
// 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;
return 0;

View File

@ -2416,10 +2416,11 @@ class App {
/// Count the required remaining positional arguments
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()))) {
return true;
}
}
return false;
}

View File

@ -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_configurable() && app->got_subcommand(subcom)) {
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() + ".");
}
}
}
return out.str();
}

View File

@ -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) {
if((min_option == 1) && (max_option == 1) && (used == 0))
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) +
" were given",
ExitCodes::RequiredError);
}
if((min_option == 1) && (used == 0))
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 " +
std::to_string(used) + "were given from [" + option_list + "]",
ExitCodes::RequiredError);
}
if(max_option == 1)
return RequiredError("Requires at most 1 options be given from [" + option_list + "]",
ExitCodes::RequiredError);

View File

@ -28,7 +28,7 @@ std::ostream &operator<<(std::ostream &in, const T &item) {
} // namespace enums
/// Export to CLI namespace
using namespace enums;
using enums::operator<<;
namespace detail {
/// a constant defining an expected max vector size defined to be a big number that could be multiplied by 4 and not

View File

@ -54,7 +54,7 @@ class Timer {
public:
/// 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()) {}
/// 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 {
public:
/// 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.
/// This destructor prints the string