Skip to content

Commit

Permalink
[lint] Enforce k prefix for global constants (flutter#33666)
Browse files Browse the repository at this point in the history
Enforces that all global constants are prefixed with a 'k' as per the
style guide and updates the codebase into conformance where necessary.

This does not change any public API.

Additional testing provided by the addition of the lint rule.

Ref: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#begin-global-constant-names-with-prefix-k
  • Loading branch information
cbracken authored May 28, 2022
1 parent 5427082 commit 1c09bf1
Show file tree
Hide file tree
Showing 35 changed files with 1,088 additions and 1,060 deletions.
6 changes: 6 additions & 0 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-*,\
readability-identifier-naming,\
-google-objc-global-variable-declaration,\
-google-objc-avoid-throwing-exception,\
-clang-analyzer-nullability.NullPassedToNonnull,\
Expand All @@ -15,6 +16,11 @@ clang-diagnostic-*,\
# to prevent new warnings being introduced.
# https://github.com/flutter/flutter/issues/93279
WarningsAsErrors: "clang-analyzer-*,\
readability-identifier-naming,\
clang-diagnostic-*,\
google-objc-*,\
google-explicit-constructor"

CheckOptions:
- key: readability-identifier-naming.GlobalConstantPrefix
value: k
675 changes: 341 additions & 334 deletions display_list/display_list_canvas_unittests.cc

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions display_list/display_list_color_filter_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace flutter {
namespace testing {

static const float matrix[20] = {
static const float kMatrix[20] = {
1, 2, 3, 4, 5, //
6, 7, 8, 9, 10, //
11, 12, 13, 14, 15, //
Expand Down Expand Up @@ -49,14 +49,14 @@ TEST(DisplayListColorFilter, FromSkiaBlendFilter) {
}

TEST(DisplayListColorFilter, FromSkiaMatrixFilter) {
sk_sp<SkColorFilter> sk_filter = SkColorFilters::Matrix(matrix);
sk_sp<SkColorFilter> sk_filter = SkColorFilters::Matrix(kMatrix);
std::shared_ptr<DlColorFilter> filter = DlColorFilter::From(sk_filter);
DlMatrixColorFilter dl_filter(matrix);
DlMatrixColorFilter dl_filter(kMatrix);
ASSERT_EQ(filter->type(), DlColorFilterType::kMatrix);
ASSERT_EQ(*filter->asMatrix(), dl_filter);
const DlMatrixColorFilter* matrix_filter = filter->asMatrix();
for (int i = 0; i < 20; i++) {
ASSERT_EQ((*matrix_filter)[i], matrix[i]);
ASSERT_EQ((*matrix_filter)[i], kMatrix[i]);
}

ASSERT_EQ(filter->asBlend(), nullptr);
Expand Down Expand Up @@ -137,24 +137,24 @@ TEST(DisplayListColorFilter, NopBlendShouldNotCrash) {
}

TEST(DisplayListColorFilter, MatrixConstructor) {
DlMatrixColorFilter filter(matrix);
DlMatrixColorFilter filter(kMatrix);
}

TEST(DisplayListColorFilter, MatrixShared) {
DlMatrixColorFilter filter(matrix);
DlMatrixColorFilter filter(kMatrix);
ASSERT_NE(filter.shared().get(), &filter);
ASSERT_EQ(*filter.shared(), filter);
}

TEST(DisplayListColorFilter, MatrixAsMatrix) {
DlMatrixColorFilter filter(matrix);
DlMatrixColorFilter filter(kMatrix);
ASSERT_NE(filter.asMatrix(), nullptr);
ASSERT_EQ(filter.asMatrix(), &filter);
}

TEST(DisplayListColorFilter, MatrixContents) {
float matrix_[20];
memcpy(matrix_, matrix, sizeof(matrix_));
memcpy(matrix_, kMatrix, sizeof(matrix_));
DlMatrixColorFilter filter(matrix_);

// Test deref operator []
Expand All @@ -176,14 +176,14 @@ TEST(DisplayListColorFilter, MatrixContents) {
}

TEST(DisplayListColorFilter, MatrixEquals) {
DlMatrixColorFilter filter1(matrix);
DlMatrixColorFilter filter2(matrix);
DlMatrixColorFilter filter1(kMatrix);
DlMatrixColorFilter filter2(kMatrix);
TestEquals(filter1, filter2);
}

TEST(DisplayListColorFilter, MatrixNotEquals) {
float matrix_[20];
memcpy(matrix_, matrix, sizeof(matrix_));
memcpy(matrix_, kMatrix, sizeof(matrix_));
DlMatrixColorFilter filter1(matrix_);
matrix_[4] += 101;
DlMatrixColorFilter filter2(matrix_);
Expand Down
Loading

0 comments on commit 1c09bf1

Please sign in to comment.