diff --git a/.clang-tidy b/.clang-tidy index 7130dced..72151d6d 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,8 +1,3 @@ -# Note: trailing suppressions (from -modernize-use-designated-initializers -# on) are checks added in clang-tidy versions newer than the 18 this config -# was tuned for; they fire on existing code. Suppressed when the linter -# moved to clangd 22 (needed to parse libc++ 22 headers) — to be triaged -# and enabled in the lint-toolchain modernization phase. Checks: > -*, bugprone-*, @@ -17,18 +12,7 @@ Checks: > -modernize-return-braced-init-list, -misc-non-private-member-variables-in-classes, -typecheck-expression-not-modifiable-lvalue, - -misc-use-internal-linkage, - -modernize-use-designated-initializers, - -bugprone-suspicious-stringview-data-usage, - -modernize-use-ranges, - -modernize-use-starts-ends-with, - -readability-container-contains, - -readability-avoid-return-with-void-value, - -readability-redundant-casting, - -readability-use-std-min-max, - -bugprone-unused-local-non-trivial-variable, - -bugprone-optional-value-conversion, - -performance-enum-size + -misc-use-internal-linkage # Turn all the warnings from the checks above into errors. WarningsAsErrors: "*" diff --git a/.gitmodules b/.gitmodules index e8379de2..bc92b458 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,10 +2,6 @@ path = vcpkg url = https://github.com/microsoft/vcpkg.git ignore = dirty -[submodule "clangd-tidy"] - path = clangd-tidy - url = https://github.com/lljbash/clangd-tidy.git - ignore = dirty [submodule "packages/streamr-trackerless-network/test/integration/ts-integration"] path = packages/streamr-trackerless-network/test/integration/ts-integration url = https://github.com/streamr-dev/native-ts-integration.git diff --git a/MODERNIZATION.md b/MODERNIZATION.md index d09a0576..d710acaa 100644 --- a/MODERNIZATION.md +++ b/MODERNIZATION.md @@ -269,13 +269,35 @@ document/replace in 1.4. (deployment-target-26 / SDK-libc++ build, Personal Team signing); Android sanity via CI keyword. -## Phase 1.5 — Lint stack remainder +## Phase 1.5 — Lint stack remainder (PR pending) - clangd/clang-format 22 already landed in Phase 1.2 (forced by libc++ 22). - Remaining: bump the `clangd-tidy` submodule; triage the `.clang-tidy` - suppressions added in 1.2 (enable checks where cheap to satisfy, keep - suppressed with justification where not). -- **Gate**: `./lint.sh` green both platforms; any format-only diff committed - separately. +- **clangd-tidy: submodule → PyPI**. The submodule pinned tag 0.2.1 (a + single-script era); upstream 1.x is a Python package with dependencies + (attrs/cattrs/typing-extensions), so a bare checkout is no longer + runnable. The submodule is gone; `install-prerequisities.sh` does + `pipx install clangd-tidy==1.1.1` (version-pinned) on both platforms and + puts `~/.local/bin` on PATH; the 10 lint.sh call sites invoke it from + PATH. The unused `clang-tidy` symlink alias went with it. Gained since + 0.2.1: `--line-filter` clang-tidy parity, diagnostic formatter fixes, + `clangd-tidy-diff`. +- **All 11 post-18 check suppressions from Phase 1.2 removed — zero kept.** + The full-monorepo sweep fired 77 findings (plus 7 more exposed by also + dropping the nested test configs' suppressions, and 1 narrowing warning + introduced by the ranges conversion itself), all fixed in code: + readability-container-contains (26; includes two C++23 + `std::string::contains` substring cases), modernize-use-designated- + initializers (22, incl. the two nested test configs' copies — also + removed), modernize-use-ranges (8), readability-avoid-return-with-void- + value (6, `return voidFn()` in void lambdas), bugprone-suspicious- + stringview-data-usage (4, string_view constants passed to `getenv()` → + now `const char*`), readability-redundant-casting (3, self-casts of + `const DhtCallContext&`), bugprone-unused-local-non-trivial-variable + (3 dead `debugString` debug leftovers deleted), performance-enum-size + (2 enums → `std::uint8_t`), bugprone-optional-value-conversion (1, + optional→value→optional round-trip in WebsocketServer), readability- + use-std-min-max (1), modernize-use-starts-ends-with (1). +- **Gate**: `./lint.sh` green both platforms; full test suite green + (several fixes touch runtime code paths); format at fixed point. ## Phase 1.6 — CI/docs closeout - Revisit preview runner images (macos-26 / ubuntu-26.04) once GA; consider a diff --git a/README.md b/README.md index baa2564c..bcfa591f 100644 --- a/README.md +++ b/README.md @@ -121,10 +121,13 @@ On the other hand, The root directory of the monorepo has the following structure: #### GIT submodules -The Streamr Native SDK monorepo has two GIT submodules at its root: +The Streamr Native SDK monorepo has one GIT submodule at its root: * `vcpkg` - [vcpkg package manager by Microsoft](https://github.com/microsoft/vcpkg) (installing as a submodule is the recommended way of installation) -* `clangd-tidy` - [clangd-tidy](https://github.com/lljbash/clangd-tidy) A fast variant of the clang-tidy linter for C++. (not available as a brew or apt package) + +The [clangd-tidy](https://github.com/lljbash/clangd-tidy) linter (a fast +variant of clang-tidy) is installed from PyPI by +`install-prerequisities.sh` (`pipx install clangd-tidy==`). #### Directories * `build` - the main build directory for the whole monorepo. diff --git a/clangd-tidy b/clangd-tidy deleted file mode 160000 index c827cc0d..00000000 --- a/clangd-tidy +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c827cc0d69221dd0f3049b99402cbe9ed3d266c5 diff --git a/install-prerequisities.sh b/install-prerequisities.sh index aaea7b00..48aa714a 100644 --- a/install-prerequisities.sh +++ b/install-prerequisities.sh @@ -26,6 +26,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then TEMP_PROFILE_CONTENTS+="export HOMEBREW_PREFIX=$(brew --prefix)\n" brew install jq || true + brew install pipx || true # Latest LLVM (keg-only: not linked into $HOMEBREW_PREFIX/bin; the build # finds it via the LLVM_PREFIX environment variable exported below). brew install llvm || true @@ -60,7 +61,7 @@ else # come from the same LLVM version on every platform: clangd must be able # to parse libc++ 22 headers, and clang-format versions must not diverge # between macOS and Linux or the format check flip-flops. - sudo apt-get install -y build-essential cmake ninja-build jq \ + sudo apt-get install -y build-essential cmake ninja-build jq pipx \ clang-22 lld-22 clang-tools-22 clangd-22 libc++-22-dev libc++abi-22-dev \ clang-format-22 \ autoconf autoconf-archive automake libtool @@ -88,20 +89,21 @@ if [[ -n "$GITHUB_ENV" ]]; then fi TEMP_PROFILE_CONTENTS+="export CMAKE_GENERATOR=Ninja\n" -cd clangd-tidy -rm -f clang-tidy -ln -s clangd-tidy clang-tidy -cd .. - -TEMP_PROFILE_CONTENTS+="export PATH=$(pwd)/clangd-tidy:\$PATH\n" - -CLANGD_TIDY_PATH="$(pwd)/clangd-tidy" - -if [[ ":$PATH:" != *":$CLANGD_TIDY_PATH:"* ]]; then - export PATH="$CLANGD_TIDY_PATH:$PATH" - if [[ -n "$GITHUB_PATH" ]]; then - echo "$CLANGD_TIDY_PATH" >> $GITHUB_PATH - fi +# clangd-tidy (the lint driver) comes from PyPI, version-pinned. It used to +# be a git submodule, but since 1.x upstream ships it as a Python package +# with dependencies, so a bare checkout is no longer runnable. +# --force makes reruns of this script idempotent (pipx errors on an +# already-installed package otherwise). +pipx install --force "clangd-tidy==1.1.1" + +# pipx installs into ~/.local/bin, which is not on PATH everywhere. +PIPX_BIN_DIR="$HOME/.local/bin" +TEMP_PROFILE_CONTENTS+="export PATH=$PIPX_BIN_DIR:\$PATH\n" +if [[ ":$PATH:" != *":$PIPX_BIN_DIR:"* ]]; then + export PATH="$PIPX_BIN_DIR:$PATH" +fi +if [[ -n "$GITHUB_PATH" ]]; then + echo "$PIPX_BIN_DIR" >> $GITHUB_PATH fi cd vcpkg diff --git a/packages/streamr-dht/include/streamr-dht/Identifiers.hpp b/packages/streamr-dht/include/streamr-dht/Identifiers.hpp index 83ade8f5..f744fe76 100644 --- a/packages/streamr-dht/include/streamr-dht/Identifiers.hpp +++ b/packages/streamr-dht/include/streamr-dht/Identifiers.hpp @@ -44,7 +44,7 @@ struct Identifiers { static DhtAddress createRandomDhtAddress() { return getDhtAddressFromRaw(DhtAddressRaw{[&]() { std::vector randomBytes(kademliaIdLengthInBytes); - std::generate(randomBytes.begin(), randomBytes.end(), []() { + std::ranges::generate(randomBytes, []() { return static_cast(std::rand() % 256); // NOLINT }); return std::string(randomBytes.begin(), randomBytes.end()); diff --git a/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockRpcLocal.hpp b/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockRpcLocal.hpp index 3ed7a8a8..a4e79860 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockRpcLocal.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockRpcLocal.hpp @@ -43,9 +43,7 @@ class ConnectionLockRpcLocal : public ConnectionLockRpc { LockResponse lockRequest( const LockRequest& request, const DhtCallContext& callContext) override { - const auto senderPeerDescriptor = - static_cast(callContext) - .incomingSourceDescriptor; + const auto senderPeerDescriptor = callContext.incomingSourceDescriptor; if (Identifiers::areEqualPeerDescriptors( senderPeerDescriptor.value(), @@ -67,9 +65,7 @@ class ConnectionLockRpcLocal : public ConnectionLockRpc { void unlockRequest( const UnlockRequest& request, const DhtCallContext& callContext) override { - const auto senderPeerDescriptor = - static_cast(callContext) - .incomingSourceDescriptor; + const auto senderPeerDescriptor = callContext.incomingSourceDescriptor; const auto nodeId = Identifiers::getNodeIdFromPeerDescriptor( senderPeerDescriptor.value()); this->options.removeRemoteLocked(nodeId, LockID{request.lockid()}); @@ -78,9 +74,7 @@ class ConnectionLockRpcLocal : public ConnectionLockRpc { void gracefulDisconnect( const DisconnectNotice& request, const DhtCallContext& callContext) override { - const auto senderPeerDescriptor = - static_cast(callContext) - .incomingSourceDescriptor; + const auto senderPeerDescriptor = callContext.incomingSourceDescriptor; SLogger::trace( Identifiers::getNodeIdFromPeerDescriptor( senderPeerDescriptor.value()) + diff --git a/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockStates.hpp b/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockStates.hpp index e8cddf1c..bb436e0b 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockStates.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/ConnectionLockStates.hpp @@ -45,11 +45,10 @@ class ConnectionLockStates { const std::optional& lockId = std::nullopt) { std::scoped_lock lock(this->localLocksMutex); if (!lockId.has_value()) { - return this->localLocks.find(id) != this->localLocks.end(); + return this->localLocks.contains(id); } - return this->localLocks.find(id) != this->localLocks.end() && - this->localLocks.at(id).find(lockId.value()) != - this->localLocks.at(id).end(); + return this->localLocks.contains(id) && + this->localLocks.at(id).contains(lockId.value()); } [[nodiscard]] bool isRemoteLocked( @@ -57,16 +56,15 @@ class ConnectionLockStates { const std::optional& lockId = std::nullopt) { std::scoped_lock lock(this->remoteLocksMutex); if (!lockId.has_value()) { - return this->remoteLocks.find(id) != this->remoteLocks.end(); + return this->remoteLocks.contains(id); } - return this->remoteLocks.find(id) != this->remoteLocks.end() && - this->remoteLocks.at(id).find(lockId.value()) != - this->remoteLocks.at(id).end(); + return this->remoteLocks.contains(id) && + this->remoteLocks.at(id).contains(lockId.value()); } [[nodiscard]] bool isWeakLocked(const DhtAddress& id) { std::scoped_lock lock(this->weakLocksMutex); - return this->weakLocks.find(id) != this->weakLocks.end(); + return this->weakLocks.contains(id); } [[nodiscard]] bool isLocked(const DhtAddress& id) { @@ -80,7 +78,7 @@ class ConnectionLockStates { void addLocalLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->localLocksMutex); - if (this->localLocks.find(id) == this->localLocks.end()) { + if (!this->localLocks.contains(id)) { this->localLocks[id] = std::set(); } this->localLocks[id].insert(lockId); @@ -88,7 +86,7 @@ class ConnectionLockStates { void addRemoteLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->remoteLocksMutex); - if (this->remoteLocks.find(id) == this->remoteLocks.end()) { + if (!this->remoteLocks.contains(id)) { this->remoteLocks[id] = std::set(); } this->remoteLocks[id].insert(lockId); @@ -96,7 +94,7 @@ class ConnectionLockStates { void addWeakLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->weakLocksMutex); - if (this->weakLocks.find(id) == this->weakLocks.end()) { + if (!this->weakLocks.contains(id)) { this->weakLocks[id] = std::set(); } this->weakLocks[id].insert(lockId); @@ -104,7 +102,7 @@ class ConnectionLockStates { void removeLocalLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->localLocksMutex); - if (this->localLocks.find(id) != this->localLocks.end()) { + if (this->localLocks.contains(id)) { this->localLocks[id].erase(lockId); if (this->localLocks[id].empty()) { this->localLocks.erase(id); @@ -114,7 +112,7 @@ class ConnectionLockStates { void removeRemoteLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->remoteLocksMutex); - if (this->remoteLocks.find(id) != this->remoteLocks.end()) { + if (this->remoteLocks.contains(id)) { this->remoteLocks[id].erase(lockId); if (this->remoteLocks[id].empty()) { this->remoteLocks.erase(id); @@ -124,7 +122,7 @@ class ConnectionLockStates { void removeWeakLocked(const DhtAddress& id, const LockID& lockId) { std::scoped_lock lock(this->weakLocksMutex); - if (this->weakLocks.find(id) != this->weakLocks.end()) { + if (this->weakLocks.contains(id)) { this->weakLocks[id].erase(lockId); if (this->weakLocks[id].empty()) { this->weakLocks.erase(id); diff --git a/packages/streamr-dht/include/streamr-dht/connection/ConnectionManager.hpp b/packages/streamr-dht/include/streamr-dht/connection/ConnectionManager.hpp index 7df7691e..a88d7fab 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/ConnectionManager.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/ConnectionManager.hpp @@ -1,6 +1,7 @@ #ifndef STREAMR_DHT_CONNECTION_CONNECTIONMANAGER_HPP #define STREAMR_DHT_CONNECTION_CONNECTIONMANAGER_HPP +#include #include #include #include @@ -52,7 +53,12 @@ namespace endpointevents = streamr::dht::connection::endpoint::endpointevents; using namespace std::chrono_literals; -enum class ConnectionManagerState { IDLE, RUNNING, STOPPING, STOPPED }; +enum class ConnectionManagerState : std::uint8_t { + IDLE, + RUNNING, + STOPPING, + STOPPED +}; struct ConnectionManagerOptions { size_t maxConnections; @@ -89,7 +95,7 @@ class ConnectionManager : public Transport, "Trying to acquire mutex lock in endpoint callback"); std::scoped_lock lock(this->endpointsMutex); SLogger::debug("Acquired mutex lock in endpoint callback"); - if (this->endpoints.find(nodeId) != this->endpoints.end()) { + if (this->endpoints.contains(nodeId)) { this->endpoints.erase(nodeId); } } @@ -129,7 +135,7 @@ class ConnectionManager : public Transport, [this](const Message& message, const SendOptions& sendOptions) { SLogger::trace( "outgoingmessagecallback() of rpcCommunicator"); - return this->send(message, sendOptions); + this->send(message, sendOptions); }, RpcCommunicatorOptions{.rpcRequestTimeout = 10s}), // NOLINT connectionLockRpcLocal( @@ -166,13 +172,12 @@ class ConnectionManager : public Transport, this->rpcCommunicator.registerRpcNotification( "unlockRequest", [this](const UnlockRequest& req, const DhtCallContext& context) { - return this->connectionLockRpcLocal.unlockRequest(req, context); + this->connectionLockRpcLocal.unlockRequest(req, context); }); this->rpcCommunicator.registerRpcNotification( "gracefulDisconnect", [this](const DisconnectNotice& req, const DhtCallContext& context) { - return this->connectionLockRpcLocal.gracefulDisconnect( - req, context); + this->connectionLockRpcLocal.gracefulDisconnect(req, context); }); SLogger::debug("ConnectionManager constructor end"); } @@ -292,7 +297,7 @@ class ConnectionManager : public Transport, std::scoped_lock lock(this->endpointsMutex); SLogger::debug("Acquired mutex lock in send"); - if (this->endpoints.find(nodeId) == this->endpoints.end()) { + if (!this->endpoints.contains(nodeId)) { SLogger::debug("Node ID not found in endpoints"); if (sendOptions.connect) { SLogger::debug("Creating new connection"); @@ -302,7 +307,7 @@ class ConnectionManager : public Transport, SLogger::debug("Created new connection"); this->onNewConnection(connection); SLogger::debug("Handled new connection"); - if (this->endpoints.find(nodeId) == this->endpoints.end()) { + if (!this->endpoints.contains(nodeId)) { SLogger::debug( "Node ID not found in endpoints after creating new connection, this means that the connection failed"); throw SendFailed( @@ -424,7 +429,7 @@ class ConnectionManager : public Transport, SLogger::debug("Trying to acquire mutex lock in unlockConnection"); std::scoped_lock lock(this->endpointsMutex); SLogger::debug("Acquired mutex lock in unlockConnection"); - if (this->endpoints.find(nodeId) == this->endpoints.end()) { + if (!this->endpoints.contains(nodeId)) { SLogger::debug("Node ID not found in endpoints"); return; } @@ -512,7 +517,7 @@ class ConnectionManager : public Transport, std::scoped_lock lock(this->endpointsMutex); SLogger::debug("Acquired mutex lock in acceptNewConnection"); - if (this->endpoints.find(nodeId) != this->endpoints.end()) { + if (this->endpoints.contains(nodeId)) { if (OffererHelper::getOfferer( Identifiers::getNodeIdFromPeerDescriptor( this->getLocalPeerDescriptor()), @@ -580,8 +585,6 @@ class ConnectionManager : public Transport, "gracefullyDisconnected() tried on a non-existing connection"); return; } - auto debugString = targetDescriptor.DebugString(); - if (endpoint->isConnected()) { try { SLogger::debug("gracefullyDisconnect() calling blockingWait()"); @@ -600,9 +603,6 @@ class ConnectionManager : public Transport, targetDescriptor, disconnectMode]() -> folly::coro::Task { - auto debugString = - targetDescriptor.DebugString(); - co_return co_await this ->doGracefullyDisconnectAsync( targetDescriptor, diff --git a/packages/streamr-dht/include/streamr-dht/connection/Handshaker.hpp b/packages/streamr-dht/include/streamr-dht/connection/Handshaker.hpp index eb108508..1e35c765 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/Handshaker.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/Handshaker.hpp @@ -152,7 +152,6 @@ class Handshaker : public EventEmitter, auto self = this->sharedFromThis(); Message message; message.ParseFromArray(data.data(), static_cast(data.size())); - const auto debugString = message.DebugString(); SLogger::trace( "Handshaker::onData() handshake message received " + message.DebugString()); diff --git a/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketClientConnector.hpp b/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketClientConnector.hpp index a7add353..0c711063 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketClientConnector.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketClientConnector.hpp @@ -55,8 +55,7 @@ class WebsocketClientConnector { }, .hasConnection = [this](const DhtAddress& nodeId) -> bool { std::scoped_lock lock(this->mutex); - return this->connectingHandshakers.find(nodeId) != - this->connectingHandshakers.end() || + return this->connectingHandshakers.contains(nodeId) || this->options.hasConnection(nodeId); }, .onNewConnection = @@ -76,7 +75,7 @@ class WebsocketClientConnector { if (this->abortController.getSignal().aborted) { return; } - return this->rpcLocal.requestConnection(req, context); + this->rpcLocal.requestConnection(req, context); }); } @@ -122,8 +121,7 @@ class WebsocketClientConnector { outgoingHandshaker->on( [this, nodeId]() { std::scoped_lock lock(this->mutex); - if (this->connectingHandshakers.find(nodeId) != - this->connectingHandshakers.end()) { + if (this->connectingHandshakers.contains(nodeId)) { this->connectingHandshakers.erase(nodeId); } }); diff --git a/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketServer.hpp b/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketServer.hpp index b0be3428..24a70908 100644 --- a/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketServer.hpp +++ b/packages/streamr-dht/include/streamr-dht/connection/websocket/WebsocketServer.hpp @@ -77,9 +77,8 @@ class WebsocketServer : public EventEmitter { return port; } catch (const WebsocketServerStartError& err) { if (err.originalErrorInfo.has_value() && - err.originalErrorInfo.value().find( - "TCP server socket binding failed") != - std::string::npos) { + err.originalErrorInfo.value().contains( + "TCP server socket binding failed")) { SLogger::warn( "failed to start WebSocket server on port: " + std::to_string(port) + " reattempting on next port"); @@ -193,7 +192,7 @@ class WebsocketServer : public EventEmitter { if (mConfig.maxMessageSize.has_value() && mConfig.maxMessageSize.value() > 0) { webSocketServerConfiguration.maxMessageSize = - mConfig.maxMessageSize.value(); + mConfig.maxMessageSize; } if (certs || mConfig.tlsCertificateFiles || tls) { diff --git a/packages/streamr-dht/include/streamr-dht/dht/routing/DuplicateDetector.hpp b/packages/streamr-dht/include/streamr-dht/dht/routing/DuplicateDetector.hpp index 26a1bd92..cafb5914 100644 --- a/packages/streamr-dht/include/streamr-dht/dht/routing/DuplicateDetector.hpp +++ b/packages/streamr-dht/include/streamr-dht/dht/routing/DuplicateDetector.hpp @@ -34,7 +34,7 @@ class DuplicateDetector { [[nodiscard]] bool isMostLikelyDuplicate(const std::string& value) { std::scoped_lock lock(this->valuesMutex); - return this->values.find(value) != this->values.end(); + return this->values.contains(value); } [[nodiscard]] size_t size() { diff --git a/packages/streamr-dht/include/streamr-dht/helpers/Offerer.hpp b/packages/streamr-dht/include/streamr-dht/helpers/Offerer.hpp index 440836bd..b368580c 100644 --- a/packages/streamr-dht/include/streamr-dht/helpers/Offerer.hpp +++ b/packages/streamr-dht/include/streamr-dht/helpers/Offerer.hpp @@ -1,6 +1,7 @@ #ifndef STREAMR_DHT_OFFERER_HPP #define STREAMR_DHT_OFFERER_HPP +#include #include #include #include @@ -10,7 +11,7 @@ namespace streamr::dht::helpers { using streamr::dht::DhtAddress; -enum class Offerer { LOCAL, REMOTE }; +enum class Offerer : std::uint8_t { LOCAL, REMOTE }; class OffererHelper { public: diff --git a/packages/streamr-dht/include/streamr-dht/transport/RoutingRpcCommunicator.hpp b/packages/streamr-dht/include/streamr-dht/transport/RoutingRpcCommunicator.hpp index bb7a4b7c..b4956631 100644 --- a/packages/streamr-dht/include/streamr-dht/transport/RoutingRpcCommunicator.hpp +++ b/packages/streamr-dht/include/streamr-dht/transport/RoutingRpcCommunicator.hpp @@ -98,7 +98,7 @@ class RoutingRpcCommunicator : public RpcCommunicator { } } SLogger::debug("Calling sendFn with message and sendOpts"); - return this->sendFn(message, sendOpts); + this->sendFn(message, sendOpts); }); } void handleMessageFromPeer(const Message& message) { diff --git a/packages/streamr-dht/lint.sh b/packages/streamr-dht/lint.sh index 07e6fd8c..e03813d6 100755 --- a/packages/streamr-dht/lint.sh +++ b/packages/streamr-dht/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name test -o -name include \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-dht/test/unit/WebsocketServerTest.cpp b/packages/streamr-dht/test/unit/WebsocketServerTest.cpp index 3a9d2bcb..18c03f06 100644 --- a/packages/streamr-dht/test/unit/WebsocketServerTest.cpp +++ b/packages/streamr-dht/test/unit/WebsocketServerTest.cpp @@ -42,7 +42,8 @@ TEST(WebsocketServerTest, TestCanThrowIfCertificateNotFound) { .portRange = {10000, 10001}, // NOLINT .enableTls = false, .tlsCertificateFiles = - std::optional{TlsCertificateFiles{"", ""}}, + std::optional{TlsCertificateFiles{ + .privateKeyFileName = "", .certFileName = ""}}, .maxMessageSize = std::nullopt}; WebsocketServer server(std::move(config)); EXPECT_THROW(server.start(), WebsocketServerStartError); // NOLINT @@ -57,7 +58,8 @@ TEST( .enableTls = false, .tlsCertificateFiles = std::optional{TlsCertificateFiles{ - "../test/unit/example.key", "../test/unit/example.crt"}}, + .privateKeyFileName = "../test/unit/example.key", + .certFileName = "../test/unit/example.crt"}}, .maxMessageSize = std::nullopt}; WebsocketServer server(std::move(config)); server.start(); @@ -70,7 +72,8 @@ TEST(WebsocketServerTest, DISABLED_UpdateCertificate) { .enableTls = true, .tlsCertificateFiles = std::optional{TlsCertificateFiles{ - "../test/unit/example.key", "../test/unit/example.crt"}}, + .privateKeyFileName = "../test/unit/example.key", + .certFileName = "../test/unit/example.crt"}}, .maxMessageSize = std::nullopt}; WebsocketServer server(std::move(config)); @@ -135,7 +138,8 @@ TEST(WebsocketServerTest, DISABLED_UpdateCertificateWithInvalidCertificate) { .enableTls = true, .tlsCertificateFiles = std::optional{TlsCertificateFiles{ - "../test/unit/example.key", "../test/unit/example.crt"}}, + .privateKeyFileName = "../test/unit/example.key", + .certFileName = "../test/unit/example.crt"}}, .maxMessageSize = std::nullopt}; WebsocketServer server(std::move(config)); diff --git a/packages/streamr-eventemitter/lint.sh b/packages/streamr-eventemitter/lint.sh index 5e834965..f334448a 100755 --- a/packages/streamr-eventemitter/lint.sh +++ b/packages/streamr-eventemitter/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-eventemitter/test/.clang-tidy b/packages/streamr-eventemitter/test/.clang-tidy index 809420af..b7ce2b09 100644 --- a/packages/streamr-eventemitter/test/.clang-tidy +++ b/packages/streamr-eventemitter/test/.clang-tidy @@ -11,9 +11,8 @@ Checks: > -modernize-use-trailing-return-type, -modernize-return-braced-init-list, -misc-non-private-member-variables-in-classes, - -misc-use-internal-linkage, - -modernize-use-designated-initializers - + -misc-use-internal-linkage + # Turn all the warnings from the checks above into errors. WarningsAsErrors: "*" HeaderFilterRegex: ".*$" diff --git a/packages/streamr-json/lint.sh b/packages/streamr-json/lint.sh index 5e834965..f334448a 100755 --- a/packages/streamr-json/lint.sh +++ b/packages/streamr-json/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-json/test/unit/toJsonTest.cpp b/packages/streamr-json/test/unit/toJsonTest.cpp index 273439a9..9fa5b63d 100644 --- a/packages/streamr-json/test/unit/toJsonTest.cpp +++ b/packages/streamr-json/test/unit/toJsonTest.cpp @@ -265,15 +265,19 @@ TEST_F(ToJsonTest, TestWeatherDataSmartPointersToJson) { auto finlandDataSample = std::make_shared(); finlandDataSample->locality = "Helsinki"; - finlandDataSample->temperatures.push_back({23.4, 1}); - finlandDataSample->temperatures.push_back({24.5, 1000}); + finlandDataSample->temperatures.push_back( + {.temperature = 23.4, .timestamp = 1}); + finlandDataSample->temperatures.push_back( + {.temperature = 24.5, .timestamp = 1000}); weatherDataSmartPointers.dataByCountry["Finland"].push_back( finlandDataSample); auto swedenDataSample = std::make_shared(); swedenDataSample->locality = "Stockholm"; - swedenDataSample->temperatures.push_back({22.0, 1}); - swedenDataSample->temperatures.push_back({21.6, 1000}); + swedenDataSample->temperatures.push_back( + {.temperature = 22.0, .timestamp = 1}); + swedenDataSample->temperatures.push_back( + {.temperature = 21.6, .timestamp = 1000}); weatherDataSmartPointers.dataByCountry["Sweden"].push_back( swedenDataSample); @@ -286,15 +290,18 @@ TEST_F(ToJsonTest, TestWeatherDataRegularPointersToJson) { weatherDataRegularPointers.dataLabel = new std::string("Test data"); auto* finlandSample = new DataSample; finlandSample->locality = "Helsinki"; - finlandSample->temperatures.push_back({23.4, 1}); - finlandSample->temperatures.push_back({24.5, 1000}); + finlandSample->temperatures.push_back( + {.temperature = 23.4, .timestamp = 1}); + finlandSample->temperatures.push_back( + {.temperature = 24.5, .timestamp = 1000}); weatherDataRegularPointers.dataByCountry["Finland"].push_back( finlandSample); auto* swedenSample = new DataSample; swedenSample->locality = "Stockholm"; - swedenSample->temperatures.push_back({22.0, 1}); - swedenSample->temperatures.push_back({21.6, 1000}); + swedenSample->temperatures.push_back({.temperature = 22.0, .timestamp = 1}); + swedenSample->temperatures.push_back( + {.temperature = 21.6, .timestamp = 1000}); weatherDataRegularPointers.dataByCountry["Sweden"].push_back(swedenSample); json expectedJson = R"( { diff --git a/packages/streamr-libstreamrproxyclient/lint.sh b/packages/streamr-libstreamrproxyclient/lint.sh index 36a0087a..f26b6ea2 100755 --- a/packages/streamr-libstreamrproxyclient/lint.sh +++ b/packages/streamr-libstreamrproxyclient/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/android/*' ! -path '*/android-library-module/*' ! -path '*/ios/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-libstreamrproxyclient/wrappers/cpp/include/StreamrProxyClient.hpp b/packages/streamr-libstreamrproxyclient/wrappers/cpp/include/StreamrProxyClient.hpp index c3cd565e..fd334677 100644 --- a/packages/streamr-libstreamrproxyclient/wrappers/cpp/include/StreamrProxyClient.hpp +++ b/packages/streamr-libstreamrproxyclient/wrappers/cpp/include/StreamrProxyClient.hpp @@ -80,8 +80,8 @@ struct StreamrProxyAddress { static StreamrProxyAddress fromCProxy(const Proxy* proxy) { return StreamrProxyAddress{ - std::string(proxy->websocketUrl), - std::string(proxy->ethereumAddress)}; + .websocketUrl = std::string(proxy->websocketUrl), + .ethereumAddress = std::string(proxy->ethereumAddress)}; } }; @@ -210,7 +210,8 @@ class StreamrProxyClient { cProxies.reserve(proxies.size()); for (const auto& proxy : proxies) { cProxies.push_back( - {proxy.websocketUrl.c_str(), proxy.ethereumAddress.c_str()}); + {.websocketUrl = proxy.websocketUrl.c_str(), + .ethereumAddress = proxy.ethereumAddress.c_str()}); } proxyClientConnect( &result, this->proxyClientHandle, cProxies.data(), cProxies.size()); diff --git a/packages/streamr-libstreamrproxyclient/wrappers/cpp/test/StreamrProxyClientCppWrapperTest.cpp b/packages/streamr-libstreamrproxyclient/wrappers/cpp/test/StreamrProxyClientCppWrapperTest.cpp index 053edc3e..1b875707 100644 --- a/packages/streamr-libstreamrproxyclient/wrappers/cpp/test/StreamrProxyClientCppWrapperTest.cpp +++ b/packages/streamr-libstreamrproxyclient/wrappers/cpp/test/StreamrProxyClientCppWrapperTest.cpp @@ -55,7 +55,8 @@ TEST_F(StreamrProxyClientCppWrapperTest, InvalidProxyUrlCpp) { validEthereumAddress, validPrivateKey, validStreamPartId); std::vector proxies = { - {invalidProxyUrl, validEthereumAddress}}; + {.websocketUrl = invalidProxyUrl, + .ethereumAddress = validEthereumAddress}}; auto result = client.connect(proxies); EXPECT_EQ(result.successful.size(), 0); @@ -82,9 +83,12 @@ TEST_F(StreamrProxyClientCppWrapperTest, ThreeProxyConnectionsFailedCpp) { goodEthereumAddress, validPrivateKey, validStreamPartId); std::vector proxies = { - {nonExistentProxyUrl0, validEthereumAddress}, - {nonExistentProxyUrl1, validEthereumAddress2}, - {nonExistentProxyUrl2, validEthereumAddress3}}; + {.websocketUrl = nonExistentProxyUrl0, + .ethereumAddress = validEthereumAddress}, + {.websocketUrl = nonExistentProxyUrl1, + .ethereumAddress = validEthereumAddress2}, + {.websocketUrl = nonExistentProxyUrl2, + .ethereumAddress = validEthereumAddress3}}; auto result = client.connect(proxies); diff --git a/packages/streamr-logger/include/streamr-logger/Logger.hpp b/packages/streamr-logger/include/streamr-logger/Logger.hpp index c233234d..39e2cd53 100644 --- a/packages/streamr-logger/include/streamr-logger/Logger.hpp +++ b/packages/streamr-logger/include/streamr-logger/Logger.hpp @@ -14,7 +14,9 @@ namespace streamr::logger { using streamr::json::StreamrJsonInitializerList; using streamr::json::toJson; -constexpr std::string_view envLogLevelName = "LOG_LEVEL"; +// const char* (not string_view): passed to getenv(), which needs a +// null-terminated string. +constexpr const char* envLogLevelName = "LOG_LEVEL"; class Logger { private: std::shared_ptr mLoggerImpl; @@ -46,7 +48,7 @@ class Logger { // use it as the default log level for this logger. // Otherwise, use the defaultLogLevel. - char* val = getenv(envLogLevelName.data()); + char* val = getenv(envLogLevelName); if (val) { mLoggerLogLevel = getStreamrLogLevelByName(val, defaultLogLevel); } else { diff --git a/packages/streamr-logger/include/streamr-logger/detail/FollyLoggerImpl.hpp b/packages/streamr-logger/include/streamr-logger/detail/FollyLoggerImpl.hpp index bc836ff8..4ad2a4e7 100644 --- a/packages/streamr-logger/include/streamr-logger/detail/FollyLoggerImpl.hpp +++ b/packages/streamr-logger/include/streamr-logger/detail/FollyLoggerImpl.hpp @@ -24,8 +24,10 @@ namespace streamr::logger::detail { using LoggerImpl = streamr::logger::LoggerImpl; constexpr std::string_view envCategoryLogLevelName = "LOG_LEVEL_"; -constexpr std::string_view envThreadIdName = "LOG_THREAD_ID"; -constexpr std::string_view envFunctionName = "LOG_FUNCTION_NAME"; +// const char* (not string_view): passed to getenv(), which needs +// null-terminated strings. +constexpr const char* envThreadIdName = "LOG_THREAD_ID"; +constexpr const char* envFunctionName = "LOG_FUNCTION_NAME"; class FollyLoggerImpl : public LoggerImpl { private: @@ -44,8 +46,8 @@ class FollyLoggerImpl : public LoggerImpl { mLogHandlerFactory = std::make_unique(mWriterFactory.get()); - mLogThreadId = getenv(envThreadIdName.data()) != nullptr; - mLogFunctionName = getenv(envFunctionName.data()) != nullptr; + mLogThreadId = getenv(envThreadIdName) != nullptr; + mLogFunctionName = getenv(envFunctionName) != nullptr; } void init(const streamr::logger::StreamrLogLevel logLevel) override { @@ -96,7 +98,7 @@ class FollyLoggerImpl : public LoggerImpl { for (char** env = environ; *env != nullptr; ++env) { const std::string envVar = *env; - if (envVar.find(envCategoryLogLevelName) == 0) { + if (envVar.starts_with(envCategoryLogLevelName)) { std::string envCategory = envVar.substr( envCategoryLogLevelName.size(), envVar.find('=') - envCategoryLogLevelName.size()); diff --git a/packages/streamr-logger/include/streamr-logger/detail/LogLevelMap.hpp b/packages/streamr-logger/include/streamr-logger/detail/LogLevelMap.hpp index 9f5ccda1..b00a7dad 100644 --- a/packages/streamr-logger/include/streamr-logger/detail/LogLevelMap.hpp +++ b/packages/streamr-logger/include/streamr-logger/detail/LogLevelMap.hpp @@ -45,8 +45,8 @@ struct LogLevelMap { [[nodiscard]] constexpr folly::LogLevel streamrLevelToFollyLevel( const StreamrLogLevel& key) const { - const auto* const itr = std::find_if( - begin(mData), end(mData), [&key](const Mapping& mapping) { + const auto* const itr = + std::ranges::find_if(mData, [&key](const Mapping& mapping) { return mapping.first.index() == key.index(); }); if (itr != end(mData)) { @@ -57,10 +57,9 @@ struct LogLevelMap { [[nodiscard]] constexpr StreamrLogLevel follyLevelToStreamrLevel( const folly::LogLevel& key) const { - const auto* const itr = std::find_if( - begin(mData), end(mData), [&key](const Mapping& mapping) { - return mapping.second == key; - }); + const auto* const itr = std::ranges::find_if( + mData, + [&key](const Mapping& mapping) { return mapping.second == key; }); if (itr != end(mData)) { return itr->first; } @@ -69,8 +68,8 @@ struct LogLevelMap { [[nodiscard]] constexpr folly::LogLevel streamrLevelNameToFollyLevel( const std::string_view& name) const { - const auto* const itr = std::find_if( - begin(mData), end(mData), [&name](const Mapping& mapping) { + const auto* const itr = + std::ranges::find_if(mData, [&name](const Mapping& mapping) { return std::visit( [&name](const auto& v) { return v.name == name; }, mapping.first); diff --git a/packages/streamr-logger/include/streamr-logger/detail/StreamrLogFormatter.hpp b/packages/streamr-logger/include/streamr-logger/detail/StreamrLogFormatter.hpp index 4cb3bb7a..84b98afc 100644 --- a/packages/streamr-logger/include/streamr-logger/detail/StreamrLogFormatter.hpp +++ b/packages/streamr-logger/include/streamr-logger/detail/StreamrLogFormatter.hpp @@ -16,7 +16,9 @@ namespace streamr::logger::detail { namespace constants { -constexpr std::string_view logColorsEnvVar = "LOG_COLORS"; +// const char* (not string_view): passed to getenv(), which needs a +// null-terminated string. +constexpr const char* logColorsEnvVar = "LOG_COLORS"; // If you change MaxFileNameAndLineNumberLength, then please change it in // nonTruncatedFormatterPart too @@ -66,11 +68,11 @@ class StreamrLogFormatter : public folly::LogFormatter { const folly::LogMessage& message, const folly::LogCategory* /* handlerCategory */) override { return formatMessageInStreamrStyle( - {message.getTimestamp(), - message.getFileBaseName(), - message.getLineNumber(), - message.getLevel(), - message.getMessage()}); + {.timestamp = message.getTimestamp(), + .fileBasename = message.getFileBaseName(), + .lineNumber = message.getLineNumber(), + .logLevel = message.getLevel(), + .logMessage = message.getMessage()}); } struct LogLevelNameAndColor { std::string_view logLevelName; @@ -100,11 +102,11 @@ class StreamrLogFormatter : public folly::LogFormatter { }, streamrLevel); - return {logLevelName, color}; + return {.logLevelName = logLevelName, .color = color}; } static bool getColorsSettingFromEnv() { - const auto* const env = std::getenv(constants::logColorsEnvVar.data()); + const auto* const env = std::getenv(constants::logColorsEnvVar); return (env == nullptr || std::string_view(env) != "false"); } diff --git a/packages/streamr-logger/lint.sh b/packages/streamr-logger/lint.sh index 5e834965..f334448a 100755 --- a/packages/streamr-logger/lint.sh +++ b/packages/streamr-logger/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-logger/src/examples/LoggerExample.cpp b/packages/streamr-logger/src/examples/LoggerExample.cpp index 884544c2..2d43825e 100644 --- a/packages/streamr-logger/src/examples/LoggerExample.cpp +++ b/packages/streamr-logger/src/examples/LoggerExample.cpp @@ -43,7 +43,7 @@ class LoggerExample { i); } - auto data = MyDataStruct{"count", loopCount}; + auto data = MyDataStruct{.name = "count", .value = loopCount}; Logger localLogger3(data, streamrloglevel::Info{}); for (int i = 0; i < loopCount; i++) { diff --git a/packages/streamr-logger/test/.clang-tidy b/packages/streamr-logger/test/.clang-tidy index 809420af..b7ce2b09 100644 --- a/packages/streamr-logger/test/.clang-tidy +++ b/packages/streamr-logger/test/.clang-tidy @@ -11,9 +11,8 @@ Checks: > -modernize-use-trailing-return-type, -modernize-return-braced-init-list, -misc-non-private-member-variables-in-classes, - -misc-use-internal-linkage, - -modernize-use-designated-initializers - + -misc-use-internal-linkage + # Turn all the warnings from the checks above into errors. WarningsAsErrors: "*" HeaderFilterRegex: ".*$" diff --git a/packages/streamr-logger/test/unit/StreamrLogFormatterTest.cpp b/packages/streamr-logger/test/unit/StreamrLogFormatterTest.cpp index a3b724a2..eee908aa 100644 --- a/packages/streamr-logger/test/unit/StreamrLogFormatterTest.cpp +++ b/packages/streamr-logger/test/unit/StreamrLogFormatterTest.cpp @@ -25,7 +25,11 @@ class StreamrLogFormatterTest : public testing::Test { TEST_F(StreamrLogFormatterTest, traceNoTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), "Filename.cpp", lineNumber2, folly::LogLevel::DBG, "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber2, + .logLevel = folly::LogLevel::DBG, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -35,11 +39,11 @@ TEST_F(StreamrLogFormatterTest, traceNoTruncate) { TEST_F(StreamrLogFormatterTest, traceTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), - "1234567890123456789012345678901234567890.cpp", - lineNumber2, - folly::LogLevel::DBG, - "Message"}; + .timestamp = getTp(), + .fileBasename = "1234567890123456789012345678901234567890.cpp", + .lineNumber = lineNumber2, + .logLevel = folly::LogLevel::DBG, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -49,7 +53,11 @@ TEST_F(StreamrLogFormatterTest, traceTruncate) { TEST_F(StreamrLogFormatterTest, debugNoTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), "Filename.cpp", lineNumber, folly::LogLevel::DBG0, "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber, + .logLevel = folly::LogLevel::DBG0, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -59,7 +67,11 @@ TEST_F(StreamrLogFormatterTest, debugNoTruncate) { TEST_F(StreamrLogFormatterTest, infoNoTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), "Filename.cpp", lineNumber, folly::LogLevel::INFO, "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber, + .logLevel = folly::LogLevel::INFO, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -69,7 +81,11 @@ TEST_F(StreamrLogFormatterTest, infoNoTruncate) { TEST_F(StreamrLogFormatterTest, warnoNoTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), "Filename.cpp", lineNumber, folly::LogLevel::WARN, "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber, + .logLevel = folly::LogLevel::WARN, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -79,7 +95,11 @@ TEST_F(StreamrLogFormatterTest, warnoNoTruncate) { TEST_F(StreamrLogFormatterTest, errorNoTruncate) { StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), "Filename.cpp", lineNumber, folly::LogLevel::ERR, "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber, + .logLevel = folly::LogLevel::ERR, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), @@ -91,11 +111,11 @@ TEST_F(StreamrLogFormatterTest, fatalNoTruncate) { // Cannot use FATAL in Folly because it aborts, CRITICAL is converted to // FATAL StreamrLogFormatter::StreamrLogMessage msg = { - getTp(), - "Filename.cpp", - lineNumber, - folly::LogLevel::CRITICAL, - "Message"}; + .timestamp = getTp(), + .fileBasename = "Filename.cpp", + .lineNumber = lineNumber, + .logLevel = folly::LogLevel::CRITICAL, + .logMessage = "Message"}; EXPECT_THAT( getFormatter().formatMessageInStreamrStyle(msg), diff --git a/packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp b/packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp index 53953cac..230136f9 100644 --- a/packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp +++ b/packages/streamr-proto-rpc/include/streamr-proto-rpc/StreamPrinter.hpp @@ -1,6 +1,7 @@ #ifndef STREAMER_PROTORPC_PLUGIN_STREAM_PRINTER_HPP #define STREAMER_PROTORPC_PLUGIN_STREAM_PRINTER_HPP +#include #include namespace streamr::protorpc { @@ -27,10 +28,8 @@ class StreamPrinter { if (buffer && bufferSize > 0) { // compute dumpsize - int64_t dumpSize = iLength - dumpIndex; - if (dumpSize > bufferSize) { - dumpSize = bufferSize; - } + const int64_t dumpSize = + std::min(iLength - dumpIndex, bufferSize); // dump const unsigned char* dumpData = &iValue[dumpIndex]; diff --git a/packages/streamr-proto-rpc/lint.sh b/packages/streamr-proto-rpc/lint.sh index 4df7df06..f0dfb6cd 100755 --- a/packages/streamr-proto-rpc/lint.sh +++ b/packages/streamr-proto-rpc/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) ! -name "PluginCodeGenerator.hpp" -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp b/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp index 245feae9..59612530 100644 --- a/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp +++ b/packages/streamr-proto-rpc/test/integration/ProtoRpcTest.cpp @@ -132,7 +132,7 @@ TEST_F(ProtoRpcClientTest, TestCanMakeRpcNotification) { "wakeUp", [&wakeUpService]( const WakeUpRequest& request, const ProtoCallContext& context) { - return wakeUpService.wakeUp(request, context); + wakeUpService.wakeUp(request, context); }); setCallbacks(false); std::promise promise; diff --git a/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp b/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp index 7425a125..032c467c 100644 --- a/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp +++ b/packages/streamr-proto-rpc/test/unit/RpcCommunicatorTest.cpp @@ -243,8 +243,7 @@ TEST_F(RpcCommunicatorTest, TestrequestServerThrowsRuntimeError) { EXPECT_TRUE(false); } catch (const RpcServerError& ex) { EXPECT_EQ(ex.code, ErrorCode::RPC_SERVER_ERROR); - EXPECT_TRUE( - ex.errorClassName.find("runtime_error") != std::string::npos); + EXPECT_TRUE(ex.errorClassName.contains("runtime_error")); EXPECT_EQ(ex.message, "TestException"); } catch (...) { EXPECT_TRUE(false); @@ -286,8 +285,7 @@ TEST_F(RpcCommunicatorTest, TestrequestServerThrowsFailedToParse) { } catch (const RpcServerError& ex) { EXPECT_EQ(ex.code, ErrorCode::RPC_SERVER_ERROR); EXPECT_EQ(ex.errorCode, "FAILED_TO_PARSE"); - EXPECT_TRUE( - ex.errorClassName.find("FailedToParse") != std::string::npos); + EXPECT_TRUE(ex.errorClassName.contains("FailedToParse")); } catch (...) { EXPECT_TRUE(false); } diff --git a/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyClient.hpp b/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyClient.hpp index 4ac78275..1ffc3d78 100644 --- a/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyClient.hpp +++ b/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyClient.hpp @@ -313,7 +313,9 @@ class ProxyClient : public EventEmitter { peerDescriptor, LockID{SERVICE_ID}); this->connections.emplace( - nodeId, ProxyConnection{peerDescriptor, direction}); + nodeId, + ProxyConnection{ + .peerDescriptor = peerDescriptor, .direction = direction}); ContentDeliveryRpcClient client{this->rpcCommunicator}; const auto remote = std::make_shared( @@ -337,11 +339,10 @@ class ProxyClient : public EventEmitter { void closeRandomConnections(size_t connectionCount) { std::vector> proxiesToDisconnect; - std::sample( - this->connections.begin(), - this->connections.end(), + std::ranges::sample( + this->connections, std::back_inserter(proxiesToDisconnect), - connectionCount, + static_cast(connectionCount), std::mt19937{std::random_device{}()}); for (const auto& nodeId : proxiesToDisconnect) { diff --git a/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyConnectionRpcLocal.hpp b/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyConnectionRpcLocal.hpp index 38c7ab36..78217374 100644 --- a/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyConnectionRpcLocal.hpp +++ b/packages/streamr-trackerless-network/include/streamr-trackerless-network/logic/proxy/ProxyConnectionRpcLocal.hpp @@ -96,7 +96,7 @@ class ProxyConnectionRpcLocal } bool hasConnection(const DhtAddress& nodeId) const { - return this->connections.find(nodeId) != this->connections.end(); + return this->connections.contains(nodeId); } void removeConnection(const DhtAddress& nodeId) { diff --git a/packages/streamr-trackerless-network/lint.sh b/packages/streamr-trackerless-network/lint.sh index 93c7763f..73dcd449 100755 --- a/packages/streamr-trackerless-network/lint.sh +++ b/packages/streamr-trackerless-network/lint.sh @@ -6,7 +6,7 @@ SRCFILES=$(find src -type f \( -name "*.hpp" -o -name "*.cpp" \) -not -path '*/p if [ -n "$SRCFILES" ]; then echo "Running clangd-tidy on $SRCFILES" - ../../clangd-tidy/clangd-tidy -p ./build $SRCFILES + clangd-tidy -p ./build $SRCFILES echo "Running clang-format --dry-run on $SRCFILES" ../../run-clang-format.py $SRCFILES @@ -15,7 +15,7 @@ fi TESTFILES=$(find test -type f \( -name "*.hpp" -o -name "*.cpp" \) -not -path '*/ts-integration/*' | sort | uniq | tr '\n' ' ') echo "Running clangd-tidy on $TESTFILES" -../../clangd-tidy/clangd-tidy -p ./build $TESTFILES +clangd-tidy -p ./build $TESTFILES echo "Running clang-format --dry-run on $TESTFILES" ../../run-clang-format.py $TESTFILES @@ -23,7 +23,7 @@ echo "Running clang-format --dry-run on $TESTFILES" INCLUDEFILES=$(find include -type f \( -name "*.hpp" -o -name "*.cpp" \) -not -path '*/proto/*' | sort | uniq | tr '\n' ' ') echo "Running clangd-tidy on $INCLUDEFILES" -../../clangd-tidy/clangd-tidy -p ./build $INCLUDEFILES +clangd-tidy -p ./build $INCLUDEFILES echo "Running clang-format --dry-run on $INCLUDEFILES" ../../run-clang-format.py $INCLUDEFILES diff --git a/packages/streamr-utils/include/streamr-utils/ENSName.hpp b/packages/streamr-utils/include/streamr-utils/ENSName.hpp index 166ae8a1..82084d92 100644 --- a/packages/streamr-utils/include/streamr-utils/ENSName.hpp +++ b/packages/streamr-utils/include/streamr-utils/ENSName.hpp @@ -9,7 +9,7 @@ namespace streamr::utils { inline bool isENSNameFormatIgnoreCase(std::string_view str) { - return str.find('.') != std::string_view::npos; + return str.contains('.'); } using ENSName = Branded; @@ -17,11 +17,10 @@ using ENSName = Branded; inline ENSName toENSName(std::string_view str) { if (isENSNameFormatIgnoreCase(str)) { auto lowercaseStr = std::string(str); - std::transform( - lowercaseStr.begin(), - lowercaseStr.end(), - lowercaseStr.begin(), - [](unsigned char c) { return std::tolower(c); }); + std::ranges::transform( + lowercaseStr, lowercaseStr.begin(), [](unsigned char c) { + return std::tolower(c); + }); return ENSName{std::move(lowercaseStr)}; } throw std::runtime_error("not a valid ENS name: " + std::string(str)); diff --git a/packages/streamr-utils/lint.sh b/packages/streamr-utils/lint.sh index 5e834965..f334448a 100755 --- a/packages/streamr-utils/lint.sh +++ b/packages/streamr-utils/lint.sh @@ -5,7 +5,7 @@ set -e FILES=$(find . -type d \( -name src -o -name include -o -name test \) ! -path '*/build/*' ! -path '*/proto/*' -print0 | xargs -0 -I{} find {} -type f \( -name "*.hpp" -o -name "*.cpp" \) -print0 | xargs -0 echo) echo "Running clangd-tidy on $FILES" -../../clangd-tidy/clangd-tidy -p ./build $FILES +clangd-tidy -p ./build $FILES echo "Running clang-format --dry-run on $FILES" ../../run-clang-format.py $FILES diff --git a/packages/streamr-utils/test/unit/SigninUtilsTest.cpp b/packages/streamr-utils/test/unit/SigninUtilsTest.cpp index a93dadfc..63332301 100644 --- a/packages/streamr-utils/test/unit/SigninUtilsTest.cpp +++ b/packages/streamr-utils/test/unit/SigninUtilsTest.cpp @@ -28,7 +28,6 @@ TEST(SigninUtilsTest, hash) { const auto hash = BinaryUtils::binaryStringToHex( SigningUtils::hash(BinaryUtils::hexToBinaryString(payloadHex))); std::string lowerCaseHash; - std::transform( - hash.begin(), hash.end(), std::back_inserter(lowerCaseHash), ::tolower); + std::ranges::transform(hash, std::back_inserter(lowerCaseHash), ::tolower); EXPECT_EQ(hash, expectedHash); } \ No newline at end of file diff --git a/packages/streamr-utils/test/unit/SigningUtilsTest.cpp b/packages/streamr-utils/test/unit/SigningUtilsTest.cpp index 2d9151fb..9744a089 100644 --- a/packages/streamr-utils/test/unit/SigningUtilsTest.cpp +++ b/packages/streamr-utils/test/unit/SigningUtilsTest.cpp @@ -27,7 +27,6 @@ TEST(SigninUtilsTest, hash) { const auto hash = BinaryUtils::binaryStringToHex( SigningUtils::hash(BinaryUtils::hexToBinaryString(payloadHex))); std::string lowerCaseHash; - std::transform( - hash.begin(), hash.end(), std::back_inserter(lowerCaseHash), ::tolower); + std::ranges::transform(hash, std::back_inserter(lowerCaseHash), ::tolower); EXPECT_EQ(hash, expectedHash); } \ No newline at end of file