From cd920a7bece186350094740ee7986ba871bd5879 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Thu, 12 Feb 2026 14:23:00 +0800 Subject: [PATCH] ci(app): run clang-tidy (#8442) * fix(app): clang-tidy warnings * build(app): convert checks to list * build(app): fix clang-tidy `HeaderFilterRegex` * ci(app): run clang-tidy * fix: ftbfs * wtf --- .github/workflows/actions.yml | 34 ++++++++---- gtk/FilterBar.cc | 2 +- libtransmission-app/.clang-tidy | 83 ++++++++++++++--------------- libtransmission-app/converters.cc | 11 ++-- libtransmission-app/display-modes.h | 6 +-- libtransmission/variant.h | 4 +- 6 files changed, 79 insertions(+), 61 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 802bb96b1..ce6926a4a 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -234,7 +234,9 @@ jobs: clang-tidy-libtransmission: runs-on: ubuntu-24.04 needs: [ what-to-make ] - if: ${{ needs.what-to-make.outputs.make-core == 'true' || needs.what-to-make.outputs.make-tests == 'true' }} + if: | + needs.what-to-make.outputs.make-core || + needs.what-to-make.outputs.make-tests steps: - name: Show Configuration run: | @@ -261,7 +263,7 @@ jobs: -DCMAKE_CXX_COMPILER='clang++' \ -DCMAKE_C_COMPILER='clang' \ -DCMAKE_INSTALL_PREFIX=pfx \ - -DENABLE_TESTS=${{ (needs.what-to-make.outputs.make-tests == 'true') && 'ON' || 'OFF' }} \ + -DENABLE_TESTS=${{ needs.what-to-make.outputs.make-tests && 'ON' || 'OFF' }} \ -DRUN_CLANG_TIDY=ON \ -DUSE_SYSTEM_DEFAULT=ON \ -DUSE_SYSTEM_CRC32C=OFF `# Not packaged in Ubuntu` \ @@ -271,18 +273,28 @@ jobs: -DUSE_SYSTEM_UTP=OFF `# Not packaged in Ubuntu` \ -DUSE_SYSTEM_WIDE_INTEGER=OFF `# Not packaged in Ubuntu` - name: Make (Core) - run: cmake --build obj --config Debug --target transmission 2>&1 | tee makelog + run: | + set -euo pipefail + cmake --build obj --config Debug --target transmission 2>&1 | tee makelog + - name: Make (App) + run: | + set -euo pipefail + cmake --build obj --config Debug --target transmission-app 2>&1 | tee -a makelog - name: Make (Tests) - if: ${{ needs.what-to-make.outputs.make-tests == 'true' }} - run: cmake --build obj --config Debug --target libtransmission-test 2>&1 | tee -a makelog + if: needs.what-to-make.outputs.make-tests + run: | + set -euo pipefail + cmake --build obj --config Debug --target libtransmission-test 2>&1 | tee -a makelog - name: Test for warnings run: | if grep 'warning:' makelog; then exit 1; fi clang-tidy-libtransmission-win32: runs-on: windows-2025 - needs: [ what-to-make ] - if: ${{ needs.what-to-make.outputs.make-core == 'true' || needs.what-to-make.outputs.make-tests == 'true' }} + needs: what-to-make + if: | + needs.what-to-make.outputs.make-core || + needs.what-to-make.outputs.make-tests steps: - name: Show Configuration run: | @@ -307,15 +319,19 @@ jobs: -G Ninja ` -DCMAKE_BUILD_TYPE=Debug ` -DCMAKE_PREFIX_PATH="${Env:DEPS_PREFIX}" ` - -DENABLE_TESTS=${{ (needs.what-to-make.outputs.make-tests == 'true') && 'ON' || 'OFF' }} ` + -DENABLE_TESTS=${{ needs.what-to-make.outputs.make-tests && 'ON' || 'OFF' }} ` -DRUN_CLANG_TIDY=ON ` -DUSE_SYSTEM_DEFAULT=OFF - name: Make (Core) run: | Import-VisualStudioVars -VisualStudioVersion 2022 -Architecture x64 cmake --build obj --config Debug --target transmission 2>&1 | tee makelog + - name: Make (App) + run: | + Import-VisualStudioVars -VisualStudioVersion 2022 -Architecture x64 + cmake --build obj --config Debug --target transmission-app 2>&1 | tee -a makelog - name: Make (Tests) - if: ${{ needs.what-to-make.outputs.make-tests == 'true' }} + if: needs.what-to-make.outputs.make-tests run: | Import-VisualStudioVars -VisualStudioVersion 2022 -Architecture x64 cmake --build obj --config Debug --target libtransmission-test 2>&1 | tee -a makelog diff --git a/gtk/FilterBar.cc b/gtk/FilterBar.cc index 40ef05c42..f4d782e0d 100644 --- a/gtk/FilterBar.cc +++ b/gtk/FilterBar.cc @@ -473,7 +473,7 @@ Glib::RefPtr FilterBar::Impl::show_mode_filter_model_new() static auto constexpr types = std::array({ { { ShowMode::ShowAll, nullptr, N_("All"), nullptr }, - { ShowMode{ -1 }, nullptr, nullptr, nullptr }, + { ShowModeSeparator, nullptr, nullptr, nullptr }, { ShowMode::ShowActive, nullptr, N_("Active"), "system-run" }, { ShowMode::ShowDownloading, "Verb", NC_("Verb", "Downloading"), "network-receive" }, { ShowMode::ShowSeeding, "Verb", NC_("Verb", "Seeding"), "network-transmit" }, diff --git a/libtransmission-app/.clang-tidy b/libtransmission-app/.clang-tidy index e36096bce..6ecec6f2d 100644 --- a/libtransmission-app/.clang-tidy +++ b/libtransmission-app/.clang-tidy @@ -1,48 +1,47 @@ --- -HeaderFilterRegex: .*/libtransmission/.* +HeaderFilterRegex: .*/libtransmission-app/.* -# TODO: Enable `portability-template-virtual-member-function` after https://github.com/llvm/llvm-project/issues/139031 is fixed # PRs welcome to fix & re-enable any of these explicitly-disabled checks -Checks: > - bugprone-*, - -bugprone-branch-clone, - -bugprone-easily-swappable-parameters, - -bugprone-implicit-widening-of-multiplication-result, - -bugprone-narrowing-conversions, - cert-*, - -cert-err58-cpp, - -cert-int09-c, - clang-analyzer-*, - -clang-analyzer-optin.core.EnumCastOutOfRange, - cppcoreguidelines-avoid-do-while, - cppcoreguidelines-avoid-goto, - cppcoreguidelines-avoid-reference-coroutine-parameters, - cppcoreguidelines-init-variables, - cppcoreguidelines-interfaces-global-init, - cppcoreguidelines-no-malloc, - cppcoreguidelines-prefer-member-initializer, - cppcoreguidelines-pro-type-cstyle-cast, - cppcoreguidelines-pro-type-member-init, - cppcoreguidelines-slicing, - cppcoreguidelines-special-member-functions, - cppcoreguidelines-virtual-class-destructor, - google-explicit-constructor, - misc-*, - -misc-include-cleaner, - -misc-no-recursion, - -misc-non-private-member-variables-in-classes, - modernize-*, - -modernize-use-trailing-return-type, - performance-*, - -performance-move-const-arg, - portability-*, - -portability-template-virtual-member-function, - readability-*, - -readability-enum-initial-value, - -readability-function-cognitive-complexity, - -readability-identifier-length, - -readability-magic-numbers, - -readability-qualified-auto, +Checks: + - bugprone-* + - -bugprone-branch-clone + - -bugprone-easily-swappable-parameters + - -bugprone-implicit-widening-of-multiplication-result + - -bugprone-narrowing-conversions + - cert-* + - -cert-err58-cpp + - -cert-int09-c # alias of `readability-enum-initial-value` + - clang-analyzer-* + - -clang-analyzer-optin.core.EnumCastOutOfRange + - cppcoreguidelines-avoid-do-while + - cppcoreguidelines-avoid-goto + - cppcoreguidelines-avoid-reference-coroutine-parameters + - cppcoreguidelines-init-variables + - cppcoreguidelines-interfaces-global-init + - cppcoreguidelines-no-malloc + - cppcoreguidelines-prefer-member-initializer + - cppcoreguidelines-pro-type-cstyle-cast + - cppcoreguidelines-pro-type-member-init + - cppcoreguidelines-slicing + - cppcoreguidelines-special-member-functions + - cppcoreguidelines-virtual-class-destructor + - google-explicit-constructor + - misc-* + - -misc-include-cleaner + - -misc-no-recursion + - -misc-non-private-member-variables-in-classes + - modernize-* + - -modernize-use-trailing-return-type + - performance-* + - -performance-move-const-arg + - portability-* + - -portability-template-virtual-member-function # TODO: Enable after https://github.com/llvm/llvm-project/issues/139031 is fixed + - readability-* + - -readability-enum-initial-value + - -readability-function-cognitive-complexity + - -readability-identifier-length + - -readability-magic-numbers + - -readability-qualified-auto CheckOptions: - { key: cppcoreguidelines-avoid-do-while.IgnoreMacros, value: true } diff --git a/libtransmission-app/converters.cc b/libtransmission-app/converters.cc index 9b348c33b..c2ede1f37 100644 --- a/libtransmission-app/converters.cc +++ b/libtransmission-app/converters.cc @@ -23,6 +23,8 @@ #include "libtransmission-app/display-modes.h" #include "libtransmission-app/converters.h" +using namespace std::literals; + namespace tr::app::detail { namespace @@ -88,10 +90,10 @@ struct TrYearMonthDay } auto const dim = days_in_month(y, m); - return d >= 1 && d <= static_cast(dim); + return d >= 1 && std::cmp_less_equal(d, dim); }; - return TrYearMonthDay{ year, month, day, is_valid_ymd(year, month, day) }; + return TrYearMonthDay{ .year = year, .month = month, .day = day, .valid = is_valid_ymd(year, month, day) }; } // c++20 (P0355) replace with std::chrono::sys_days{} after Debian 11 is EOL @@ -344,11 +346,12 @@ tr_variant from_stats_mode(StatsMode const& src) { if (auto const* local = std::localtime(&tt)) { - return fmt::format(FMT_STRING("{:%FT%T%z}"), *local); + // fmt::runtime to workaround FTBFS in clang + return fmt::format(fmt::runtime("{:%FT%T%z}"), *local); } } - return fmt::format(FMT_STRING("{:%FT%TZ}"), src); + return fmt::format("{:%FT%TZ}", src); } bool to_sys_seconds(tr_variant const& src, std::chrono::sys_seconds* tgt) diff --git a/libtransmission-app/display-modes.h b/libtransmission-app/display-modes.h index 1e9902158..f488a7653 100644 --- a/libtransmission-app/display-modes.h +++ b/libtransmission-app/display-modes.h @@ -7,7 +7,7 @@ namespace tr::app { -enum class ShowMode +enum class ShowMode : uint8_t { ShowAll, ShowActive, @@ -21,7 +21,7 @@ enum class ShowMode inline auto constexpr ShowModeCount = 8U; inline auto constexpr DefaultShowMode = ShowMode::ShowAll; -enum class SortMode +enum class SortMode : uint8_t { SortByActivity, SortByAge, @@ -37,7 +37,7 @@ enum class SortMode inline auto constexpr SortModeCount = 10U; inline auto constexpr DefaultSortMode = SortMode::SortByName; -enum class StatsMode +enum class StatsMode : uint8_t { TotalRatio, TotalTransfer, diff --git a/libtransmission/variant.h b/libtransmission/variant.h index 578d58137..1968ea669 100644 --- a/libtransmission/variant.h +++ b/libtransmission/variant.h @@ -91,7 +91,7 @@ public: { return item.first == key; }; - return std::find_if(std::begin(vec_), std::end(vec_), predicate); + return std::ranges::find_if(vec_, predicate); } [[nodiscard]] constexpr auto find(tr_quark const key) const noexcept @@ -101,7 +101,7 @@ public: [[nodiscard]] constexpr auto contains(tr_quark const key) const noexcept { - return find(key) != end(); + return find(key) != end(); // NOLINT(readability-container-contains) } [[nodiscard]] constexpr auto size() const noexcept