Skip to content

Commit d6637da

Browse files
committed
[build] Expand clang-tidy, clang-format coverage
- Apply clang-format on src/rust too - Enable modernize-type-traits, readability-redundant-casting, readability-redundant-declaration tidy checks - Fix compile_flags.txt based on bzlmod transition
1 parent 4c1c293 commit d6637da

File tree

17 files changed

+49
-31
lines changed

17 files changed

+49
-31
lines changed

.clang-tidy

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,31 @@ Checks: >
1616
misc-unused-alias-decls,
1717
modernize-macro-to-enum,
1818
modernize-redundant-void-arg,
19+
modernize-type-traits,
1920
modernize-unary-static-assert,
2021
modernize-use-bool-literals,
2122
performance-for-range-copy,
2223
performance-move-constructor-init,
2324
readability-container-contains,
2425
readability-duplicate-include,
2526
readability-redundant-access-specifiers,
27+
readability-redundant-casting,
28+
readability-redundant-declaration,
2629
readability-static-accessed-through-instance
2730
28-
# TODO: Fix and re-enable
31+
# TODO: Fix and enable
32+
# bugprone-parent-virtual-call
2933
# bugprone-return-const-ref-from-parameter
30-
# modernize-type-traits
34+
# cppcoreguidelines-missing-std-forward
3135
# modernize-use-override
32-
# readability-redundant-casting
36+
# readability-avoid-const-params-in-decls
3337

3438
WarningsAsErrors: '*'
35-
HeaderFilterRegex: '.*/workerd/.*'
39+
HeaderFilterRegex: '.*src/workerd/.*'
3640

3741
CheckOptions:
3842
# JSG has very entrenched include cycles
3943
- key: misc-header-include-cycle.IgnoredFilesList
4044
value: "jsg/jsg.h|jsg/dom-exception.h"
45+
- key: cppcoreguidelines-missing-std-forward.ForwardFunction
46+
value: "kj::fwd"

compile_flags.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
-Iexternal/ncrypto/include
1717
-isystembazel-bin/external/sqlite3
1818
-Isrc
19+
-isystem/usr/lib/llvm-21/include/c++/v1
20+
-isystem/usr/lib/llvm-21/lib/clang/21/include
1921
-isystem/usr/lib/llvm-20/include/c++/v1
2022
-isystem/usr/lib/llvm-20/lib/clang/20/include
2123
-isystem/usr/lib/llvm-19/include/c++/v1
@@ -137,3 +139,13 @@
137139
-Wunused-variable
138140
-no-canonical-prefixes
139141
-fbracket-depth=512
142+
-D___COMMENT_0___="include paths needed while bzlmod and WORKSPACE are used together resulting in mangled path names, can drop after bzlmod transition is complete"
143+
-Iexternal/+_repo_rules2+simdutf/
144+
-Iexternal/+_repo_rules+nbytes/include/
145+
-Iexternal/+_repo_rules+ncrypto/include
146+
-Iexternal/workerd-google-benchmark++_repo_rules+codspeed/google_benchmark/include/
147+
-Iexternal/perfetto+/include/
148+
-Iexternal/perfetto+/include/perfetto/base/build_configs/bazel/
149+
-Ibazel-bin/external/perfetto+/
150+
-isystemexternal/+_repo_rules2+com_googlesource_chromium_icu/source/common
151+
-isystemexternal/+_repo_rules+v8/include

src/rust/cxx-integration-test/cxx-rust-integration-test.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <workerd/rust/cxx-integration-test/lib.rs.h>
22
#include <workerd/rust/cxx-integration/lib.rs.h>
33

4+
#include <kj-rs/kj-rs.h>
45
#include <rust/cxx.h>
56
#include <signal.h>
67

78
#include <kj/async.h>
89
#include <kj/test.h>
9-
#include <kj-rs/kj-rs.h>
1010

1111
using namespace kj_rs;
1212

src/rust/cxx-integration-test/cxx-rust-integration-test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ using TestCallback = kj::Function<size_t(size_t, size_t)>;
1010

1111
using UsizeCallback = kj::Function<void(size_t)>;
1212

13-
} // namespace edgeworker::rust::test
13+
} // namespace workerd::rust::test

src/rust/gen-compile-cache/cxx-bridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include <rust/cxx.h>
44

55
namespace workerd::rust::gen_compile_cache {
6-
::rust::Vec<uint8_t> compile(::rust::Str path, ::rust::Str source);
6+
::rust::Vec<uint8_t> compile(::rust::Str path, ::rust::Str source);
77
}

src/rust/kj/ffi.c++

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
#include <kj/compat/http.h>
1010

1111
static_assert(sizeof(kj::rust::HttpConnectSettings) == 16, "HttpConnectSettings size mismatch");
12-
static_assert(alignof(kj::rust::HttpConnectSettings) == alignof(uint64_t), "HttpConnectSettings alignment mismatch");
12+
static_assert(alignof(kj::rust::HttpConnectSettings) == alignof(uint64_t),
13+
"HttpConnectSettings alignment mismatch");
1314

