Write the clang-tidy file OpenBMC needs
Now that CI can handle clang-tidy, and a lot of the individual fixes
have landed for the various static analysis checks, lets see how close
we are.
This includes bringing a bunch of the code up to par with the checks
that require. Most of them fall into the category of extraneous else
statements, const correctness problems, or extra copies.
Tested:
CI only. Unit tests pass.
Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: I9fbd346560a75fdd3901fa40c57932486275e912
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 93c2a60..cc30cab 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -222,16 +222,13 @@
state = ConnState::terminated;
return;
}
- else if (retryPolicyAction == "SuspendRetries")
+ if (retryPolicyAction == "SuspendRetries")
{
state = ConnState::suspended;
return;
}
- else
- {
- // keep retrying, reset count and continue.
- retryCount = 0;
- }
+ // keep retrying, reset count and continue.
+ retryCount = 0;
}
if ((state == ConnState::connectFailed) ||
@@ -265,11 +262,8 @@
});
return;
}
- else
- {
- // reset retry count.
- retryCount = 0;
- }
+ // reset retry count.
+ retryCount = 0;
connStateCheck();
return;
diff --git a/http/http_request.h b/http/http_request.h
index 10aabc3..c3e497f 100644
--- a/http/http_request.h
+++ b/http/http_request.h
@@ -42,37 +42,37 @@
return req.method();
}
- const std::string_view getHeaderValue(std::string_view key) const
+ std::string_view getHeaderValue(std::string_view key) const
{
return req[key];
}
- const std::string_view getHeaderValue(boost::beast::http::field key) const
+ std::string_view getHeaderValue(boost::beast::http::field key) const
{
return req[key];
}
- const std::string_view methodString() const
+ std::string_view methodString() const
{
return req.method_string();
}
- const std::string_view target() const
+ std::string_view target() const
{
return req.target();
}
- unsigned version()
+ unsigned version() const
{
return req.version();
}
- bool isUpgrade()
+ bool isUpgrade() const
{
return boost::beast::websocket::is_upgrade(req);
}
- bool keepAlive()
+ bool keepAlive() const
{
return req.keep_alive();
}
diff --git a/http/routing.h b/http/routing.h
index b49e15e..52d1b06 100644
--- a/http/routing.h
+++ b/http/routing.h
@@ -40,7 +40,9 @@
std::unique_ptr<BaseRule> upgrade()
{
if (ruleToUpgrade)
+ {
return std::move(ruleToUpgrade);
+ }
return {};
}
@@ -660,12 +662,16 @@
for (size_t x : node->paramChildrens)
{
if (!x)
+ {
continue;
+ }
Node* child = &nodes[x];
optimizeNode(child);
}
if (node->children.empty())
+ {
return;
+ }
bool mergeWithChild = true;
for (const std::pair<std::string, unsigned>& kv : node->children)
{
@@ -710,8 +716,10 @@
void validate()
{
if (!head()->isSimpleNode())
+ {
throw std::runtime_error(
"Internal error: Trie header should be simple!");
+ }
optimize();
}
@@ -754,15 +762,21 @@
{
RoutingParams empty;
if (params == nullptr)
+ {
params = ∅
+ }
unsigned found{};
RoutingParams matchParams;
if (node == nullptr)
+ {
node = head();
+ }
if (pos == req_url.size())
+ {
return {node->ruleIndex, *params};
+ }
auto updateFound =
[&found, &matchParams](std::pair<unsigned, RoutingParams>& ret) {
@@ -847,7 +861,9 @@
for (; epos < req_url.size(); epos++)
{
if (req_url[epos] == '/')
+ {
break;
+ }
}
if (epos != pos)
@@ -948,7 +964,9 @@
}
}
if (nodes[idx].ruleIndex)
+ {
throw std::runtime_error("handler already exists for " + url);
+ }
nodes[idx].ruleIndex = ruleIndex;
}
@@ -1085,7 +1103,9 @@
{
std::unique_ptr<BaseRule> upgraded = rule->upgrade();
if (upgraded)
+ {
rule = std::move(upgraded);
+ }
rule->validate();
internalAddRuleObject(rule->rule, rule.get());
}
@@ -1121,7 +1141,9 @@
}
if (ruleIndex >= rules.size())
+ {
throw std::runtime_error("Trie internal structure corrupted!");
+ }
if (ruleIndex == ruleSpecialRedirectSlash)
{
@@ -1223,7 +1245,9 @@
}
if (ruleIndex >= rules.size())
+ {
throw std::runtime_error("Trie internal structure corrupted!");
+ }
if (ruleIndex == ruleSpecialRedirectSlash)
{