chore: Enable more clang-tidy checks (#3054)

This commit is contained in:
Alex Kremer
2026-05-01 15:31:45 +01:00
committed by GitHub
parent d6bae6c12b
commit 51244feb4a
239 changed files with 1150 additions and 733 deletions

View File

@@ -29,7 +29,7 @@ public:
* @param ip The ip addr of the client
* @return true if authorized; false otherwise
*/
virtual bool
[[nodiscard]] virtual bool
isAdmin(RequestHeader const& request, std::string_view ip) const = 0;
};
@@ -45,7 +45,7 @@ public:
* @param ip The ip addr of the client
* @return true if authorized; false otherwise
*/
bool
[[nodiscard]] bool
isAdmin(RequestHeader const&, std::string_view ip) const override;
};
@@ -76,7 +76,7 @@ public:
* @param request The request from a host
* @return true if the password from request matches admin password from config
*/
bool
[[nodiscard]] bool
isAdmin(RequestHeader const& request, std::string_view) const override;
};

View File

@@ -66,7 +66,7 @@ public:
* @return The resolved client IP address if the connection is from a trusted proxy, otherwise
* std::nullopt.
*/
std::optional<std::string>
[[nodiscard]] std::optional<std::string>
resolveClientIp(std::string const& connectionIp, HttpHeaders const& headers) const;
/**

View File

@@ -257,10 +257,10 @@ private:
}
boost::json::array warnings = std::move(result.warnings);
warnings.emplace_back(rpc::makeWarning(rpc::WarnRpcClio));
warnings.emplace_back(rpc::makeWarning(rpc::WarningCode::WarnRpcClio));
if (etl_->lastCloseAgeSeconds() >= 60)
warnings.emplace_back(rpc::makeWarning(rpc::WarnRpcOutdated));
warnings.emplace_back(rpc::makeWarning(rpc::WarningCode::WarnRpcOutdated));
response["warnings"] = warnings;
connection->send(boost::json::serialize(response));
@@ -277,7 +277,7 @@ private:
}
}
bool
[[nodiscard]] bool
shouldReplaceParams(boost::json::object const& req) const
{
auto const hasParams = req.contains(JS(params));

View File

@@ -338,7 +338,7 @@ private:
if (!ec) {
auto ctxRef = ctx_
? std::optional<std::reference_wrapper<boost::asio::ssl::context>>{ctx_.value()}
? std::optional<std::reference_wrapper<boost::asio::ssl::context>>{*ctx_}
: std::nullopt;
std::make_shared<Detector<PlainSessionType, SslSessionType, HandlerType>>(

View File

@@ -54,7 +54,7 @@ public:
*
* @return The API subversion.
*/
virtual uint32_t
[[nodiscard]] virtual uint32_t
apiSubversion() const = 0;
};

View File

@@ -63,7 +63,7 @@ public:
* @param request Json request
* @return size_t The weight value (specific weight if defined, otherwise default weight)
*/
size_t
[[nodiscard]] size_t
requestWeight(boost::json::object const& request) const override;
};

View File

@@ -22,7 +22,7 @@ public:
* @param request The JSON object representing the request
* @return The calculated weight of the request
*/
virtual size_t
[[nodiscard]] virtual size_t
requestWeight(boost::json::object const& request) const = 0;
};

View File

@@ -47,7 +47,7 @@ public:
* @param ip IP address
* @return true if the given IP is whitelisted; false otherwise
*/
bool
[[nodiscard]] bool
isWhiteListed(std::string_view ip) const;
private:
@@ -115,7 +115,7 @@ public:
* @param ip The IP to check
* @return true if the given IP is whitelisted; false otherwise
*/
bool
[[nodiscard]] bool
isWhiteListed(std::string_view ip) const override
{
return whitelist_.isWhiteListed(ip);

View File

@@ -147,7 +147,7 @@ public:
}
}
boost::json::object
[[nodiscard]] boost::json::object
composeError(auto const& error) const
{
auto e = rpc::makeError(error);
@@ -163,7 +163,7 @@ public:
if (connection_->upgraded)
appendFieldIfExist(JS(api_version));
e[JS(request)] = request_.value();
e[JS(request)] = *request_;
}
if (connection_->upgraded) {

View File

@@ -323,11 +323,11 @@ public:
jsonResponse["warning"] = "load";
if (jsonResponse.contains("warnings") && jsonResponse["warnings"].is_array()) {
jsonResponse["warnings"].as_array().push_back(
rpc::makeWarning(rpc::WarnRpcRateLimit)
rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)
);
} else {
jsonResponse["warnings"] =
boost::json::array{rpc::makeWarning(rpc::WarnRpcRateLimit)};
boost::json::array{rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)};
}
// Reserialize when we need to include this warning
@@ -361,7 +361,7 @@ public:
}
private:
http::response<http::string_body>
[[nodiscard]] http::response<http::string_body>
httpResponse(http::status status, std::string contentType, std::string message) const
{
http::response<http::string_body> res{status, req_.version()};

View File

@@ -210,11 +210,11 @@ public:
if (jsonResponse.contains("warnings") && jsonResponse["warnings"].is_array()) {
jsonResponse["warnings"].as_array().push_back(
rpc::makeWarning(rpc::WarnRpcRateLimit)
rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)
);
} else {
jsonResponse["warnings"] =
boost::json::array{rpc::makeWarning(rpc::WarnRpcRateLimit)};
boost::json::array{rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)};
}
// Reserialize when we need to include this warning