1415
namespace kj::rust {
1516
kj::Promise<void> connect(HttpService& service,

src/rust/kj/tests/ffi-test.c++

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#include <kj-rs/kj-rs.h>
99

1010
#include <kj/test.h>
11+
1112
#include <cmath>
1213

1314
using namespace kj_rs;
1415

15-
1616
static kj::StringPtr tlsHost;
1717

1818
kj::Promise<void> startTls(kj::StringPtr hostName) {
@@ -28,8 +28,8 @@ class MockHttpService: public kj::HttpService {
2828
const kj::HttpHeaders& headers,
2929
kj::AsyncInputStream& requestBody,
3030
kj::HttpService::Response& response) override {
31-
KJ_UNIMPLEMENTED("not exercised by test");
32-
}
31+
KJ_UNIMPLEMENTED("not exercised by test");
32+
}
3333

3434
kj::Promise<void> connect(kj::StringPtr host,
3535
const kj::HttpHeaders& headers,
@@ -55,8 +55,8 @@ class TestConnectResponse: public kj::HttpService::ConnectResponse {
5555
kj::StringPtr statusText,
5656
const kj::HttpHeaders& headers,
5757
kj::Maybe<uint64_t> expectedBodySize = kj::none) override {
58-
KJ_UNIMPLEMENTED("not exercised by test");
59-
}
58+
KJ_UNIMPLEMENTED("not exercised by test");
59+
}
6060
};
6161

6262
KJ_TEST("http connect settings") {
@@ -82,6 +82,6 @@ KJ_TEST("http connect settings") {
8282
settings.tls_starter = tlsStarter;
8383

8484
auto promise = proxy->connect(host.asBytes().as<Rust>(), headers, connection, tunnel, settings);
85-
KJ_ASSERT_NONNULL(*tlsStarter)(host).wait(waitScope);
85+
KJ_ASSERT_NONNULL (*tlsStarter)(host).wait(waitScope);
8686
KJ_EXPECT(tlsHost == host);
8787
}

src/rust/python-parser/import_parsing.c++

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// https://opensource.org/licenses/Apache-2.0
44

55
#include <workerd/rust/python-parser/lib.rs.h>
6+
67
#include <kj-rs/kj-rs.h>
8+
79
#include <kj/test.h>
810

911
using namespace kj_rs;
@@ -93,12 +95,14 @@ KJ_TEST("supports commas") {
9395
}
9496

9597
KJ_TEST("supports backslash") {
98+
// clang-format off
9699
auto result = parseImports(kj::arr(
97100
"import a\\\n,b"_kj,
98101
"import\\\n q,w"_kj,
99102
"from \\\nx import y"_kj,
100103
"from \\\n c import y"_kj
101104
));
105+
// clang-format on
102106
KJ_REQUIRE(result.size() == 6);
103107
KJ_REQUIRE(result[0] == "a");
104108
KJ_REQUIRE(result[1] == "b");
@@ -109,6 +113,7 @@ KJ_TEST("supports backslash") {
109113
}
110114

111115
KJ_TEST("multiline-strings ignored") {
116+
// clang-format off
112117
auto files = kj::arr(R"SCRIPT(
113118
FOO="""
114119
import x
@@ -128,6 +133,7 @@ import b \
128133
R"SCRIPT(import x
129134
from y import z
130135
""")SCRIPT"_kj);
136+
// clang-format on
131137
auto result = parseImports(files);
132138
KJ_REQUIRE(result.size() == 0);
133139
}

src/workerd/jsg/jsg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,8 +2968,8 @@ inline V8Ref<T> V8Ref<T>::addRef(jsg::Lock& js) {
29682968
return js.v8Ref(getHandle(js));
29692969
}
29702970

2971-
v8::Local<v8::Value> deepClone(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
2972-
// Defined in util.c++.
2971+
// v8::Local<v8::Value> deepClone(v8::Local<v8::Context> context, v8::Local<v8::Value> value);
2972+
// Already defined in util.c++.
29732973

29742974
template <typename T>
29752975
V8Ref<T> V8Ref<T>::deepClone(jsg::Lock& js) {

src/workerd/jsg/url.c++

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ void Url::setHash(kj::Maybe<kj::ArrayPtr<const char>> value) {
314314
}
315315

316316
Url::SchemeType Url::getSchemeType() const {
317-
uint8_t value = ada_get_scheme_type(const_cast<void*>(getInner<ada_url>(inner)));
317+
uint8_t value = ada_get_scheme_type(getInner<ada_url>(inner));
318318
KJ_REQUIRE(value <= static_cast<uint8_t>(SchemeType::FILE));
319319
return static_cast<SchemeType>(value);
320320
}
321321

322322
Url::HostType Url::getHostType() const {
323-
uint8_t value = ada_get_host_type(const_cast<void*>(getInner<ada_url>(inner)));
323+
uint8_t value = ada_get_host_type(getInner<ada_url>(inner));
324324
KJ_REQUIRE(value <= static_cast<uint8_t>(HostType::IPV6));
325325
return static_cast<HostType>(value);
326326
}

0 commit comments

Comments
 (0)