-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: No warning if the number of elements in the spread operator using the if statement is more than two. #74
Changes from 9 commits
5d9187a
6c03299
acd7cfb
65967fb
c60580c
fabc4ed
caaa2fc
7b2f3c9
2d4da04
26f65e1
9583540
c7c2e78
c43c65d
fc8e51b
9fbba7f
16fdc57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,18 @@ class AvoidSingleChild extends DartLintRule { | |
if (childrenList.elements.length != 1) { | ||
return; | ||
} | ||
for (final element in childrenList.elements) { | ||
if (element is IfElement) { | ||
if (_hasSingleChild(element.thenElement)) { | ||
return; | ||
} | ||
|
||
if (element.elseElement != null && | ||
_hasSingleChild(element.elseElement!)) { | ||
return; | ||
} | ||
} | ||
} | ||
final element = childrenList.elements.first; | ||
if (element is ForElement) { | ||
return; | ||
|
@@ -85,4 +96,12 @@ class AvoidSingleChild extends DartLintRule { | |
} | ||
}); | ||
} | ||
|
||
bool _hasSingleChild(CollectionElement element) { | ||
if (element is SpreadElement && element.expression is ListLiteral) { | ||
final spreadElement = element.expression as ListLiteral; | ||
return spreadElement.elements.length != 1; | ||
boywithdv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, at a quick glance, it seems that the function name does not match the actual situation. The function name _hasSingleChild seems to return true in the case of a single element, so the function name should be changed to _hasMultipleChild to make it clear that it returns true when there are multiple child elements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Names are important. Make sure you name it with proper thought and self-review to make sure it is correct. |
||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the subject of this Issue, but this pattern has one element each, so lint is the expected value.