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

Commit c6d909a

Browse files
authored
fix: prefer-extracting-callbacks in nested widgets (#639)
1 parent 4f81ffa commit c6d909a

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
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: support excludes for a separate anti-pattern.
6+
* fix: prefer-extracting-callbacks in nested widgets
67

78
## 4.9.0
89

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class _InstanceCreationVisitor extends RecursiveAstVisitor<void> {
3434

3535
@override
3636
void visitInstanceCreationExpression(InstanceCreationExpression node) {
37+
super.visitInstanceCreationExpression(node);
38+
3739
for (final argument in node.argumentList.arguments) {
3840
final expression =
3941
argument is NamedExpression ? argument.expression : argument;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ class MyWidgetWithEmptyCallbacks extends StatelessWidget {
8888
}
8989
}
9090

91+
class MyWidgetWithNestedWidget extends StatelessWidget {
92+
@override
93+
Widget build(BuildContext context) {
94+
return Container(
95+
child: TextButton(
96+
// LINT
97+
onPressed: () {
98+
return null;
99+
},
100+
child: Container(),
101+
),
102+
);
103+
}
104+
}
105+
91106
class Widget {}
92107

93108
class StatelessWidget extends Widget {}

test/src/analyzers/lint_analyzer/rules/rules_list/prefer_extracting_callbacks/prefer_extracting_callbacks_rule_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ void main() {
2525

2626
RuleTestHelper.verifyIssues(
2727
issues: issues,
28-
startLines: [11, 55],
29-
startColumns: [7, 7],
28+
startLines: [11, 55, 97],
29+
startColumns: [7, 7, 9],
3030
locationTexts: [
3131
'onPressed: () {\n'
3232
' return null;\n'
3333
' }',
3434
'onPressed: () {\n'
3535
' return null;\n'
3636
' }',
37+
'onPressed: () {\n'
38+
' return null;\n'
39+
' }',
3740
],
3841
messages: [
3942
'Prefer extracting the callback to a separate widget method.',
4043
'Prefer extracting the callback to a separate widget method.',
44+
'Prefer extracting the callback to a separate widget method.',
4145
],
4246
);
4347
});

0 commit comments

Comments
 (0)