Skip to content

Commit 31afa38

Browse files
authored
[lint] Merge impeller .clang-tidy into main config (flutter#33692)
Merges most (but not all) of the impeller .clang-tidy rules into the main .clang-tidy config. Merges: readability-identifier-naming.PrivateMemberSuffix (_) readability-identifier-naming.EnumConstantPrefix (k) modernize-use-default-member-init.UseAssignment Does not merge: readability-identifier-naming.PublicMethodCase (CamelCase) readability-identifier-naming.PrivateMethodCase (CamelCase) These last two are not merged due to the non-trivial number of existing field accessors that use field_name() methods to directly return field_name_. While these are permitted by the C++ style guide, we may want to move to a single, simple rule and name everything in CamelCase. These can be enabled in a followup patch. No new tests added, since this change is style-only.
1 parent 47988c1 commit 31afa38

31 files changed

+170
-172
lines changed

.clang-tidy

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Checks: "google-*,\
33
clang-analyzer-*,\
44
clang-diagnostic-*,\
5+
modernize-use-default-member-init,\
56
readability-identifier-naming,\
67
-google-objc-global-variable-declaration,\
78
-google-objc-avoid-throwing-exception,\
@@ -22,5 +23,15 @@ google-objc-*,\
2223
google-explicit-constructor"
2324

2425
CheckOptions:
25-
- key: readability-identifier-naming.GlobalConstantPrefix
26-
value: k
26+
- key: modernize-use-default-member-init.UseAssignment
27+
value: true
28+
- key: readability-identifier-naming.EnumConstantCase
29+
value: 'CamelCase'
30+
- key: readability-identifier-naming.EnumConstantPrefix
31+
value: 'k'
32+
- key: readability-identifier-naming.GlobalConstantPrefix
33+
value: 'k'
34+
- key: readability-identifier-naming.PrivateMemberCase
35+
value: 'lower_case'
36+
- key: readability-identifier-naming.PrivateMemberSuffix
37+
value: '_'

ci/licenses_golden/licenses_flutter

-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ FILE: ../../../flutter/fml/unique_fd.cc
397397
FILE: ../../../flutter/fml/unique_fd.h
398398
FILE: ../../../flutter/fml/unique_object.h
399399
FILE: ../../../flutter/fml/wakeable.h
400-
FILE: ../../../flutter/impeller/.clang-tidy
401400
FILE: ../../../flutter/impeller/aiks/aiks_context.cc
402401
FILE: ../../../flutter/impeller/aiks/aiks_context.h
403402
FILE: ../../../flutter/impeller/aiks/aiks_playground.cc

display_list/display_list_unittests.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1360,15 +1360,15 @@ TEST(DisplayList, DisplayListBlenderRefHandling) {
13601360
class BlenderRefTester : public virtual AttributeRefTester {
13611361
public:
13621362
void setRefToPaint(SkPaint& paint) const override {
1363-
paint.setBlender(blender);
1363+
paint.setBlender(blender_);
13641364
}
13651365
void setRefToDisplayList(DisplayListBuilder& builder) const override {
1366-
builder.setBlender(blender);
1366+
builder.setBlender(blender_);
13671367
}
1368-
bool ref_is_unique() const override { return blender->unique(); }
1368+
bool ref_is_unique() const override { return blender_->unique(); }
13691369

13701370
private:
1371-
sk_sp<SkBlender> blender =
1371+
sk_sp<SkBlender> blender_ =
13721372
SkBlenders::Arithmetic(0.25, 0.25, 0.25, 0.25, true);
13731373
};
13741374

flow/surface_frame.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
1717
const SubmitCallback& submit_callback,
1818
std::unique_ptr<GLContextResult> context_result,
1919
bool display_list_fallback)
20-
: submitted_(false),
21-
surface_(surface),
20+
: surface_(surface),
2221
framebuffer_info_(std::move(framebuffer_info)),
2322
submit_callback_(submit_callback),
2423
context_result_(std::move(context_result)) {

fml/platform/posix/mapping_posix.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ Mapping::Mapping() = default;
5151
Mapping::~Mapping() = default;
5252

5353
FileMapping::FileMapping(const fml::UniqueFD& handle,
54-
std::initializer_list<Protection> protection)
55-
: size_(0), mapping_(nullptr) {
54+
std::initializer_list<Protection> protection) {
5655
if (!handle.is_valid()) {
5756
return;
5857
}

fml/synchronization/semaphore.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,44 @@ namespace fml {
1515
class PlatformSemaphore {
1616
public:
1717
explicit PlatformSemaphore(uint32_t count)
18-
: _sem(dispatch_semaphore_create(count)), _initial(count) {}
18+
: sem_(dispatch_semaphore_create(count)), initial_(count) {}
1919

2020
~PlatformSemaphore() {
21-
for (uint32_t i = 0; i < _initial; ++i) {
21+
for (uint32_t i = 0; i < initial_; ++i) {
2222
Signal();
2323
}
24-
if (_sem != nullptr) {
25-
dispatch_release(reinterpret_cast<dispatch_object_t>(_sem));
26-
_sem = nullptr;
24+
if (sem_ != nullptr) {
25+
dispatch_release(reinterpret_cast<dispatch_object_t>(sem_));
26+
sem_ = nullptr;
2727
}
2828
}
2929

30-
bool IsValid() const { return _sem != nullptr; }
30+
bool IsValid() const { return sem_ != nullptr; }
3131

3232
bool Wait() {
33-
if (_sem == nullptr) {
33+
if (sem_ == nullptr) {
3434
return false;
3535
}
36-
return dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER) == 0;
36+
return dispatch_semaphore_wait(sem_, DISPATCH_TIME_FOREVER) == 0;
3737
}
3838

3939
bool TryWait() {
40-
if (_sem == nullptr) {
40+
if (sem_ == nullptr) {
4141
return false;
4242
}
4343

44-
return dispatch_semaphore_wait(_sem, DISPATCH_TIME_NOW) == 0;
44+
return dispatch_semaphore_wait(sem_, DISPATCH_TIME_NOW) == 0;
4545
}
4646

4747
void Signal() {
48-
if (_sem != nullptr) {
49-
dispatch_semaphore_signal(_sem);
48+
if (sem_ != nullptr) {
49+
dispatch_semaphore_signal(sem_);
5050
}
5151
}
5252

5353
private:
54-
dispatch_semaphore_t _sem;
55-
const uint32_t _initial;
54+
dispatch_semaphore_t sem_;
55+
const uint32_t initial_;
5656

5757
FML_DISALLOW_COPY_AND_ASSIGN(PlatformSemaphore);
5858
};

impeller/.clang-tidy

-30
This file was deleted.

impeller/archivist/archive_database.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace impeller {
1818

1919
struct ArchiveDatabase::Handle {
20-
Handle(const std::string& filename) {
20+
explicit Handle(const std::string& filename) {
2121
if (::sqlite3_initialize() != SQLITE_OK) {
2222
VALIDATION_LOG << "Could not initialize sqlite.";
2323
return;

impeller/archivist/archivist_unittests.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static int64_t LastSample = 0;
1818

1919
class Sample : public Archivable {
2020
public:
21-
Sample(uint64_t count = 42) : some_data_(count) {}
21+
explicit Sample(uint64_t count = 42) : some_data_(count) {}
2222

2323
Sample(Sample&&) = default;
2424

impeller/base/base_unittests.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TEST(ThreadTest, CanCreateRWMutex) {
4444
f.mtx.UnlockWriter();
4545
// int b = f.a; <--- Static analysis error.
4646
f.mtx.LockReader();
47-
int b = f.a;
47+
int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
4848
FML_ALLOW_UNUSED_LOCAL(b);
4949
f.mtx.UnlockReader();
5050
}
@@ -61,7 +61,7 @@ TEST(ThreadTest, CanCreateRWMutexLock) {
6161
// int b = f.a; <--- Static analysis error.
6262
{
6363
auto read_lock = ReaderLock(f.mtx);
64-
int b = f.a;
64+
int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
6565
FML_ALLOW_UNUSED_LOCAL(b);
6666
}
6767

impeller/blobcat/blob_library.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BlobLibrary::BlobLibrary(std::shared_ptr<fml::Mapping> mapping)
4242
{
4343
const size_t read_size = sizeof(Blob) * header.blob_count;
4444
::memcpy(blobs.data(), mapping_->GetMapping() + offset, read_size);
45-
offset += read_size;
45+
offset += read_size; // NOLINT(clang-analyzer-deadcode.DeadStores)
4646
}
4747

4848
// Read the blobs.

impeller/compiler/reflector.cc

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// FLUTTER_NOLINT: https://github.com/flutter/flutter/issues/105732
6+
57
#include "impeller/compiler/reflector.h"
68

79
#include <atomic>

impeller/entity/entity_unittests.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ TEST_P(EntityTest, CanCreateEntity) {
3838

3939
class TestPassDelegate final : public EntityPassDelegate {
4040
public:
41-
TestPassDelegate(std::optional<Rect> coverage) : coverage_(coverage) {}
41+
explicit TestPassDelegate(std::optional<Rect> coverage)
42+
: coverage_(coverage) {}
4243

4344
// |EntityPassDelegate|
4445
~TestPassDelegate() override = default;

impeller/geometry/path_component.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct CubicPathComponent {
130130

131131
struct ContourComponent {
132132
Point destination;
133-
bool is_closed;
133+
bool is_closed = false;
134134

135135
ContourComponent() {}
136136

impeller/renderer/backend/gles/texture_gles.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct TexImage2DData {
9090
GLenum type = GL_NONE;
9191
std::shared_ptr<const fml::Mapping> data;
9292

93-
TexImage2DData(PixelFormat pixel_format) {
93+
explicit TexImage2DData(PixelFormat pixel_format) {
9494
switch (pixel_format) {
9595
case PixelFormat::kA8UNormInt:
9696
internal_format = GL_ALPHA;

impeller/renderer/backend/metal/command_buffer_mtl.mm

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace impeller {
1010
namespace {
11+
12+
// NOLINTBEGIN(readability-identifier-naming)
13+
1114
// TODO(dnfield): remove this declaration when we no longer need to build on
1215
// machines with lower SDK versions than 11.0.
1316
#if !defined(MAC_OS_VERSION_11_0) || \
@@ -21,6 +24,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
2124
} API_AVAILABLE(macos(11.0), ios(14.0));
2225
#endif
2326

27+
// NOLINTEND(readability-identifier-naming)
28+
2429
API_AVAILABLE(ios(14.0), macos(11.0))
2530
NSString* MTLCommandEncoderErrorStateToString(
2631
MTLCommandEncoderErrorState state) {
@@ -39,6 +44,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
3944
return @"unknown";
4045
}
4146

47+
// NOLINTBEGIN(readability-identifier-naming)
48+
4249
// TODO(dnfield): This can be removed when all bots have been sufficiently
4350
// upgraded for MAC_OS_VERSION_12_0.
4451
#if !defined(MAC_OS_VERSION_12_0) || \
@@ -47,6 +54,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
4754
constexpr int MTLCommandBufferErrorStackOverflow = 12;
4855
#endif
4956

57+
// NOLINTEND(readability-identifier-naming)
58+
5059
static NSString* MTLCommandBufferErrorToString(MTLCommandBufferError code) {
5160
switch (code) {
5261
case MTLCommandBufferErrorNone:

impeller/renderer/backend/metal/render_pass_mtl.mm

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ static bool ConfigureStencilAttachment(
186186
/// absent.
187187
///
188188
struct PassBindingsCache {
189-
PassBindingsCache(id<MTLRenderCommandEncoder> encoder) : encoder_(encoder) {}
189+
explicit PassBindingsCache(id<MTLRenderCommandEncoder> encoder)
190+
: encoder_(encoder) {}
190191

191192
PassBindingsCache(const PassBindingsCache&) = delete;
192193

lib/ui/painting/paint.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ constexpr float kInvertColors[20] = {
6464
// clang-format on
6565

6666
// Must be kept in sync with the MaskFilter private constants in painting.dart.
67-
enum MaskFilterType { Null, Blur };
67+
enum MaskFilterType { kNull, kBlur };
6868

6969
Paint::Paint(Dart_Handle paint_objects, Dart_Handle paint_data)
7070
: paint_objects_(paint_objects), paint_data_(paint_data) {}
@@ -169,9 +169,9 @@ const SkPaint* Paint::paint(SkPaint& paint) const {
169169
}
170170

171171
switch (uint_data[kMaskFilterIndex]) {
172-
case Null:
172+
case kNull:
173173
break;
174-
case Blur:
174+
case kBlur:
175175
SkBlurStyle blur_style =
176176
static_cast<SkBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
177177
double sigma = float_data[kMaskFilterSigmaIndex];
@@ -300,10 +300,10 @@ bool Paint::sync_to(DisplayListBuilder* builder,
300300

301301
if (flags.applies_mask_filter()) {
302302
switch (uint_data[kMaskFilterIndex]) {
303-
case Null:
303+
case kNull:
304304
builder->setMaskFilter(nullptr);
305305
break;
306-
case Blur:
306+
case kBlur:
307307
SkBlurStyle blur_style =
308308
static_cast<SkBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
309309
double sigma = float_data[kMaskFilterSigmaIndex];

runtime/dart_isolate.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ constexpr std::string_view kFileUriPrefix = "file://";
4242

4343
class DartErrorString {
4444
public:
45-
DartErrorString() : str_(nullptr) {}
45+
DartErrorString() {}
4646
~DartErrorString() {
4747
if (str_) {
4848
::free(str_);
@@ -54,7 +54,7 @@ class DartErrorString {
5454

5555
private:
5656
FML_DISALLOW_COPY_AND_ASSIGN(DartErrorString);
57-
char* str_;
57+
char* str_ = nullptr;
5858
};
5959

6060
} // anonymous namespace

shell/common/skia_event_tracer_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FlutterEventTracer : public SkEventTracer {
8181

8282
FlutterEventTracer(bool enabled,
8383
const std::optional<std::vector<std::string>>& allowlist)
84-
: enabled_(enabled ? kYes : kNo), shaders_category_flag_(nullptr) {
84+
: enabled_(enabled ? kYes : kNo) {
8585
if (allowlist.has_value()) {
8686
allowlist_.emplace();
8787
for (const std::string& category : *allowlist) {
@@ -311,7 +311,7 @@ class FlutterEventTracer : public SkEventTracer {
311311
std::mutex flag_map_mutex_;
312312
std::map<const char*, uint8_t> category_flag_map_;
313313
std::map<const uint8_t*, const char*> reverse_flag_map_;
314-
const uint8_t* shaders_category_flag_;
314+
const uint8_t* shaders_category_flag_ = nullptr;
315315
FML_DISALLOW_COPY_AND_ASSIGN(FlutterEventTracer);
316316
};
317317

shell/gpu/gpu_surface_gl_skia.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ GPUSurfaceGLSkia::GPUSurfaceGLSkia(sk_sp<GrDirectContext> gr_context,
7373
bool render_to_surface)
7474
: delegate_(delegate),
7575
context_(gr_context),
76-
context_owner_(false),
76+
7777
render_to_surface_(render_to_surface),
7878
weak_factory_(this) {
7979
auto context_switch = delegate_->GLContextMakeCurrent();

0 commit comments

Comments
 (0)