Skip to content

Commit 14097df

Browse files
committed
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 <[email protected]>
1 parent 2460019 commit 14097df

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

CONTRIBUTING.md

+10
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ Contributions are welcomed. Open a pull-request or an issue.
55
This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
66

77
[code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md
8+
9+
## Code Style
10+
11+
This project prefers, but does not strictly enforce, a specific source code style. The style is described in `.clang-format` and `.clang-tidy`.
12+
13+
To generate a clang-tidy report:
14+
15+
```bash
16+
clang-tidy --extra-arg=-std=c++17 --config-file=.clang-tidy include/argparse/argparse.hpp
17+
```

include/argparse/argparse.hpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ class Argument {
505505
m_values.emplace_back(m_implicit_value);
506506
std::visit([](const auto &f) { f({}); }, m_action);
507507
return start;
508-
} else if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) {
508+
}
509+
if ((dist = static_cast<std::size_t>(std::distance(start, end))) >= num_args_min) {
509510
if (num_args_max < dist) {
510511
end = std::next(start, num_args_max);
511512
}
@@ -525,8 +526,9 @@ class Argument {
525526
void operator()(void_action &f) {
526527
std::for_each(first, last, f);
527528
if (!self.m_default_value.has_value()) {
528-
if (!self.m_accepts_optional_like_value)
529+
if (!self.m_accepts_optional_like_value) {
529530
self.m_values.resize(std::distance(first, last));
531+
}
530532
}
531533
}
532534

@@ -619,9 +621,11 @@ class Argument {
619621
std::size_t m_max;
620622

621623
public:
622-
NArgsRange(std::size_t minimum, std::size_t maximum) : m_min(minimum), m_max(maximum) {
623-
if (minimum > maximum)
624+
NArgsRange(std::size_t minimum, std::size_t maximum)
625+
: m_min(minimum), m_max(maximum) {
626+
if (minimum > maximum) {
624627
throw std::logic_error("Range of number of arguments is invalid");
628+
}
625629
}
626630

627631
bool contains(std::size_t value) const {
@@ -647,17 +651,17 @@ class Argument {
647651

648652
void throw_nargs_range_validation_error() const {
649653
std::stringstream stream;
650-
if (!m_used_name.empty())
654+
if (!m_used_name.empty()) {
651655
stream << m_used_name << ": ";
656+
}
652657
if (m_num_args_range.is_exact()) {
653658
stream << m_num_args_range.get_min();
654659
} else if (m_num_args_range.is_right_bounded()) {
655660
stream << m_num_args_range.get_min() << " to " << m_num_args_range.get_max();
656661
} else {
657662
stream << m_num_args_range.get_min() << " or more";
658663
}
659-
stream << " argument(s) expected. "
660-
<< m_values.size() << " provided.";
664+
stream << " argument(s) expected. " << m_values.size() << " provided.";
661665
throw std::runtime_error(stream.str());
662666
}
663667

@@ -862,11 +866,13 @@ class Argument {
862866
}
863867
if (m_default_value.has_value()) {
864868
return std::any_cast<T>(m_default_value);
865-
} else {
866-
if constexpr (details::IsContainer<T>)
867-
if (!m_accepts_optional_like_value)
868-
return any_cast_container<T>(m_values);
869869
}
870+
if constexpr (details::IsContainer<T>) {
871+
if (!m_accepts_optional_like_value) {
872+
return any_cast_container<T>(m_values);
873+
}
874+
}
875+
870876
throw std::logic_error("No value provided for '" + m_names.back() + "'.");
871877
}
872878

0 commit comments

Comments
 (0)