diff --git a/CHANGELOG.md b/CHANGELOG.md index fe602af1b6..979df9fdee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +* fix: [`avoid-border-all`](https://dartcodemetrics.dev/docs/rules/flutter/avoid-border-all) is triggered even when it is not a const. + ## 4.15.1 * chore: restrict `analyzer` version to `>=2.4.0 <4.1.0`. diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/visitor.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/visitor.dart index 5c10dd054b..c96358afab 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/visitor.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/visitor.dart @@ -21,7 +21,9 @@ class _Visitor extends RecursiveAstVisitor { final arg = (argument as NamedExpression).expression; if (arg is Literal) { continue; - } else if (arg is MethodInvocation || arg is ConditionalExpression) { + } else if (arg is MethodInvocation || + arg is ConditionalExpression || + arg is PropertyAccess) { isAllConst = false; } else if (arg is SimpleIdentifier) { final element = arg.staticElement; diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples/example.dart index 838a450e53..9cb1db7723 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples/example.dart @@ -1,5 +1,5 @@ class MyWidget extends StatelessWidget { - Widget build(BuildContext _) => Column(children: [ + Widget build(BuildContext context) => Column(children: [ const Container(border: Border.fromBorderSide(BorderSide())), Container(border: Border.all()), // LINT Container( @@ -27,6 +27,11 @@ class MyWidget extends StatelessWidget { style: BorderStyle.none, ), ), + Container( + border: Border.all( + color: Theme.of(context).color, + ), + ), Container( border: Border.all( color: const Color(0), @@ -106,3 +111,9 @@ class Widget { } class BuildContext {} + +class Theme { + const color = Color(0); + + static Color of(BuildContext context) => color; +}