Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit b3bd2ab

Browse files
Konoshenko Vladdkrutskikh
authored andcommitted
fix: added parameter constant check in avoid-border-all. (#723)
* fix: added parameter constant check in `avoid-border-all`. * fix: removed extra code
1 parent 6e5e136 commit b3bd2ab

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/avoid_border_all_rule.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import 'package:analyzer/dart/ast/ast.dart';
44
import 'package:analyzer/dart/ast/visitor.dart';
5+
import 'package:analyzer/dart/element/element.dart';
56

67
import '../../../../../utils/node_utils.dart';
78
import '../../../lint_utils.dart';

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/visitor.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_border_all/examples/example.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2652
class Border {

0 commit comments

Comments
 (0)