View File

@@ -42,7 +42,7 @@ public:
*
* @return true if the connection was upgraded.
*/
virtual bool
[[nodiscard]] virtual bool
wasUpgraded() const = 0;
/**
@@ -50,7 +50,7 @@ public:
*
* @return The ip of the client.
*/
std::string const&
[[nodiscard]] std::string const&
ip() const;
/**
@@ -89,7 +89,7 @@ public:
*
* @return true if the client is an admin.
*/
bool
[[nodiscard]] bool
isAdmin() const;
/**

View File

@@ -115,7 +115,7 @@ public:
[this,
&request,
&response,
&onTaskComplete = onTaskComplete.value(),
&onTaskComplete = *onTaskComplete, // NOLINT(bugprone-unchecked-optional-access)
&connectionMetadata,
subscriptionContext =
std::move(subscriptionContext)](boost::asio::yield_context innerYield) mutable {
@@ -171,7 +171,7 @@ public:
if (not postSuccessful) {
// onTaskComplete must be called to notify coroutineGroup that the foreign task is done
onTaskComplete->operator()();
(*onTaskComplete)(); // NOLINT(bugprone-unchecked-optional-access)
rpcEngine_->notifyTooBusy();
return impl::ErrorHelper{request}.makeTooBusyError();
}
@@ -180,11 +180,13 @@ public:
coroutineGroup.asyncWait(yield);
ASSERT(response.has_value(), "Woke up coroutine without setting response");
// NOLINTBEGIN(bugprone-unchecked-optional-access)
if (not dosguard_.get().add(connectionMetadata.ip(), response->message().size())) {
response->setMessage(makeLoadWarning(*response));
}
return std::move(response).value();
return *std::move(response);
// NOLINTEND(bugprone-unchecked-optional-access)
}
private:
@@ -317,10 +319,10 @@ private:
}
boost::json::array warnings = std::move(result.warnings);
warnings.emplace_back(rpc::makeWarning(rpc::WarnRpcClio));
warnings.emplace_back(rpc::makeWarning(rpc::WarningCode::WarnRpcClio));
if (etl_->lastCloseAgeSeconds() >= 60)
warnings.emplace_back(rpc::makeWarning(rpc::WarnRpcOutdated));
warnings.emplace_back(rpc::makeWarning(rpc::WarningCode::WarnRpcOutdated));
response["warnings"] = warnings;
return Response{boost::beast::http::status::ok, response, rawRequest};
@@ -361,14 +363,17 @@ private:
auto jsonResponse = boost::json::parse(response.message()).as_object();
jsonResponse["warning"] = "load";
if (jsonResponse.contains("warnings") && jsonResponse["warnings"].is_array()) {
jsonResponse["warnings"].as_array().push_back(rpc::makeWarning(rpc::WarnRpcRateLimit));
jsonResponse["warnings"].as_array().push_back(
rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)
);
} else {
jsonResponse["warnings"] = boost::json::array{rpc::makeWarning(rpc::WarnRpcRateLimit)};
jsonResponse["warnings"] =
boost::json::array{rpc::makeWarning(rpc::WarningCode::WarnRpcRateLimit)};
}
return jsonResponse;
}
bool
[[nodiscard]] bool
shouldReplaceParams(boost::json::object const& req) const
{
auto const hasParams = req.contains(JS(params));

View File

@@ -59,7 +59,7 @@ public:
*
* @return The method of the request.
*/
Method
[[nodiscard]] Method
method() const;
/**
@@ -67,7 +67,7 @@ public:
*
* @return true if the request is an HTTP request, false otherwise.
*/
bool
[[nodiscard]] bool
isHttp() const;
/**
@@ -75,7 +75,7 @@ public:
*
* @return The HTTP request or std::nullopt if the request is a WebSocket request.
*/
std::optional<
[[nodiscard]] std::optional<
std::reference_wrapper<boost::beast::http::request<boost::beast::http::string_body> const>>
asHttpRequest() const;
@@ -85,7 +85,7 @@ public:
*
* @return The message of the request.
*/
std::string_view
[[nodiscard]] std::string_view
message() const;
/**
@@ -93,7 +93,7 @@ public:
*
* @return The target of the request or std::nullopt if the request is a WebSocket request.
*/
std::optional<std::string_view>
[[nodiscard]] std::optional<std::string_view>
target() const;
/**
@@ -101,7 +101,7 @@ public:
*
* @return The headers of the request.
*/
HttpHeaders const&
[[nodiscard]] HttpHeaders const&
httpHeaders() const;
/**
@@ -110,7 +110,7 @@ public:
* @param headerName The name of the header.
* @return The value of the header or std::nullopt if the header does not exist.
*/
std::optional<std::string_view>
[[nodiscard]] std::optional<std::string_view>
headerValue(boost::beast::http::field headerName) const;
/**
@@ -119,7 +119,7 @@ public:
* @param headerName The name of the header.
* @return The value of the header or std::nullopt if the header does not exist.
*/
std::optional<std::string_view>
[[nodiscard]] std::optional<std::string_view>
headerValue(std::string const& headerName) const;
private:
@@ -130,7 +130,7 @@ private:
*
* @return The HTTP request.
*/
HttpRequest const&
[[nodiscard]] HttpRequest const&
httpRequest() const;
};

