Skip to content

Commit

Permalink
fix: Fixed the potential cast error in avoid_single_child (#41)
Browse files Browse the repository at this point in the history
* fix: Fixed the potential cast error in `avoid_single_child`

* chore: Add ListView test with non ListLiteral
  • Loading branch information
naipaka authored Jul 31, 2024
1 parent d85a1c9 commit 5c0c8b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/altive_lints/lib/src/lints/avoid_single_child.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class AvoidSingleChild extends DartLintRule {
);

final childrenList = childrenArg is NamedExpression
? childrenArg.expression as ListLiteral
? childrenArg.expression is ListLiteral
? childrenArg.expression as ListLiteral
: null
: null;

if (childrenList != null && childrenList.elements.length == 1) {
Expand Down
6 changes: 6 additions & 0 deletions packages/altive_lints/lint_test/lints/avoid_single_child.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class MyWidget extends StatelessWidget {
Text('World'),
],
),
ListView(
children: List.generate(
10,
(index) => Text('Hello $index'),
),
),
],
);
}
Expand Down

0 comments on commit 5c0c8b5

Please sign in to comment.