Skip to content

Commit

Permalink
Add clang-tidy and include-what-you-use
Browse files Browse the repository at this point in the history
  • Loading branch information
eel76 committed Dec 10, 2024
1 parent 415e1f1 commit e291533
Showing 5 changed files with 51 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Checks: '-*,clang-analyzer-*'
WarningsAsErrors: '*,-clang-analyzer-core.uninitialized.UndefReturn'
4 changes: 1 addition & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -8,9 +8,7 @@ RUN apt update && apt upgrade --yes
# Install additional packages

RUN apt install --yes gcc-14 g++-14
RUN apt install --yes clang-format pre-commit
RUN apt install --yes lcov
RUN apt install --yes cppcheck
RUN apt install --yes clang-format clang-tidy cppcheck iwyu lcov pre-commit

# Choose default gcc and g++ version

36 changes: 28 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
fail_fast: false
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.3
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.30.0
hooks:
- id: clang-format
types_or: [c++]
- id: check-github-actions
- id: check-github-workflows
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.10
hooks:
- id: cmake-format
- id: cmake-lint
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.30.0
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.3
hooks:
- id: check-github-actions
- id: check-github-workflows
- id: clang-format
types_or: [c++]
# - repo: https://github.com/pocc/pre-commit-hooks
# rev: v1.3.5
# hooks:
# - id: clang-tidy
# args: [-p=build]
# files: \.(h|cpp)$
# - id: oclint
# - id: cppcheck
# - id: cpplint
# - id: include-what-you-use
- repo: local
hooks:
- id: cppcheck
@@ -33,3 +44,12 @@ repos:
--error-exitcode=1,
]
files: \.(h|cpp)$
- id: clang-tidy
name: clang-tidy
entry: clang-tidy
language: system
args:
[
-p=build
]
files: \.(h|cpp)$
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -22,6 +22,24 @@ option(TRAITS_BUILD_EXAMPLES "whether or not examples should be built" ON)
option(TRAITS_BUILD_TESTS "whether or not tests should be built" ON)
option(TRAITS_TEST_COVERAGE "whether or not test coverage should be generated" OFF)

option(TRAITS_COMPILE_COMMANDS "whether or not to generate compile commands database" ON)
option(TRAITS_CLANG_TIDY "whether or not clang-tidy should be run" OFF)
option(TRAITS_INCLUDE_WHAT_YOU_USE "whether or not include-what-you-use should be run" OFF)

if(TRAITS_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()

if(TRAITS_CLANG_TIDY)
find_program(CLANG_TIDY_EXE NAMES clang-tidy REQUIRED)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE})
endif()

if(TRAITS_INCLUDE_WHAT_YOU_USE)
find_program(IWYU_EXE NAMES include-what-you-use REQUIRED)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXE})
endif()

# installation rules

configure_file("cmake/traits-config-version.cmake.in"
2 changes: 2 additions & 0 deletions examples/quickstart.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <algorithm>
#include <format>
#include <iostream>
#include <string>
#include <vector>

#include "traits.h"

0 comments on commit e291533

Please sign in to comment.