From 1667a06077b918c8d8591b4021086d51840f2e89 Mon Sep 17 00:00:00 2001 From: Felix Hanau Date: Fri, 7 Aug 2026 14:21:26 -0400 Subject: [PATCH] [build] Add misc-include-cleaner clang-tidy check for headers Reduces transitive include bloat by enforcing that no unused headers are being added. --- .clang-tidy | 6 +++++ build/tools/clang_tidy/check_path_filters.bzl | 6 +++++ build/tools/clang_tidy/clang_tidy.bzl | 22 +++++++++++++------ src/rust/cxx/include/cxx.h | 2 -- src/rust/cxx/kj-rs/future.h | 1 - src/rust/cxx/kj-rs/kj-rs.h | 3 +++ src/rust/cxx/src/cxx.cc | 1 + src/rust/cxx/tests/ffi/tests.h | 1 + src/rust/jsg-test/ffi.h | 3 +-- src/rust/jsg/BUILD.bazel | 2 -- src/rust/jsg/ffi.c++ | 2 +- src/rust/jsg/ffi.h | 6 ++--- src/rust/jsg/jsg.h | 1 - src/rust/worker/bridge.h | 2 -- src/workerd/api/container.h | 2 +- src/workerd/api/crypto/impl.h | 2 ++ src/workerd/api/data-url.c++ | 1 + src/workerd/api/eventsource.c++ | 2 +- src/workerd/api/eventsource.h | 1 - src/workerd/api/fuzzilli.c++ | 5 +++++ src/workerd/api/fuzzilli.h | 5 ----- src/workerd/api/global-scope.h | 1 + src/workerd/api/html-rewriter.h | 2 +- src/workerd/api/messagechannel.h | 2 -- src/workerd/api/modules.h | 1 - src/workerd/api/node/node.h | 3 --- src/workerd/api/node/process.c++ | 2 ++ src/workerd/api/node/process.h | 3 --- src/workerd/api/pyodide/pyodide.h | 2 -- src/workerd/api/r2-bucket.h | 2 +- src/workerd/api/r2.h | 2 ++ src/workerd/api/streams.h | 4 ++++ src/workerd/api/streams/compression.c++ | 2 ++ src/workerd/api/streams/compression.h | 4 +--- src/workerd/api/streams/writable.h | 1 - src/workerd/api/unsafe.h | 6 ++--- src/workerd/api/util.h | 2 -- src/workerd/api/web-socket.h | 2 -- src/workerd/api/worker-loader.h | 1 - src/workerd/api/worker-rpc.h | 2 -- src/workerd/io/limit-enforcer.h | 1 - src/workerd/io/trace.h | 1 - src/workerd/io/worker-interface.h | 1 - src/workerd/io/worker-modules.h | 2 ++ src/workerd/jsg/BUILD.bazel | 2 +- src/workerd/jsg/iterator.h | 1 + src/workerd/jsg/jsg-test.h | 2 ++ src/workerd/jsg/jsvalue.c++ | 6 ++--- src/workerd/jsg/memory.h | 2 -- src/workerd/jsg/modules-new.c++ | 2 +- src/workerd/jsg/modules.c++ | 2 -- src/workerd/jsg/struct.h | 2 -- src/workerd/jsg/type-wrapper.h | 1 + src/workerd/jsg/url-test.c++ | 2 -- src/workerd/jsg/v8-platform-wrapper.c++ | 2 +- src/workerd/server/pyodide.h | 1 - src/workerd/server/workerd-api.h | 1 - .../server/workerd-debug-port-client.h | 1 - src/workerd/util/checked-queue.h | 2 -- src/workerd/util/mimetype.h | 1 - src/workerd/util/sentry.h | 2 -- src/workerd/util/strong-bool.h | 8 +++++-- src/workerd/util/thread-scopes.h | 2 +- src/workerd/util/use-perfetto-categories.h | 2 ++ 64 files changed, 83 insertions(+), 86 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 4f9a175ff10..3811b50f128 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,6 +29,7 @@ Checks: > google-readability-casting, misc-confusable-identifiers, misc-header-include-cycle, + misc-include-cleaner, misc-redundant-expression, misc-throw-by-value-catch-by-reference, misc-unused-alias-decls, @@ -96,6 +97,11 @@ CheckOptions: value: "jsg/jsg.h|jsg/dom-exception.h" - key: cppcoreguidelines-missing-std-forward.ForwardFunction value: "kj::fwd" + - key: misc-include-cleaner.MissingIncludes + value: False + # Ignore KJ headers (too many to clean up for now) and some JSG headers where misc-include-cleaner reports false positives + - key: misc-include-cleaner.IgnoreHeaders + value: "jsg.h|function.h|kj/.*" #### # Custom checks. diff --git a/build/tools/clang_tidy/check_path_filters.bzl b/build/tools/clang_tidy/check_path_filters.bzl index fd915f060b4..e88631fe511 100644 --- a/build/tools/clang_tidy/check_path_filters.bzl +++ b/build/tools/clang_tidy/check_path_filters.bzl @@ -23,3 +23,9 @@ CHECK_PATH_FILTERS = { # "src/workerd/api", ], } + +HEADER_ONLY_CHECKS = [ + # Enabling misc-include-cleaner on headers means having to clean up much + # fewer includes while still getting rid of superfluous transitive includes. + "misc-include-cleaner", +] diff --git a/build/tools/clang_tidy/clang_tidy.bzl b/build/tools/clang_tidy/clang_tidy.bzl index ee15bd794f5..1cb512ac0bb 100644 --- a/build/tools/clang_tidy/clang_tidy.bzl +++ b/build/tools/clang_tidy/clang_tidy.bzl @@ -7,13 +7,15 @@ load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") -load("//build/tools/clang_tidy:check_path_filters.bzl", "CHECK_PATH_FILTERS") +load("//build/tools/clang_tidy:check_path_filters.bzl", "CHECK_PATH_FILTERS", "HEADER_ONLY_CHECKS") def _get_disabled_checks_for_file(file_path): """Returns checks that should be disabled for this file. Checks listed in CHECK_PATH_FILTERS are only enabled for files under their allowed paths. For files not under any allowed path, the check is disabled. + Checks listed in HEADER_ONLY_CHECKS are only enabled for header files and + disabled otherwise. """ disabled = [] for check, allowed_paths in CHECK_PATH_FILTERS.items(): @@ -30,6 +32,11 @@ def _get_disabled_checks_for_file(file_path): break if not enabled: disabled.append(check) + + for check in HEADER_ONLY_CHECKS: + if not file_path.endswith(".h"): + disabled.append(check) + return disabled def _clang_tidy_aspect_impl(target, ctx): @@ -60,6 +67,12 @@ def _clang_tidy_aspect_impl(target, ctx): # we use $location in our copts, expand it rule_copts = [ctx.expand_location(opt) for opt in rule_copts] + # disable clang tidy if no-clang-tidy tag is defined. For no-clang-tidy- + # headers, we only disable it on header files. + # todo: figure out a better way to control clang tidy on a per-target basis. + if "no-clang-tidy" in ctx.rule.attr.tags: + return [] + srcs = [] if hasattr(ctx.rule.attr, "srcs"): for src in ctx.rule.attr.srcs: @@ -68,7 +81,7 @@ def _clang_tidy_aspect_impl(target, ctx): for src in src.files.to_list() if src.is_source and src.short_path.endswith((".c++", ".c", ".h")) ] - if hasattr(ctx.rule.attr, "hdrs"): + if hasattr(ctx.rule.attr, "hdrs") and not "no-clang-tidy-headers" in ctx.rule.attr.tags: for src in ctx.rule.attr.hdrs: srcs += [ src @@ -84,11 +97,6 @@ def _clang_tidy_aspect_impl(target, ctx): external_includes = compilation_context.external_includes.to_list() headers = compilation_context.headers - # disable clang tidy if no-clang-tidy tag is defined. - # todo: figure out a better way to control clang tidy on a per-target basis. - if "no-clang-tidy" in ctx.rule.attr.tags: - return [] - # bazel doesn't expose implementation deps through compilation context # https://github.com/bazelbuild/bazel/issues/19663 if hasattr(ctx.rule.attr, "implementation_deps"): diff --git a/src/rust/cxx/include/cxx.h b/src/rust/cxx/include/cxx.h index 9ca54c3f586..3ba90332e82 100644 --- a/src/rust/cxx/include/cxx.h +++ b/src/rust/cxx/include/cxx.h @@ -8,12 +8,10 @@ #include #include #include -#include #include #include #include #include -#include #ifdef _WIN32 #include #else diff --git a/src/rust/cxx/kj-rs/future.h b/src/rust/cxx/kj-rs/future.h index 39aae452a09..a8c243a347d 100644 --- a/src/rust/cxx/kj-rs/future.h +++ b/src/rust/cxx/kj-rs/future.h @@ -5,7 +5,6 @@ #include -#include #include namespace kj_rs { diff --git a/src/rust/cxx/kj-rs/kj-rs.h b/src/rust/cxx/kj-rs/kj-rs.h index 78e093e79e3..4e4756e1e1b 100644 --- a/src/rust/cxx/kj-rs/kj-rs.h +++ b/src/rust/cxx/kj-rs/kj-rs.h @@ -1,8 +1,11 @@ #pragma once +// This file is intentionally used as a catchall kj-rs header +// NOLINTBEGIN(misc-include-cleaner) // KJ-C++ conversion utilities #include "kj-rs/convert.h" // Rust futures support #include "kj-rs/future.h" // KJ promises support #include "kj-rs/promise.h" +// NOLINTEND(misc-include-cleaner) diff --git a/src/rust/cxx/src/cxx.cc b/src/rust/cxx/src/cxx.cc index 7384d28992d..7ce73d260f2 100644 --- a/src/rust/cxx/src/cxx.cc +++ b/src/rust/cxx/src/cxx.cc @@ -5,6 +5,7 @@ #include #include #include +#include extern "C" { void cxxbridge1$cxx_string$init(std::string *s, const std::uint8_t *ptr, diff --git a/src/rust/cxx/tests/ffi/tests.h b/src/rust/cxx/tests/ffi/tests.h index 556407d44ba..c7f1a714e3a 100644 --- a/src/rust/cxx/tests/ffi/tests.h +++ b/src/rust/cxx/tests/ffi/tests.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace A { struct AShared; diff --git a/src/rust/jsg-test/ffi.h b/src/rust/jsg-test/ffi.h index 58c74ab9b7e..1aef7b1f658 100644 --- a/src/rust/jsg-test/ffi.h +++ b/src/rust/jsg-test/ffi.h @@ -8,9 +8,8 @@ #include #include -#include #include -#include +#include #include #include diff --git a/src/rust/jsg/BUILD.bazel b/src/rust/jsg/BUILD.bazel index 7a3b3cd9dd4..925c177df48 100644 --- a/src/rust/jsg/BUILD.bazel +++ b/src/rust/jsg/BUILD.bazel @@ -26,7 +26,6 @@ wd_cc_library( srcs = [], hdrs = ["jsg.h"], local_defines = ["JSG_IMPLEMENTATION"], - tags = ["no-clang-tidy"], visibility = ["//visibility:public"], deps = [":jsg"], ) @@ -38,7 +37,6 @@ wd_cc_library( "ffi.h", ], local_defines = ["JSG_IMPLEMENTATION"], - tags = ["no-clang-tidy"], textual_hdrs = [ "ffi-inl.h", ], diff --git a/src/rust/jsg/ffi.c++ b/src/rust/jsg/ffi.c++ index a2f904a59aa..3293df73361 100644 --- a/src/rust/jsg/ffi.c++ +++ b/src/rust/jsg/ffi.c++ @@ -78,7 +78,7 @@ static v8::Local makeInternedStr(v8::Isolate* isolate, const Name& n } // Wrappable implementation - calls into Rust via CXX bridge -Wrappable::~Wrappable() { +Wrappable::~Wrappable() noexcept(false) { wrappable_invoke_drop(*this); } diff --git a/src/rust/jsg/ffi.h b/src/rust/jsg/ffi.h index 16f56170280..a1dfc9cc973 100644 --- a/src/rust/jsg/ffi.h +++ b/src/rust/jsg/ffi.h @@ -4,12 +4,10 @@ #pragma once -#include #include -#include #include -#include +#include #include #include @@ -56,7 +54,7 @@ struct TraitObjectPtr { // and destruction without knowing the concrete type at compile time. class Wrappable: public ::workerd::jsg::Wrappable { public: - ~Wrappable(); + ~Wrappable() noexcept(false); void jsgVisitForGc(::workerd::jsg::GcVisitor& visitor) override; kj::StringPtr jsgGetMemoryName() const override; size_t jsgGetMemorySelfSize() const override; diff --git a/src/rust/jsg/jsg.h b/src/rust/jsg/jsg.h index 0d6bb72c5c3..e1ac9d1593a 100644 --- a/src/rust/jsg/jsg.h +++ b/src/rust/jsg/jsg.h @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/src/rust/worker/bridge.h b/src/rust/worker/bridge.h index 7e4b4bb5c91..9e8d44c53d0 100644 --- a/src/rust/worker/bridge.h +++ b/src/rust/worker/bridge.h @@ -6,8 +6,6 @@ #include -#include - namespace workerd::rust::worker { inline workerd::EventOutcome fromImpl(kj_rs::Rust*, workerd::rust::worker::EventOutcome outcome) { diff --git a/src/workerd/api/container.h b/src/workerd/api/container.h index d097b597211..dec948bc21e 100644 --- a/src/workerd/api/container.h +++ b/src/workerd/api/container.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/workerd/api/crypto/impl.h b/src/workerd/api/crypto/impl.h index 1a25fa8f6b9..c26653635db 100644 --- a/src/workerd/api/crypto/impl.h +++ b/src/workerd/api/crypto/impl.h @@ -9,6 +9,8 @@ #include "crypto.h" +// For fastEncodeBase64Url, widely used in crypto implementation +// NOLINTNEXTLINE(misc-include-cleaner) #include #include diff --git a/src/workerd/api/data-url.c++ b/src/workerd/api/data-url.c++ index 11b3d264682..02e1294270c 100644 --- a/src/workerd/api/data-url.c++ +++ b/src/workerd/api/data-url.c++ @@ -4,6 +4,7 @@ #include +#include #include namespace workerd::api { diff --git a/src/workerd/api/eventsource.c++ b/src/workerd/api/eventsource.c++ index 21e3e35687c..75eac57a74b 100644 --- a/src/workerd/api/eventsource.c++ +++ b/src/workerd/api/eventsource.c++ @@ -4,8 +4,8 @@ #include "eventsource.h" +#include "events.h" #include "http.h" -#include "messagechannel.h" #include "streams/common.h" #include diff --git a/src/workerd/api/eventsource.h b/src/workerd/api/eventsource.h index 70158abf21b..b0f359717c4 100644 --- a/src/workerd/api/eventsource.h +++ b/src/workerd/api/eventsource.h @@ -4,7 +4,6 @@ #pragma once #include "basics.h" -#include "events.h" #include "http.h" #include diff --git a/src/workerd/api/fuzzilli.c++ b/src/workerd/api/fuzzilli.c++ index 0a9e7443e15..603d636aa32 100644 --- a/src/workerd/api/fuzzilli.c++ +++ b/src/workerd/api/fuzzilli.c++ @@ -6,7 +6,12 @@ #include #include +#include #include +#include +#include +#include +#include #include #include diff --git a/src/workerd/api/fuzzilli.h b/src/workerd/api/fuzzilli.h index 5d2b167af86..b74eabf0a69 100644 --- a/src/workerd/api/fuzzilli.h +++ b/src/workerd/api/fuzzilli.h @@ -4,13 +4,8 @@ #include #include -#include #include #include -#include -#include -#include -#include #include diff --git a/src/workerd/api/global-scope.h b/src/workerd/api/global-scope.h index 926963caefe..2a722eeadbf 100644 --- a/src/workerd/api/global-scope.h +++ b/src/workerd/api/global-scope.h @@ -5,6 +5,7 @@ #pragma once #include "basics.h" +#include "events.h" #include "filesystem.h" #include "http.h" #include "messagechannel.h" diff --git a/src/workerd/api/html-rewriter.h b/src/workerd/api/html-rewriter.h index 730073106eb..e64d832c207 100644 --- a/src/workerd/api/html-rewriter.h +++ b/src/workerd/api/html-rewriter.h @@ -7,7 +7,7 @@ #include #include -#include +#include struct lol_html_HtmlRewriterBuilder; struct lol_html_HtmlRewriter; diff --git a/src/workerd/api/messagechannel.h b/src/workerd/api/messagechannel.h index 88c0be2b635..e48ee7c1b66 100644 --- a/src/workerd/api/messagechannel.h +++ b/src/workerd/api/messagechannel.h @@ -1,10 +1,8 @@ #pragma once #include -#include #include #include -#include #include namespace workerd::api { diff --git a/src/workerd/api/modules.h b/src/workerd/api/modules.h index d1dc04b991a..6a2b66f4001 100644 --- a/src/workerd/api/modules.h +++ b/src/workerd/api/modules.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/src/workerd/api/node/node.h b/src/workerd/api/node/node.h index c43c05151fc..343bf0a7e14 100644 --- a/src/workerd/api/node/node.h +++ b/src/workerd/api/node/node.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -23,8 +22,6 @@ #include -#include - namespace workerd::api::node { #define NODEJS_MODULES(V) \ diff --git a/src/workerd/api/node/process.c++ b/src/workerd/api/node/process.c++ index 31909c20a2b..ae28437596a 100644 --- a/src/workerd/api/node/process.c++ +++ b/src/workerd/api/node/process.c++ @@ -3,6 +3,8 @@ // https://opensource.org/licenses/Apache-2.0 #include "process.h" +#include "node-version.h" + #include #include #include diff --git a/src/workerd/api/node/process.h b/src/workerd/api/node/process.h index 085c4d153b9..4e842d06b92 100644 --- a/src/workerd/api/node/process.h +++ b/src/workerd/api/node/process.h @@ -3,9 +3,6 @@ // https://opensource.org/licenses/Apache-2.0 #pragma once -#include -#include -#include #include namespace workerd::api::node { diff --git a/src/workerd/api/pyodide/pyodide.h b/src/workerd/api/pyodide/pyodide.h index 5ed363ac422..4b2bb5cde49 100644 --- a/src/workerd/api/pyodide/pyodide.h +++ b/src/workerd/api/pyodide/pyodide.h @@ -5,11 +5,9 @@ #include #include -#include #include #include -#include #include #include diff --git a/src/workerd/api/r2-bucket.h b/src/workerd/api/r2-bucket.h index a57770965f9..c1a3275243a 100644 --- a/src/workerd/api/r2-bucket.h +++ b/src/workerd/api/r2-bucket.h @@ -6,7 +6,7 @@ #include "r2-rpc.h" -#include +#include #include namespace workerd::api { diff --git a/src/workerd/api/r2.h b/src/workerd/api/r2.h index eb104bbef50..62809f1c953 100644 --- a/src/workerd/api/r2.h +++ b/src/workerd/api/r2.h @@ -4,7 +4,9 @@ #pragma once +// NOLINTNEXTLINE(misc-include-cleaner) #include "r2-bucket.h" +// NOLINTNEXTLINE(misc-include-cleaner) #include "r2-multipart.h" namespace workerd::api::public_beta { diff --git a/src/workerd/api/streams.h b/src/workerd/api/streams.h index 917e5462e10..0288b070d85 100644 --- a/src/workerd/api/streams.h +++ b/src/workerd/api/streams.h @@ -7,6 +7,9 @@ // // This is the most over-engineered spec... +// This header is intentionally used to include the entire streams API – include it only when +// strictly necessary +// NOLINTBEGIN(misc-include-cleaner) #include #include #include @@ -16,6 +19,7 @@ #include #include #include +// NOLINTEND(misc-include-cleaner) namespace workerd::api { diff --git a/src/workerd/api/streams/compression.c++ b/src/workerd/api/streams/compression.c++ index 6d582d25101..ff8dbee4484 100644 --- a/src/workerd/api/streams/compression.c++ +++ b/src/workerd/api/streams/compression.c++ @@ -12,6 +12,8 @@ #include #include +#include + namespace workerd::api { CompressionAllocator::CompressionAllocator( kj::Arc&& externalMemoryTarget) diff --git a/src/workerd/api/streams/compression.h b/src/workerd/api/streams/compression.h index 6309179d385..9fe69454c96 100644 --- a/src/workerd/api/streams/compression.h +++ b/src/workerd/api/streams/compression.h @@ -7,8 +7,6 @@ #include #include -#include - namespace workerd::api { // A custom allocator to be used by the zlib and brotli libraries. @@ -19,7 +17,7 @@ class CompressionAllocator final { public: CompressionAllocator(kj::Arc&& externalMemoryTarget); - static void* AllocForZlib(void* data, uInt items, uInt size); + static void* AllocForZlib(void* data, uint items, uint size); static void* AllocForBrotli(void* data, size_t size); static void FreeForZlib(void* data, void* pointer); diff --git a/src/workerd/api/streams/writable.h b/src/workerd/api/streams/writable.h index 46444760995..ccd283ba1e6 100644 --- a/src/workerd/api/streams/writable.h +++ b/src/workerd/api/streams/writable.h @@ -7,7 +7,6 @@ #include "common.h" #include -#include namespace workerd::api { diff --git a/src/workerd/api/unsafe.h b/src/workerd/api/unsafe.h index baed5bc2b8f..bf73e30ca47 100644 --- a/src/workerd/api/unsafe.h +++ b/src/workerd/api/unsafe.h @@ -1,9 +1,7 @@ #pragma once -#include #include #include -#include #include #include @@ -11,11 +9,11 @@ #ifdef _WIN32 #include -#else -#include #endif +#ifdef WORKERD_FUZZILLI #include +#endif namespace workerd::api { diff --git a/src/workerd/api/util.h b/src/workerd/api/util.h index bc1b6507411..f662514ecb4 100644 --- a/src/workerd/api/util.h +++ b/src/workerd/api/util.h @@ -6,8 +6,6 @@ #include -#include - #include #include #include diff --git a/src/workerd/api/web-socket.h b/src/workerd/api/web-socket.h index 63ee58a1404..dd16cd81e69 100644 --- a/src/workerd/api/web-socket.h +++ b/src/workerd/api/web-socket.h @@ -5,7 +5,6 @@ #pragma once #include "basics.h" -#include "events.h" #include #include @@ -16,7 +15,6 @@ #include #include -#include namespace workerd { class ActorObserver; diff --git a/src/workerd/api/worker-loader.h b/src/workerd/api/worker-loader.h index 6a39468cc4e..e3daf329ef2 100644 --- a/src/workerd/api/worker-loader.h +++ b/src/workerd/api/worker-loader.h @@ -5,7 +5,6 @@ #include #include #include -#include namespace workerd::api { diff --git a/src/workerd/api/worker-rpc.h b/src/workerd/api/worker-rpc.h index 6cc4a4cb226..ca948b7b440 100644 --- a/src/workerd/api/worker-rpc.h +++ b/src/workerd/api/worker-rpc.h @@ -18,9 +18,7 @@ #include #include #include -#include #include -#include namespace workerd::api { diff --git a/src/workerd/io/limit-enforcer.h b/src/workerd/io/limit-enforcer.h index 9d14f084a6e..401210bfabe 100644 --- a/src/workerd/io/limit-enforcer.h +++ b/src/workerd/io/limit-enforcer.h @@ -10,7 +10,6 @@ #include #include // For Promise -#include // For KJ_REQUIRE #include // for Own #include // for OneOf #include // for Duration diff --git a/src/workerd/io/trace.h b/src/workerd/io/trace.h index c0aca4514c9..8e87192367b 100644 --- a/src/workerd/io/trace.h +++ b/src/workerd/io/trace.h @@ -18,7 +18,6 @@ #include #include -#include #include namespace kj { diff --git a/src/workerd/io/worker-interface.h b/src/workerd/io/worker-interface.h index 453669e83dd..87df3e502a2 100644 --- a/src/workerd/io/worker-interface.h +++ b/src/workerd/io/worker-interface.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/src/workerd/io/worker-modules.h b/src/workerd/io/worker-modules.h index 47221ca48dc..3b486c6d11f 100644 --- a/src/workerd/io/worker-modules.h +++ b/src/workerd/io/worker-modules.h @@ -2,11 +2,13 @@ #include #include +#include #include #include #include #include +#include #include #include diff --git a/src/workerd/jsg/BUILD.bazel b/src/workerd/jsg/BUILD.bazel index 9d9eb74f984..84614ffc7dd 100644 --- a/src/workerd/jsg/BUILD.bazel +++ b/src/workerd/jsg/BUILD.bazel @@ -116,7 +116,7 @@ wd_cc_library( "@ssl", ], local_defines = ["JSG_IMPLEMENTATION"], - tags = ["no-clang-tidy"], + tags = ["no-clang-tidy-headers"], visibility = [ "//src/rust/jsg:__pkg__", "//src/rust/jsg-test:__pkg__", diff --git a/src/workerd/jsg/iterator.h b/src/workerd/jsg/iterator.h index cc439b2c83a..35d3871f26b 100644 --- a/src/workerd/jsg/iterator.h +++ b/src/workerd/jsg/iterator.h @@ -6,6 +6,7 @@ #include #include +// NOLINTNEXTLINE(misc-include-cleaner) #include #include diff --git a/src/workerd/jsg/jsg-test.h b/src/workerd/jsg/jsg-test.h index 6afc4211ecc..9c27149da90 100644 --- a/src/workerd/jsg/jsg-test.h +++ b/src/workerd/jsg/jsg-test.h @@ -8,6 +8,8 @@ #include #include #include +// False negative +// NOLINTNEXTLINE(misc-include-cleaner) #include #include diff --git a/src/workerd/jsg/jsvalue.c++ b/src/workerd/jsg/jsvalue.c++ index 8eaf0f12561..0ad87b2ae24 100644 --- a/src/workerd/jsg/jsvalue.c++ +++ b/src/workerd/jsg/jsvalue.c++ @@ -466,7 +466,7 @@ kj::String JsDate::toISOString(jsg::Lock& js) const { } JsDate::operator kj::Date() const { - return kj::UNIX_EPOCH + (int64_t(inner->ValueOf()) * kj::MILLISECONDS); + return kj::UNIX_EPOCH + (static_cast(inner->ValueOf()) * kj::MILLISECONDS); } JsRegExp Lock::regexp(kj::StringPtr str, RegExpFlags flags, kj::Maybe backtrackLimit) { @@ -743,7 +743,7 @@ kj::ArrayPtr JsArrayBuffer::asArrayPtr() const { JsArrayBuffer JsArrayBuffer::slice(Lock& js, size_t newLength) const { JSG_REQUIRE(newLength <= size(), RangeError, "New length exceeds buffer length"); auto dest = create(js, newLength); - dest.asArrayPtr().copyFrom(asArrayPtr().slice(0, newLength)); + dest.asArrayPtr().copyFrom(asArrayPtr().first(newLength)); return dest; } @@ -933,7 +933,7 @@ kj::ArrayPtr JsSharedArrayBuffer::asArrayPtr() const { JsSharedArrayBuffer JsSharedArrayBuffer::slice(Lock& js, size_t newLength) const { JSG_REQUIRE(newLength <= size(), RangeError, "New length exceeds buffer length"); auto dest = create(js, newLength); - dest.asArrayPtr().copyFrom(asArrayPtr().slice(0, newLength)); + dest.asArrayPtr().copyFrom(asArrayPtr().first(newLength)); return dest; } diff --git a/src/workerd/jsg/memory.h b/src/workerd/jsg/memory.h index 3a1471ac273..4f6839cab54 100644 --- a/src/workerd/jsg/memory.h +++ b/src/workerd/jsg/memory.h @@ -13,9 +13,7 @@ #include #include -#include #include -#include #include #include #include diff --git a/src/workerd/jsg/modules-new.c++ b/src/workerd/jsg/modules-new.c++ index 9c53a7836c3..d4617a8104c 100644 --- a/src/workerd/jsg/modules-new.c++ +++ b/src/workerd/jsg/modules-new.c++ @@ -1140,7 +1140,7 @@ class IsolateModuleRegistry final { }; struct InstanceCallbacks final { - const Entry& keyForRow(const Entry& entry) const { + const Entry& keyForRow(const Entry& entry KJ_LIFETIMEBOUND) const { return entry; } bool matches(const Entry& entry, const Url& id, const Module* def) const { diff --git a/src/workerd/jsg/modules.c++ b/src/workerd/jsg/modules.c++ index e76e335ff12..495b1bbc54a 100644 --- a/src/workerd/jsg/modules.c++ +++ b/src/workerd/jsg/modules.c++ @@ -8,8 +8,6 @@ #include -#include - #include namespace workerd::jsg { diff --git a/src/workerd/jsg/struct.h b/src/workerd/jsg/struct.h index 32a45e13088..e0a9dd8e412 100644 --- a/src/workerd/jsg/struct.h +++ b/src/workerd/jsg/struct.h @@ -9,10 +9,8 @@ // struct is translated to/from a native JS object with the same field names. #include -#include #include -#include #include namespace workerd::jsg { diff --git a/src/workerd/jsg/type-wrapper.h b/src/workerd/jsg/type-wrapper.h index bfd1f670d6b..dca07db5f4a 100644 --- a/src/workerd/jsg/type-wrapper.h +++ b/src/workerd/jsg/type-wrapper.h @@ -7,6 +7,7 @@ // // The TypeWrapper knows how to convert a variety of types between C++ and JavaScript. +// NOLINTNEXTLINE(misc-include-cleaner) #include #include #include diff --git a/src/workerd/jsg/url-test.c++ b/src/workerd/jsg/url-test.c++ index a8bf87fd37b..e1bd128146d 100644 --- a/src/workerd/jsg/url-test.c++ +++ b/src/workerd/jsg/url-test.c++ @@ -7,8 +7,6 @@ #include #include -#include - namespace workerd::jsg::test { namespace { diff --git a/src/workerd/jsg/v8-platform-wrapper.c++ b/src/workerd/jsg/v8-platform-wrapper.c++ index 503804b88ed..fecdef08533 100644 --- a/src/workerd/jsg/v8-platform-wrapper.c++ +++ b/src/workerd/jsg/v8-platform-wrapper.c++ @@ -6,7 +6,7 @@ #include "jsg.h" -#include +#include namespace workerd::jsg { diff --git a/src/workerd/server/pyodide.h b/src/workerd/server/pyodide.h index ab66407faca..a92a94ce454 100644 --- a/src/workerd/server/pyodide.h +++ b/src/workerd/server/pyodide.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include diff --git a/src/workerd/server/workerd-api.h b/src/workerd/server/workerd-api.h index 7377abc0d10..b38efc19805 100644 --- a/src/workerd/server/workerd-api.h +++ b/src/workerd/server/workerd-api.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include diff --git a/src/workerd/server/workerd-debug-port-client.h b/src/workerd/server/workerd-debug-port-client.h index 664ff5899ec..c648b8d61a4 100644 --- a/src/workerd/server/workerd-debug-port-client.h +++ b/src/workerd/server/workerd-debug-port-client.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include #include diff --git a/src/workerd/util/checked-queue.h b/src/workerd/util/checked-queue.h index 2294212b534..3d3c6d93017 100644 --- a/src/workerd/util/checked-queue.h +++ b/src/workerd/util/checked-queue.h @@ -2,9 +2,7 @@ #include #include -#include -#include #include namespace workerd::util { diff --git a/src/workerd/util/mimetype.h b/src/workerd/util/mimetype.h index 1c4b9dac31a..e05297bee0d 100644 --- a/src/workerd/util/mimetype.h +++ b/src/workerd/util/mimetype.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include diff --git a/src/workerd/util/sentry.h b/src/workerd/util/sentry.h index 2ff914fd637..865ec9328a7 100644 --- a/src/workerd/util/sentry.h +++ b/src/workerd/util/sentry.h @@ -12,8 +12,6 @@ #include #include -#include - namespace workerd { // For internal errors, we generate an ID to include when rendering user-facing "internal error" diff --git a/src/workerd/util/strong-bool.h b/src/workerd/util/strong-bool.h index 6bdb4484247..3a0da784bd5 100644 --- a/src/workerd/util/strong-bool.h +++ b/src/workerd/util/strong-bool.h @@ -5,8 +5,12 @@ #include -#include -#include +// This header does not use the given includes directly, but any source file that uses +// WD_STRONG_BOOL will need them. +// NOLINTBEGIN(misc-include-cleaner) +#include // For operator<=> +#include // For std::uint8_t +// NOLINTEND(misc-include-cleaner) namespace workerd { diff --git a/src/workerd/util/thread-scopes.h b/src/workerd/util/thread-scopes.h index cdb0b4fc2b8..105043a22ce 100644 --- a/src/workerd/util/thread-scopes.h +++ b/src/workerd/util/thread-scopes.h @@ -22,7 +22,7 @@ #define WORKERD_ASAN 1 #endif -#include +#include namespace workerd { diff --git a/src/workerd/util/use-perfetto-categories.h b/src/workerd/util/use-perfetto-categories.h index 678f30760e7..3d952a57edb 100644 --- a/src/workerd/util/use-perfetto-categories.h +++ b/src/workerd/util/use-perfetto-categories.h @@ -1,5 +1,7 @@ #pragma once +// This file is widely used to enable perfetto +// NOLINTNEXTLINE(misc-include-cleaner) #include // This header is to be imported by any translation unit (c++ file) that