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
This commit is contained in:
Yat Ho
2026-02-12 14:23:00 +08:00
committed by GitHub
parent e6d7d42e2a
commit cd920a7bec
6 changed files with 79 additions and 61 deletions

View File

@@ -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

View File

@@ -473,7 +473,7 @@ Glib::RefPtr<Gtk::ListStore> FilterBar::Impl::show_mode_filter_model_new()
static auto constexpr types = std::array<FilterTypeInfo, 9>({ {
{ 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" },

View File

@@ -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 }

View File

@@ -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<unsigned>(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)

View File

@@ -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,

View File

@@ -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