Skip to content

Commit

Permalink
Add clang-tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgunter committed Aug 5, 2024
1 parent a3b815c commit 8184e41
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 10 deletions.
33 changes: 33 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Checks: >
*,
-*-macro-to-enum,
-*-magic-numbers,
-*-named-parameter,
-abseil-*,
-altera-*,
-android-*,
-boost-*,
-cert-dcl58-cpp,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-fuchsia-default-arguments-*,
-fuchsia-overloaded-operator,
-fuchsia-trailing-return,
-google-readability-todo,
-llvm-*,
-llvmlibc-*,
-objc-*,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-zircon-*,
CheckOptions:
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: cppcoreguidelines-macro-usage.AllowedRegexp
value: "^WHIRLWIND_[A-Z_]+$"
- key: hicpp-multiway-paths-covered.WarnOnMissingElse
value: true
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
WarningsAsErrors: "*"
HeaderFilterRegex: "whirlwind/.*\\.hpp$"
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,20 @@ jobs:
- uses: lukka/run-cmake@v10.7
with:
workflowPreset: ${{ matrix.preset }}

clang-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.7
with:
fetch-depth: 0
submodules: true
- uses: aminya/setup-cpp@v0.37.0
with:
compiler: llvm
clangtidy: "18"
- uses: lukka/get-cmake@v3.30.2
- uses: lukka/run-vcpkg@v11.5
- uses: lukka/run-cmake@v10.7
with:
workflowPreset: clang-tidy
24 changes: 24 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "clang-tidy",
"inherits": "debug",
"cacheVariables": {
"CMAKE_CXX_CLANG_TIDY": "clang-tidy"
}
}
],
"buildPresets": [
Expand All @@ -39,6 +46,10 @@
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "clang-tidy",
"configurePreset": "clang-tidy"
}
],
"testPresets": [
Expand Down Expand Up @@ -94,6 +105,19 @@
"name": "debug"
}
]
},
{
"name": "clang-tidy",
"steps": [
{
"type": "configure",
"name": "clang-tidy"
},
{
"type": "build",
"name": "clang-tidy"
}
]
}
]
}
4 changes: 3 additions & 1 deletion include/whirlwind/graph/edge_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class EdgeList {
constexpr EdgeList() = default;

/** Create a new `EdgeList` from a sequence of (tail,head) pairs. */
constexpr EdgeList(container_type<value_type> edges) : edges_(std::move(edges)) {}
explicit constexpr EdgeList(container_type<value_type> edges)
: edges_(std::move(edges))
{}

/**
* Create a new `EdgeList` from sequences of tail and head vertices.
Expand Down
4 changes: 2 additions & 2 deletions include/whirlwind/graph/rectangular_grid_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class RectangularGridGraph {
* A view of the vertex's outgoing incident edges and successor vertices.
*/
[[nodiscard]] auto
outgoing_edges(const vertex_type& vertex) const
outgoing_edges(vertex_type vertex) const
-> std::generator<std::pair<edge_type, vertex_type>>
{
WHIRLWIND_ASSERT(contains_vertex(vertex));
Expand Down Expand Up @@ -464,7 +464,7 @@ class RectangularGridGraph {
auto off1 = off0 + num_lr_edges;
auto off2 = off1 + num_ud_edges;

return std::array{std::move(off0), std::move(off1), std::move(off2)};
return std::array{off0, off1, off2};
}

[[nodiscard]] constexpr auto
Expand Down
3 changes: 2 additions & 1 deletion include/whirlwind/math/numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <concepts>
#include <limits>
#include <numbers>
#include <type_traits>

#include <whirlwind/common/compatibility.hpp>
Expand Down Expand Up @@ -58,7 +59,7 @@ template<std::floating_point Real>
[[nodiscard]] WHIRLWIND_CONSTEVAL auto
pi() noexcept -> Real
{
return static_cast<Real>(3.141592653589793238462643383279502884L);
return std::numbers::pi_v<Real>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package(Catch2 3.3 CONFIG REQUIRED)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/)
include(WhirlwindWarnings)

# Add test executable.
Expand Down
1 change: 1 addition & 0 deletions test/common/test_version.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <type_traits>

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>

#include <whirlwind/common/version.hpp>
Expand Down
1 change: 1 addition & 0 deletions test/graph/csr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <type_traits>

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_range_equals.hpp>

#include <whirlwind/graph/csr_graph.hpp>
Expand Down
3 changes: 2 additions & 1 deletion test/graph/forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <utility>

#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_range_equals.hpp>
#include <range/v3/view/transform.hpp>

Expand All @@ -11,7 +12,7 @@
#include <whirlwind/graph/forest.hpp>
#include <whirlwind/graph/rectangular_grid_graph.hpp>

#include "../string_conversions.hpp"
#include "../testing/string_conversions.hpp" // IWYU pragma: keep

namespace {

Expand Down
5 changes: 3 additions & 2 deletions test/math/test_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>

#include <whirlwind/math/numbers.hpp>
Expand All @@ -13,7 +14,7 @@ namespace ww = whirlwind;

TEST_CASE("zero", "[numbers]")
{
STATIC_REQUIRE(ww::zero<float>() == 0.0f);
STATIC_REQUIRE(ww::zero<float>() == 0.0F);
STATIC_REQUIRE(ww::zero<double>() == 0.0);
STATIC_REQUIRE(ww::zero<int>() == 0);
STATIC_REQUIRE(ww::zero<signed char>() == 0);
Expand All @@ -22,7 +23,7 @@ TEST_CASE("zero", "[numbers]")

TEST_CASE("one", "[numbers]")
{
STATIC_REQUIRE(ww::one<float>() == 1.0f);
STATIC_REQUIRE(ww::one<float>() == 1.0F);
STATIC_REQUIRE(ww::one<double>() == 1.0);
STATIC_REQUIRE(ww::one<int>() == 1);
STATIC_REQUIRE(ww::one<signed char>() == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
namespace std {

template<class T1, class T2>
ostream&
operator<<(ostream& os, const pair<T1, T2>& value)
auto
operator<<(ostream& os, const pair<T1, T2>& value) -> ostream&
{
os << "(" << value.first << ", " << value.second << ")";
return os;
Expand Down

0 comments on commit 8184e41

Please sign in to comment.