From f1a1f5f5cf2a01bac1c032730ff1c44be1857d12 Mon Sep 17 00:00:00 2001 From: tsukuda jukiya <67436434+boywithdv@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:40:38 +0900 Subject: [PATCH] fix: Exclude Colors.transparent from the target of avoid_hardcoded_color (#63) * fix: Colors.transparent from the target of avoid_hardcoded_color * fix:revison --- .../altive_lints/lib/src/lints/avoid_hardcoded_color.dart | 4 ++++ .../altive_lints/lint_test/lints/avoid_hardcoded_color.dart | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/altive_lints/lib/src/lints/avoid_hardcoded_color.dart b/packages/altive_lints/lib/src/lints/avoid_hardcoded_color.dart index 2f00db0..f904911 100644 --- a/packages/altive_lints/lib/src/lints/avoid_hardcoded_color.dart +++ b/packages/altive_lints/lib/src/lints/avoid_hardcoded_color.dart @@ -59,6 +59,10 @@ class AvoidHardcodedColor extends DartLintRule { final element = node.staticElement; if (element is PropertyAccessorElement) { final returnType = element.returnType; + // Allow Colors.transparent as a valid hardcoded color, as it serves. + if (node.identifier.name == 'transparent') { + return; + } if (_isColorType(returnType)) { reporter.atNode(node, _code); } diff --git a/packages/altive_lints/lint_test/lints/avoid_hardcoded_color.dart b/packages/altive_lints/lint_test/lints/avoid_hardcoded_color.dart index 53b1a00..fb27ea4 100644 --- a/packages/altive_lints/lint_test/lints/avoid_hardcoded_color.dart +++ b/packages/altive_lints/lint_test/lints/avoid_hardcoded_color.dart @@ -14,6 +14,8 @@ class MyWidget extends StatelessWidget { // expect_lint: avoid_hardcoded_color const ColoredBox(color: Colors.green), ColoredBox(color: Theme.of(context).colorScheme.primary), + + const ColoredBox(color: Colors.transparent), ], ); }