View File

@@ -73,7 +73,8 @@ makeData(http::status status, MessageType message, Request const& request)
if (not request.isHttp())
return std::move(messageData).body;
auto const& httpRequest = request.asHttpRequest()->get();
auto const& httpRequest =
(*request.asHttpRequest()).get(); // NOLINT(bugprone-unchecked-optional-access)
return makeHttpData(
std::move(messageData), status, httpRequest.version(), httpRequest.keep_alive()
);
@@ -131,7 +132,8 @@ Response::Response(
)
{
ASSERT(request.isHttp(), "Request must be HTTP to construct response from HTTP response");
data = prepareResponse(std::move(response), request.asHttpRequest()->get().keep_alive());
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
data = prepareResponse(std::move(response), (*request.asHttpRequest()).get().keep_alive());
}
std::string const&

View File

@@ -87,7 +87,7 @@ public:
*
* @return The message of the response.
*/
std::string const&
[[nodiscard]] std::string const&
message() const;
/**
@@ -121,7 +121,7 @@ public:
*
* @return The message of the response as a const buffer.
*/
boost::asio::const_buffer
[[nodiscard]] boost::asio::const_buffer
asWsResponse() const&;
};

View File

@@ -300,7 +300,9 @@ Server::handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield
);
if (not connectionExpected.has_value()) {
if (connectionExpected.error().has_value()) {
LOG(log_.info()) << *connectionExpected.error();
LOG(
log_.info()
) << *connectionExpected.error(); // NOLINT(bugprone-unchecked-optional-access)
}
return;
}

View File

@@ -43,7 +43,7 @@ handleHttpRequest(
)
{
ASSERT(request.target().has_value(), "Got not a HTTP request");
auto it = handlers.find(*request.target());
auto it = handlers.find(*request.target()); // NOLINT(bugprone-unchecked-optional-access)
if (it == handlers.end()) {
return Response{boost::beast::http::status::bad_request, "Bad target", request};
}
@@ -282,7 +282,7 @@ ConnectionHandler::sequentRequestResponseLoop(
auto maybeReturnValue =
processRequest(connection, subscriptionContext, *expectedRequest, yield);
if (maybeReturnValue.has_value())
return maybeReturnValue.value();
return *maybeReturnValue;
}
}
@@ -326,7 +326,7 @@ ConnectionHandler::parallelRequestResponseLoop(
processRequest(connection, subscriptionContext, request, innerYield);
if (maybeCloseConnectionGracefully.has_value()) {
stop = true;
closeConnectionGracefully &= maybeCloseConnectionGracefully.value();
closeConnectionGracefully &= *maybeCloseConnectionGracefully;
}
}
);

View File

@@ -101,7 +101,7 @@ public:
void
stop(boost::asio::yield_context yield);
bool
[[nodiscard]] bool
isStopping() const;
private:
@@ -112,7 +112,7 @@ private:
* @param connection The connection that caused the error.
* @return True if the connection should be gracefully closed, false otherwise.
*/
bool
[[nodiscard]] bool
handleError(Error const& error, Connection const& connection) const;
/**

View File

@@ -42,7 +42,7 @@ composeErrorImpl(
if (not rawRequest.isHttp())
appendFieldIfExist(JS(api_version));
e[JS(request)] = request.value();
e[JS(request)] = *request;
}
if (not rawRequest.isHttp()) {

View File

@@ -124,7 +124,7 @@ public:
return {};
}
bool
[[nodiscard]] bool
wasUpgraded() const override
{
return false;
@@ -156,7 +156,7 @@ public:
receive(boost::asio::yield_context yield) override
{
if (request_.has_value()) {
Request result{std::move(request_).value()};
Request result{*std::move(request_)};
request_.reset();
return result;
}
@@ -196,7 +196,7 @@ public:
request_ = std::move(expectedRequest).value();
return boost::beast::websocket::is_upgrade(request_.value());
return boost::beast::websocket::is_upgrade(*request_);
}
std::expected<ConnectionPtr, Error>
@@ -211,7 +211,7 @@ public:
std::move(stream_),
std::move(ip_),
std::move(buffer_),
std::move(request_).value(),
std::move(*request_), // NOLINT(bugprone-unchecked-optional-access)
tagDecoratorFactory,
yield
);

View File

@@ -99,7 +99,7 @@ public:
return {};
}
bool
[[nodiscard]] bool
wasUpgraded() const override
{
return true;