Skip to content

Commit 296b4a5

Browse files
committed
[build] Expand clang-tidy coverage
1 parent 13628a9 commit 296b4a5

File tree

15 files changed

+35
-22
lines changed

15 files changed

+35
-22
lines changed

.clang-tidy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ Checks: >
1616
bugprone-return-const-ref-from-parameter,
1717
bugprone-suspicious-*,
1818
-bugprone-suspicious-semicolon,
19+
bugprone-switch-missing-default-case,
1920
bugprone-undefined-memory-manipulation,
2021
bugprone-unhandled-self-assignment,
2122
bugprone-unused-raii,
2223
bugprone-use-after-move,
2324
cppcoreguidelines-c-copy-assignment-signature,
25+
cppcoreguidelines-interfaces-global-init,
2426
cppcoreguidelines-misleading-capture-default-by-value,
2527
cppcoreguidelines-noexcept-destructor,
2628
cppcoreguidelines-prefer-member-initializer,
@@ -32,6 +34,7 @@ Checks: >
3234
misc-unused-alias-decls,
3335
misc-unused-using-decls,
3436
modernize-avoid-variadic-functions,
37+
modernize-loop-convert,
3538
modernize-macro-to-enum,
3639
modernize-redundant-void-arg,
3740
modernize-type-traits,
@@ -72,6 +75,7 @@ Checks: >
7275
# modernize-use-override
7376
# modernize-use-ranges
7477
# readability-avoid-return-with-void-value
78+
# readability-convert-member-functions-to-static
7579
# readability-redundant-smartptr-get
7680
# readability-use-anyofallof
7781

src/workerd/api/analytics-engine-impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void setDoubles(Message msg, kj::ArrayPtr<double> arr, kj::StringPtr errorPrefix
2020

2121
uint index = 1;
2222
for (auto& item: arr) {
23+
// NOLINTNEXTLINE(bugprone-switch-missing-default-case)
2324
switch (index) {
2425
case 1:
2526
msg.setDouble1(item);
@@ -108,6 +109,7 @@ void setBlobs(Message msg,
108109
sizeSum += value.size();
109110
JSG_REQUIRE(sizeSum <= MAX_CUMULATIVE_BYTES_IN_BLOBS, TypeError, errorPrefix,
110111
"Cumulative size of blobs exceeds ", MAX_CUMULATIVE_BYTES_IN_BLOBS, " bytes).");
112+
// NOLINTNEXTLINE(bugprone-switch-missing-default-case)
111113
switch (index) {
112114
case 1:
113115
msg.setBlob1(value);

src/workerd/api/crypto/aes.c++

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ class AesCtrKey final: public AesKeyBase {
475475
return *EVP_aes_192_ctr();
476476
case 32:
477477
return *EVP_aes_256_ctr();
478+
default:
479+
KJ_FAIL_ASSERT("CryptoKey has invalid data length");
478480
}
479-
KJ_FAIL_ASSERT("CryptoKey has invalid data length");
480481
}
481482

482483
jsg::BufferSource encryptOrDecrypt(jsg::Lock& js,

src/workerd/api/crypto/ec.c++

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,9 @@ kj::OneOf<jsg::Ref<CryptoKey>, CryptoKeyPair> EdDsaKey::generateKey(jsg::Lock& j
11201120
case NID_X25519:
11211121
return generateKeyImpl<X25519_PUBLIC_VALUE_LEN, X25519_keypair>(js, normalizedName, nid,
11221122
privateKeyUsages, publicKeyUsages, extractablePrivateKey, "X25519"_kj);
1123+
default:
1124+
KJ_FAIL_REQUIRE("ED ", normalizedName, " unimplemented", nid);
11231125
}
1124-
1125-
KJ_FAIL_REQUIRE("ED ", normalizedName, " unimplemented", nid);
11261126
}
11271127

11281128
} // namespace

src/workerd/api/crypto/impl.c++

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ kj::Vector<kj::OneOf<kj::StringPtr, OpensslUntranslatedError>> consumeAllOpenssl
137137
switch (ERR_GET_REASON(error)) {
138138
case RSA_R_DATA_LEN_NOT_EQUAL_TO_MOD_LEN:
139139
return "Invalid RSA signature."_kj;
140+
default:
140141
}
141142
break;
142143
case ERR_LIB_EC:
@@ -149,8 +150,10 @@ kj::Vector<kj::OneOf<kj::StringPtr, OpensslUntranslatedError>> consumeAllOpenssl
149150
return "Point is not on curve."_kj;
150151
case EC_R_UNKNOWN_GROUP:
151152
return "Unsupported elliptic curve group."_kj;
153+
default:
152154
}
153155
break;
156+
default:
154157
}
155158

156159
return OpensslUntranslatedError{

src/workerd/api/crypto/jwk.c++

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,11 @@ JsonWebKey toJwk(const EVPKeyPointer& key, KeyType keyType) {
285285
// DSA keys are not supported for JWK export.
286286
break;
287287
}
288+
default:
289+
break;
288290
}
289291
}
290-
291-
return JsonWebKey{
292-
.kty = kj::str("INVALID"),
293-
};
292+
return JsonWebKey{.kty = kj::str("INVALID")};
294293
}
295294

296295
EVPKeyPointer fromJwk(const JsonWebKey& jwk, KeyType keyType) {

src/workerd/api/crypto/x509.c++

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ jsg::JsObject X509Certificate::toLegacyObject(jsg::Lock& js) {
820820
}
821821
break;
822822
}
823+
default:
823824
}
824825
}
825826

src/workerd/api/form-data.c++

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ void FormData::forEach(jsg::Lock& js,
512512
// it up. Using the classic for (;;) syntax here allows for that. However, this does
513513
// mean that it's possible for a user to trigger an infinite loop here if new items
514514
// are added to the search params unconditionally on each iteration.
515-
for (size_t i = 0; i < this->data.size(); i++) {
516-
auto& [key, value] = this->data[i];
515+
for (auto& [key, value]: this->data) {
517516
callback(js, clone(js, value), key, JSG_THIS);
518517
}
519518
}

src/workerd/api/node/exceptions.c++

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ namespace {
6363
case UV_##name: \
6464
return js.str(#name##_kj);
6565
jsg::JsValue uv_err_name(jsg::Lock& js, int err) {
66-
switch (err) { UV_ERRNO_MAP(UV_ERR_NAME_GEN) }
66+
switch (err) {
67+
UV_ERRNO_MAP(UV_ERR_NAME_GEN)
68+
default:
69+
break;
70+
}
6771
return js.str("UNKNOWN"_kj);
6872
}
6973
#undef UV_ERR_NAME_GEN

src/workerd/api/url.c++

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,7 @@ void URLSearchParams::forEach(jsg::Lock& js,
623623
// it up. Using the classic for (;;) syntax here allows for that. However, this does
624624
// mean that it's possible for a user to trigger an infinite loop here if new items
625625
// are added to the search params unconditionally on each iteration.
626-
for (size_t i = 0; i < this->url->query.size(); i++) {
627-
auto& [key, value] = this->url->query[i];
626+
for (auto& [key, value]: this->url->query) {
628627
callback(js, value, key, JSG_THIS);
629628
}
630629
}

0 commit comments

Comments
 (0)