Skip to content

Commit

Permalink
[lint] Merge impeller .clang-tidy into main config (#33692)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbracken authored Jun 21, 2022
1 parent 47988c1 commit 31afa38
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 172 deletions.
15 changes: 13 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Checks: "google-*,\
clang-analyzer-*,\
clang-diagnostic-*,\
modernize-use-default-member-init,\
readability-identifier-naming,\
-google-objc-global-variable-declaration,\
-google-objc-avoid-throwing-exception,\
Expand All @@ -22,5 +23,15 @@ google-objc-*,\
google-explicit-constructor"

CheckOptions:
- key: readability-identifier-naming.GlobalConstantPrefix
value: k
- key: modernize-use-default-member-init.UseAssignment
value: true
- key: readability-identifier-naming.EnumConstantCase
value: 'CamelCase'
- key: readability-identifier-naming.EnumConstantPrefix
value: 'k'
- key: readability-identifier-naming.GlobalConstantPrefix
value: 'k'
- key: readability-identifier-naming.PrivateMemberCase
value: 'lower_case'
- key: readability-identifier-naming.PrivateMemberSuffix
value: '_'
1 change: 0 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ FILE: ../../../flutter/fml/unique_fd.cc
FILE: ../../../flutter/fml/unique_fd.h
FILE: ../../../flutter/fml/unique_object.h
FILE: ../../../flutter/fml/wakeable.h
FILE: ../../../flutter/impeller/.clang-tidy
FILE: ../../../flutter/impeller/aiks/aiks_context.cc
FILE: ../../../flutter/impeller/aiks/aiks_context.h
FILE: ../../../flutter/impeller/aiks/aiks_playground.cc
Expand Down
8 changes: 4 additions & 4 deletions display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1360,15 +1360,15 @@ TEST(DisplayList, DisplayListBlenderRefHandling) {
class BlenderRefTester : public virtual AttributeRefTester {
public:
void setRefToPaint(SkPaint& paint) const override {
paint.setBlender(blender);
paint.setBlender(blender_);
}
void setRefToDisplayList(DisplayListBuilder& builder) const override {
builder.setBlender(blender);
builder.setBlender(blender_);
}
bool ref_is_unique() const override { return blender->unique(); }
bool ref_is_unique() const override { return blender_->unique(); }

private:
sk_sp<SkBlender> blender =
sk_sp<SkBlender> blender_ =
SkBlenders::Arithmetic(0.25, 0.25, 0.25, 0.25, true);
};

Expand Down
3 changes: 1 addition & 2 deletions flow/surface_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
const SubmitCallback& submit_callback,
std::unique_ptr<GLContextResult> context_result,
bool display_list_fallback)
: submitted_(false),
surface_(surface),
: surface_(surface),
framebuffer_info_(std::move(framebuffer_info)),
submit_callback_(submit_callback),
context_result_(std::move(context_result)) {
Expand Down
3 changes: 1 addition & 2 deletions fml/platform/posix/mapping_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ Mapping::Mapping() = default;
Mapping::~Mapping() = default;

FileMapping::FileMapping(const fml::UniqueFD& handle,
std::initializer_list<Protection> protection)
: size_(0), mapping_(nullptr) {
std::initializer_list<Protection> protection) {
if (!handle.is_valid()) {
return;
}
Expand Down
28 changes: 14 additions & 14 deletions fml/synchronization/semaphore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@ namespace fml {
class PlatformSemaphore {
public:
explicit PlatformSemaphore(uint32_t count)
: _sem(dispatch_semaphore_create(count)), _initial(count) {}
: sem_(dispatch_semaphore_create(count)), initial_(count) {}

~PlatformSemaphore() {
for (uint32_t i = 0; i < _initial; ++i) {
for (uint32_t i = 0; i < initial_; ++i) {
Signal();
}
if (_sem != nullptr) {
dispatch_release(reinterpret_cast<dispatch_object_t>(_sem));
_sem = nullptr;
if (sem_ != nullptr) {
dispatch_release(reinterpret_cast<dispatch_object_t>(sem_));
sem_ = nullptr;
}
}

bool IsValid() const { return _sem != nullptr; }
bool IsValid() const { return sem_ != nullptr; }

bool Wait() {
if (_sem == nullptr) {
if (sem_ == nullptr) {
return false;
}
return dispatch_semaphore_wait(_sem, DISPATCH_TIME_FOREVER) == 0;
return dispatch_semaphore_wait(sem_, DISPATCH_TIME_FOREVER) == 0;
}

bool TryWait() {
if (_sem == nullptr) {
if (sem_ == nullptr) {
return false;
}

return dispatch_semaphore_wait(_sem, DISPATCH_TIME_NOW) == 0;
return dispatch_semaphore_wait(sem_, DISPATCH_TIME_NOW) == 0;
}

void Signal() {
if (_sem != nullptr) {
dispatch_semaphore_signal(_sem);
if (sem_ != nullptr) {
dispatch_semaphore_signal(sem_);
}
}

private:
dispatch_semaphore_t _sem;
const uint32_t _initial;
dispatch_semaphore_t sem_;
const uint32_t initial_;

FML_DISALLOW_COPY_AND_ASSIGN(PlatformSemaphore);
};
Expand Down
30 changes: 0 additions & 30 deletions impeller/.clang-tidy

This file was deleted.

2 changes: 1 addition & 1 deletion impeller/archivist/archive_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace impeller {

struct ArchiveDatabase::Handle {
Handle(const std::string& filename) {
explicit Handle(const std::string& filename) {
if (::sqlite3_initialize() != SQLITE_OK) {
VALIDATION_LOG << "Could not initialize sqlite.";
return;
Expand Down
2 changes: 1 addition & 1 deletion impeller/archivist/archivist_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static int64_t LastSample = 0;

class Sample : public Archivable {
public:
Sample(uint64_t count = 42) : some_data_(count) {}
explicit Sample(uint64_t count = 42) : some_data_(count) {}

Sample(Sample&&) = default;

Expand Down
4 changes: 2 additions & 2 deletions impeller/base/base_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TEST(ThreadTest, CanCreateRWMutex) {
f.mtx.UnlockWriter();
// int b = f.a; <--- Static analysis error.
f.mtx.LockReader();
int b = f.a;
int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
FML_ALLOW_UNUSED_LOCAL(b);
f.mtx.UnlockReader();
}
Expand All @@ -61,7 +61,7 @@ TEST(ThreadTest, CanCreateRWMutexLock) {
// int b = f.a; <--- Static analysis error.
{
auto read_lock = ReaderLock(f.mtx);
int b = f.a;
int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
FML_ALLOW_UNUSED_LOCAL(b);
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/blobcat/blob_library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BlobLibrary::BlobLibrary(std::shared_ptr<fml::Mapping> mapping)
{
const size_t read_size = sizeof(Blob) * header.blob_count;
::memcpy(blobs.data(), mapping_->GetMapping() + offset, read_size);
offset += read_size;
offset += read_size; // NOLINT(clang-analyzer-deadcode.DeadStores)
}

// Read the blobs.
Expand Down
2 changes: 2 additions & 0 deletions impeller/compiler/reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// FLUTTER_NOLINT: https://github.com/flutter/flutter/issues/105732

#include "impeller/compiler/reflector.h"

#include <atomic>
Expand Down
3 changes: 2 additions & 1 deletion impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ TEST_P(EntityTest, CanCreateEntity) {

class TestPassDelegate final : public EntityPassDelegate {
public:
TestPassDelegate(std::optional<Rect> coverage) : coverage_(coverage) {}
explicit TestPassDelegate(std::optional<Rect> coverage)
: coverage_(coverage) {}

// |EntityPassDelegate|
~TestPassDelegate() override = default;
Expand Down
2 changes: 1 addition & 1 deletion impeller/geometry/path_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct CubicPathComponent {

struct ContourComponent {
Point destination;
bool is_closed;
bool is_closed = false;

ContourComponent() {}

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/texture_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct TexImage2DData {
GLenum type = GL_NONE;
std::shared_ptr<const fml::Mapping> data;

TexImage2DData(PixelFormat pixel_format) {
explicit TexImage2DData(PixelFormat pixel_format) {
switch (pixel_format) {
case PixelFormat::kA8UNormInt:
internal_format = GL_ALPHA;
Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/backend/metal/command_buffer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace impeller {
namespace {

// NOLINTBEGIN(readability-identifier-naming)

// TODO(dnfield): remove this declaration when we no longer need to build on
// machines with lower SDK versions than 11.0.
#if !defined(MAC_OS_VERSION_11_0) || \
Expand All @@ -21,6 +24,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
} API_AVAILABLE(macos(11.0), ios(14.0));
#endif

// NOLINTEND(readability-identifier-naming)

API_AVAILABLE(ios(14.0), macos(11.0))
NSString* MTLCommandEncoderErrorStateToString(
MTLCommandEncoderErrorState state) {
Expand All @@ -39,6 +44,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
return @"unknown";
}

// NOLINTBEGIN(readability-identifier-naming)

// TODO(dnfield): This can be removed when all bots have been sufficiently
// upgraded for MAC_OS_VERSION_12_0.
#if !defined(MAC_OS_VERSION_12_0) || \
Expand All @@ -47,6 +54,8 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
constexpr int MTLCommandBufferErrorStackOverflow = 12;
#endif

// NOLINTEND(readability-identifier-naming)

static NSString* MTLCommandBufferErrorToString(MTLCommandBufferError code) {
switch (code) {
case MTLCommandBufferErrorNone:
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ static bool ConfigureStencilAttachment(
/// absent.
///
struct PassBindingsCache {
PassBindingsCache(id<MTLRenderCommandEncoder> encoder) : encoder_(encoder) {}
explicit PassBindingsCache(id<MTLRenderCommandEncoder> encoder)
: encoder_(encoder) {}

PassBindingsCache(const PassBindingsCache&) = delete;

Expand Down
10 changes: 5 additions & 5 deletions lib/ui/painting/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ constexpr float kInvertColors[20] = {
// clang-format on

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

Paint::Paint(Dart_Handle paint_objects, Dart_Handle paint_data)
: paint_objects_(paint_objects), paint_data_(paint_data) {}
Expand Down Expand Up @@ -169,9 +169,9 @@ const SkPaint* Paint::paint(SkPaint& paint) const {
}

switch (uint_data[kMaskFilterIndex]) {
case Null:
case kNull:
break;
case Blur:
case kBlur:
SkBlurStyle blur_style =
static_cast<SkBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
double sigma = float_data[kMaskFilterSigmaIndex];
Expand Down Expand Up @@ -300,10 +300,10 @@ bool Paint::sync_to(DisplayListBuilder* builder,

if (flags.applies_mask_filter()) {
switch (uint_data[kMaskFilterIndex]) {
case Null:
case kNull:
builder->setMaskFilter(nullptr);
break;
case Blur:
case kBlur:
SkBlurStyle blur_style =
static_cast<SkBlurStyle>(uint_data[kMaskFilterBlurStyleIndex]);
double sigma = float_data[kMaskFilterSigmaIndex];
Expand Down
4 changes: 2 additions & 2 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ constexpr std::string_view kFileUriPrefix = "file://";

class DartErrorString {
public:
DartErrorString() : str_(nullptr) {}
DartErrorString() {}
~DartErrorString() {
if (str_) {
::free(str_);
Expand All @@ -54,7 +54,7 @@ class DartErrorString {

private:
FML_DISALLOW_COPY_AND_ASSIGN(DartErrorString);
char* str_;
char* str_ = nullptr;
};

} // anonymous namespace
Expand Down
4 changes: 2 additions & 2 deletions shell/common/skia_event_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class FlutterEventTracer : public SkEventTracer {

FlutterEventTracer(bool enabled,
const std::optional<std::vector<std::string>>& allowlist)
: enabled_(enabled ? kYes : kNo), shaders_category_flag_(nullptr) {
: enabled_(enabled ? kYes : kNo) {
if (allowlist.has_value()) {
allowlist_.emplace();
for (const std::string& category : *allowlist) {
Expand Down Expand Up @@ -311,7 +311,7 @@ class FlutterEventTracer : public SkEventTracer {
std::mutex flag_map_mutex_;
std::map<const char*, uint8_t> category_flag_map_;
std::map<const uint8_t*, const char*> reverse_flag_map_;
const uint8_t* shaders_category_flag_;
const uint8_t* shaders_category_flag_ = nullptr;
FML_DISALLOW_COPY_AND_ASSIGN(FlutterEventTracer);
};

Expand Down
2 changes: 1 addition & 1 deletion shell/gpu/gpu_surface_gl_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ GPUSurfaceGLSkia::GPUSurfaceGLSkia(sk_sp<GrDirectContext> gr_context,
bool render_to_surface)
: delegate_(delegate),
context_(gr_context),
context_owner_(false),

render_to_surface_(render_to_surface),
weak_factory_(this) {
auto context_switch = delegate_->GLContextMakeCurrent();
Expand Down
Loading

0 comments on commit 31afa38

Please sign in to comment.