Skip to content

Commit b1ef740

Browse files
committed
Add clang-tidy and clang-tidy-fix targets
1 parent 4051ee1 commit b1ef740

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

.clang-tidy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Checks: >
2+
clang-diagnostic-*,
3+
clang-analyzer-*,
4+
cppcoreguidelines-*,
5+
modernize-*,
6+
performance-*,
7+
readability-*,
8+
-modernize-use-trailing-return-type,
9+
-readability-identifier-length
10+
11+
# Treat all warnings as errors
12+
WarningsAsErrors: '*'
13+
14+
# Only warn on headers in the code tree
15+
HeaderFilterRegex: 'builtins/|runtime/'
16+
17+
# Use the same style as clang-format (look for .clang-format)
18+
FormatStyle: file
19+
20+
# Don’t analyze temporary dtors (speeds up checking)
21+
AnalyzeTemporaryDtors: false

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ include("spidermonkey")
3838
include("openssl")
3939
include("${HOST_API}/host_api.cmake")
4040
include("build-crates")
41+
include("lint")
4142

4243
option(ENABLE_JS_DEBUGGER "Enable support for debugging content via a socket connection" ON)
4344

cmake/lint.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
set(CLANG_TIDY ${WASI_SDK_PREFIX}/bin/clang-tidy)
2+
set(RUN_CLANG_TIDY ${WASI_SDK_PREFIX}/bin/run-clang-tidy)
3+
set(CLANG_APPLY_REPLACEMENTS ${WASI_SDK_PREFIX}/bin/clang-apply-replacements)
4+
set(WASI_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot)
5+
6+
add_custom_target(clang-tidy
7+
COMMAND ${RUN_CLANG_TIDY}
8+
-p=${CMAKE_BINARY_DIR}
9+
-clang-tidy-binary=${CLANG_TIDY}
10+
-extra-arg=--sysroot=${WASI_SYSROOT}
11+
-config-file=${CMAKE_SOURCE_DIR}/.clang-tidy
12+
${CMAKE_SOURCE_DIR}/builtins
13+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
14+
COMMENT "Running clang‑tidy over the codebase"
15+
VERBATIM)
16+
17+
add_custom_target(clang-tidy-fix
18+
COMMAND ${RUN_CLANG_TIDY}
19+
-p=${CMAKE_BINARY_DIR}
20+
-clang-tidy-binary=${CLANG_TIDY}
21+
-clang-apply-replacements-binary=${CLANG_APPLY_REPLACEMENTS}
22+
-extra-arg=--sysroot=${WASI_SYSROOT}
23+
-config-file=${CMAKE_SOURCE_DIR}/.clang-tidy
24+
-fix
25+
${CMAKE_SOURCE_DIR}/builtins
26+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
27+
COMMENT "Running clang‑tidy over the codebase and applying fixes"
28+
VERBATIM)

justfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ do_clean:
4545
clean-all: && do_clean
4646
@echo "This will remove {{builddir}}"
4747

48+
# Run clang-tidy
49+
lint: (build "clang-tidy")
50+
51+
# Run clang-tidy and apply offered fixes
52+
lint-fix: (build "clang-tidy-fix")
53+
4854
# Componentize js script
4955
componentize script="" outfile="starling.wasm": build
5056
{{ builddir }}/componentize.sh {{ script }} -o {{ outfile }}

0 commit comments

Comments
 (0)