Clean miscellaneous source styling

Clears warnings for the following checks in clang-tidy:
  readability-braces-around-statements
  readability-else-after-return checks

Also adds hints about code style to CONTRIBUTING document.

Signed-off-by: Sean Robinson <sean.robinson@scottsdalecc.edu>
This commit is contained in:
Sean Robinson 2022-07-06 09:59:58 -07:00
parent 2460019e2e
commit 14097df904
2 changed files with 27 additions and 11 deletions

View File

@ -5,3 +5,13 @@ Contributions are welcomed. Open a pull-request or an issue.
This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code. This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md [code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md
## Code Style
This project prefers, but does not strictly enforce, a specific source code style. The style is described in `.clang-format` and `.clang-tidy`.
To generate a clang-tidy report:
```bash
clang-tidy --extra-arg=-std=c++17 --config-file=.clang-tidy include/argparse/argparse.hpp
```

View File

@ -505,7 +505,8 @@ public:
m_values.emplace_back(m_implicit_value); m_values.emplace_back(m_implicit_value);
std::visit([](const auto &f) { f({}); }, m_action); std::visit([](const auto &f) { f({}); }, m_action);
return start; return start;
} else if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) { }
if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) {
if (num_args_max < dist) { if (num_args_max < dist) {
end = std::next(start, num_args_max); end = std::next(start, num_args_max);
} }
@ -525,8 +526,9 @@ public:
void operator()(void_action &f) { void operator()(void_action &f) {
std::for_each(first, last, f); std::for_each(first, last, f);
if (!self.m_default_value.has_value()) { if (!self.m_default_value.has_value()) {
if (!self.m_accepts_optional_like_value) if (!self.m_accepts_optional_like_value) {
self.m_values.resize(std::distance(first, last)); self.m_values.resize(std::distance(first, last));
}
} }
} }
@ -619,9 +621,11 @@ private:
std::size_t m_max; std::size_t m_max;
public: public:
NArgsRange(std::size_t minimum, std::size_t maximum) : m_min(minimum), m_max(maximum) { NArgsRange(std::size_t minimum, std::size_t maximum)
if (minimum > maximum) : m_min(minimum), m_max(maximum) {
if (minimum > maximum) {
throw std::logic_error("Range of number of arguments is invalid"); throw std::logic_error("Range of number of arguments is invalid");
}
} }
bool contains(std::size_t value) const { bool contains(std::size_t value) const {
@ -647,8 +651,9 @@ private:
void throw_nargs_range_validation_error() const { void throw_nargs_range_validation_error() const {
std::stringstream stream; std::stringstream stream;
if (!m_used_name.empty()) if (!m_used_name.empty()) {
stream << m_used_name << ": "; stream << m_used_name << ": ";
}
if (m_num_args_range.is_exact()) { if (m_num_args_range.is_exact()) {
stream << m_num_args_range.get_min(); stream << m_num_args_range.get_min();
} else if (m_num_args_range.is_right_bounded()) { } else if (m_num_args_range.is_right_bounded()) {
@ -656,8 +661,7 @@ private:
} else { } else {
stream << m_num_args_range.get_min() << " or more"; stream << m_num_args_range.get_min() << " or more";
} }
stream << " argument(s) expected. " stream << " argument(s) expected. " << m_values.size() << " provided.";
<< m_values.size() << " provided.";
throw std::runtime_error(stream.str()); throw std::runtime_error(stream.str());
} }
@ -862,11 +866,13 @@ private:
} }
if (m_default_value.has_value()) { if (m_default_value.has_value()) {
return std::any_cast<T>(m_default_value); return std::any_cast<T>(m_default_value);
} else {
if constexpr (details::IsContainer<T>)
if (!m_accepts_optional_like_value)
return any_cast_container<T>(m_values);
} }
if constexpr (details::IsContainer<T>) {
if (!m_accepts_optional_like_value) {
return any_cast_container<T>(m_values);
}
}
throw std::logic_error("No value provided for '" + m_names.back() + "'."); throw std::logic_error("No value provided for '" + m_names.back() + "'.");
} }