Skip to content

Commit e291533

Browse files
committed
Add clang-tidy and include-what-you-use
1 parent 415e1f1 commit e291533

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Checks: '-*,clang-analyzer-*'
2+
WarningsAsErrors: '*,-clang-analyzer-core.uninitialized.UndefReturn'

.devcontainer/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ RUN apt update && apt upgrade --yes
88
# Install additional packages
99

1010
RUN apt install --yes gcc-14 g++-14
11-
RUN apt install --yes clang-format pre-commit
12-
RUN apt install --yes lcov
13-
RUN apt install --yes cppcheck
11+
RUN apt install --yes clang-format clang-tidy cppcheck iwyu lcov pre-commit
1412

1513
# Choose default gcc and g++ version
1614

.pre-commit-config.yaml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1+
fail_fast: false
12
repos:
2-
- repo: https://github.com/pre-commit/mirrors-clang-format
3-
rev: v19.1.3
3+
- repo: https://github.com/sirosen/check-jsonschema
4+
rev: 0.30.0
45
hooks:
5-
- id: clang-format
6-
types_or: [c++]
6+
- id: check-github-actions
7+
- id: check-github-workflows
78
- repo: https://github.com/cheshirekow/cmake-format-precommit
89
rev: v0.6.10
910
hooks:
1011
- id: cmake-format
1112
- id: cmake-lint
12-
- repo: https://github.com/sirosen/check-jsonschema
13-
rev: 0.30.0
13+
- repo: https://github.com/pre-commit/mirrors-clang-format
14+
rev: v19.1.3
1415
hooks:
15-
- id: check-github-actions
16-
- id: check-github-workflows
16+
- id: clang-format
17+
types_or: [c++]
18+
# - repo: https://github.com/pocc/pre-commit-hooks
19+
# rev: v1.3.5
20+
# hooks:
21+
# - id: clang-tidy
22+
# args: [-p=build]
23+
# files: \.(h|cpp)$
24+
# - id: oclint
25+
# - id: cppcheck
26+
# - id: cpplint
27+
# - id: include-what-you-use
1728
- repo: local
1829
hooks:
1930
- id: cppcheck
@@ -33,3 +44,12 @@ repos:
3344
--error-exitcode=1,
3445
]
3546
files: \.(h|cpp)$
47+
- id: clang-tidy
48+
name: clang-tidy
49+
entry: clang-tidy
50+
language: system
51+
args:
52+
[
53+
-p=build
54+
]
55+
files: \.(h|cpp)$

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ option(TRAITS_BUILD_EXAMPLES "whether or not examples should be built" ON)
2222
option(TRAITS_BUILD_TESTS "whether or not tests should be built" ON)
2323
option(TRAITS_TEST_COVERAGE "whether or not test coverage should be generated" OFF)
2424

25+
option(TRAITS_COMPILE_COMMANDS "whether or not to generate compile commands database" ON)
26+
option(TRAITS_CLANG_TIDY "whether or not clang-tidy should be run" OFF)
27+
option(TRAITS_INCLUDE_WHAT_YOU_USE "whether or not include-what-you-use should be run" OFF)
28+
29+
if(TRAITS_COMPILE_COMMANDS)
30+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
31+
endif()
32+
33+
if(TRAITS_CLANG_TIDY)
34+
find_program(CLANG_TIDY_EXE NAMES clang-tidy REQUIRED)
35+
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE})
36+
endif()
37+
38+
if(TRAITS_INCLUDE_WHAT_YOU_USE)
39+
find_program(IWYU_EXE NAMES include-what-you-use REQUIRED)
40+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXE})
41+
endif()
42+
2543
# installation rules
2644

2745
configure_file("cmake/traits-config-version.cmake.in"

examples/quickstart.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include <algorithm>
12
#include <format>
23
#include <iostream>
4+
#include <string>
35
#include <vector>
46

57
#include "traits.h"

0 commit comments

Comments
 (0)