Skip to content

Commit cacf227

Browse files
committed
[build] Expand clang-tidy coverage
1 parent 205258d commit cacf227

File tree

14 files changed

+30
-22
lines changed

14 files changed

+30
-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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,12 @@ JsonWebKey toJwk(const EVPKeyPointer& key, KeyType keyType) {
283283
return jwkFromRsaKey(key, keyType);
284284
case EVP_PKEY_DSA: {
285285
// DSA keys are not supported for JWK export.
286-
break;
286+
[[fallthrough]];
287287
}
288+
default:
289+
return JsonWebKey{.kty = kj::str("INVALID")};
288290
}
289291
}
290-
291-
return JsonWebKey{
292-
.kty = kj::str("INVALID"),
293-
};
294292
}
295293

296294
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/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
}

src/workerd/io/trace.c++

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,8 +1156,8 @@ kj::Maybe<kj::Array<kj::String>> getScriptTagsFromReader(const rpc::Trace::Onset
11561156
if (reader.hasScriptTags()) {
11571157
auto tags = reader.getScriptTags();
11581158
kj::Vector<kj::String> scriptTags(tags.size());
1159-
for (size_t i = 0; i < tags.size(); i++) {
1160-
scriptTags.add(kj::str(tags[i]));
1159+
for (auto&& tag: tags) {
1160+
scriptTags.add(kj::str(tag));
11611161
}
11621162
return kj::Maybe(scriptTags.releaseAsArray());
11631163
}
@@ -1339,8 +1339,8 @@ TailEvent::Event readEventFromTailEvent(const rpc::Trace::TailEvent::Reader& rea
13391339
case rpc::Trace::TailEvent::Event::ATTRIBUTE: {
13401340
auto listReader = event.getAttribute();
13411341
kj::Vector<Attribute> attrs(listReader.size());
1342-
for (size_t n = 0; n < listReader.size(); n++) {
1343-
attrs.add(Attribute(listReader[n]));
1342+
for (auto&& reader: listReader) {
1343+
attrs.add(Attribute(reader));
13441344
}
13451345
return attrs.releaseAsArray();
13461346
}

0 commit comments

Comments
 (0)