This repository was archived by the owner on Jul 16, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all
test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 33## Unreleased
44
55* feat: add static code diagnostic ` avoid-collection-methods-with-unrelated-types `
6+ * fix: added parameter constant check in ` avoid-border-all ` .
67
78## 4.11.0
89
Original file line number Diff line number Diff line change 22
33import 'package:analyzer/dart/ast/ast.dart' ;
44import 'package:analyzer/dart/ast/visitor.dart' ;
5+ import 'package:analyzer/dart/element/element.dart' ;
56
67import '../../../../../utils/node_utils.dart' ;
78import '../../../lint_utils.dart' ;
Original file line number Diff line number Diff line change @@ -15,7 +15,25 @@ class _Visitor extends RecursiveAstVisitor<void> {
1515 if (expression.staticType? .getDisplayString (withNullability: true ) ==
1616 _className &&
1717 expression.constructorName.name? .name == _borderRadiusConstructorName) {
18- _expressions.add (expression);
18+ var isAllConst = true ;
19+
20+ for (final argument in expression.argumentList.arguments) {
21+ final arg = (argument as NamedExpression ).expression;
22+ if (arg is Literal ) {
23+ continue ;
24+ } else if (arg is MethodInvocation || arg is ConditionalExpression ) {
25+ isAllConst = false ;
26+ } else if (arg is SimpleIdentifier ) {
27+ final element = arg.staticElement;
28+ if (element is PropertyAccessorElement && ! element.variable.isConst) {
29+ isAllConst = false ;
30+ }
31+ }
32+ }
33+
34+ if (isAllConst) {
35+ _expressions.add (expression);
36+ }
1937 }
2038 }
2139}
Original file line number Diff line number Diff line change @@ -20,7 +20,33 @@ class MyWidget extends StatelessWidget {
2020 style: BorderStyle .none,
2121 ),
2222 ), // LINT
23+ Container (
24+ border: Border .all (
25+ color: const Color (0 ),
26+ width: foo (),
27+ style: BorderStyle .none,
28+ ),
29+ ),
30+ Container (
31+ border: Border .all (
32+ color: const Color (0 ),
33+ width: someBool ? 1 : 0 ,
34+ style: BorderStyle .none,
35+ ),
36+ ),
37+ Container (
38+ border: Border .all (
39+ color: const Color (0 ),
40+ width: someInt,
41+ style: BorderStyle .none,
42+ ),
43+ ),
2344 ]);
45+
46+ var someBool = false ;
47+ var someInt = 5 ;
48+
49+ double foo () => 20.0 ;
2450}
2551
2652class Border {
You can’t perform that action at this time.
0 commit comments