Skip to content

[Engine] Consider enabling clang-tidy: misc-include-cleaner #133417

@matanlurey

Description

@matanlurey

clangd has a "preview mode" for a feature called "Include Cleaner":

Manually managing includes in a C++ translation unit, especially in the face of transitive inclusions, requires a lot of effort. Include Cleaner aims to provide diagnostics to keep includes in an IWYU-clean state.

// main.cpp

#include "foo.h"
#include "bar.h" // <- Will be marked as unused and suggested to be removed.

int main() {
  Foo f;
}

It can be enabled with a .clangd file at the root:

# .clangd
Diagnostics:
  UnusedIncludes: Strict
  MissingIncludes: Strict

To run these on CI, we can include the Clang Tidy check misc-include-cleaner:

https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html

Here are some files I spot-checked in the engine repo:

Screenshot 2023-08-27 at 2 58 18 PM

Screenshot 2023-08-27 at 2 56 18 PM

Screenshot 2023-08-27 at 2 57 00 PM

Screenshot 2023-08-27 at 2 57 45 PM

And here is an example of running clang-tidy --fix on dl_unittests.cc:

impeller/display_list/dl_unittests.cc
@@ -3,10 +3,18 @@
 // found in the LICENSE file.
 
 #include <array>
+#include <cassert>
 #include <cmath>
+#include <cstddef>
+#include <cstdint>
 #include <memory>
+#include <optional>
+#include <tuple>
 #include <vector>
 
+#include "display_list/dl_canvas.h"
+#include "display_list/dl_sampling_options.h"
+#include "display_list/dl_vertices.h"
 #include "flutter/display_list/display_list_builder.h"
 #include "flutter/display_list/dl_blend_mode.h"
 #include "flutter/display_list/dl_color.h"
@@ -16,24 +24,33 @@
 #include "flutter/display_list/effects/dl_color_source.h"
 #include "flutter/display_list/effects/dl_image_filter.h"
 #include "flutter/display_list/effects/dl_mask_filter.h"
-#include "flutter/testing/testing.h"
+#include "gtest/gtest-param-test.h"
 #include "gtest/gtest.h"
 #include "impeller/display_list/dl_dispatcher.h"
 #include "impeller/display_list/dl_image_impeller.h"
 #include "impeller/display_list/dl_playground.h"
 #include "impeller/entity/contents/solid_color_contents.h"
 #include "impeller/entity/contents/solid_rrect_blur_contents.h"
+#include "impeller/entity/entity.h"
+#include "impeller/geometry/color.h"
 #include "impeller/geometry/constants.h"
 #include "impeller/geometry/point.h"
+#include "impeller/geometry/rect.h"
 #include "impeller/geometry/scalar.h"
+#include "impeller/playground/playground_test.h"
 #include "impeller/playground/widgets.h"
-#include "impeller/scene/node.h"
+#include "include/core/SkPath.h"
+#include "include/core/SkPath.h"
+#include "include/core/SkPathTypes.h"
+#include "include/core/SkPoint.h"
+#include "include/core/SkRect.h"
+#include "include/core/SkScalar.h"
+#include "include/core/SkTextBlob.h"
 #include "third_party/imgui/imgui.h"
-#include "third_party/skia/include/core/SkBlurTypes.h"
-#include "third_party/skia/include/core/SkClipOp.h"
 #include "third_party/skia/include/core/SkPathBuilder.h"
 #include "third_party/skia/include/core/SkRRect.h"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.engineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions