-
Notifications
You must be signed in to change notification settings - Fork 17
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
add exclude params support to avoid_returning_widgets rule #162
add exclude params support to avoid_returning_widgets rule #162
Conversation
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.
Well done, @4akloon! I've added a few suggestions here - please, take a look.
reporter.reportErrorForNode(code, node); | ||
} | ||
}); | ||
} | ||
|
||
bool _hasIgnored(Declaration node, DartType returnType) { |
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.
bool _hasIgnored(Declaration node, DartType returnType) { | |
bool _shouldIgnore(Declaration node, DartType returnType) { |
or
bool _hasIgnored(Declaration node, DartType returnType) { | |
bool _isIgnored(Declaration node, DartType returnType) { |
What do you think about this naming?
final excludedItem = config.parameters.exclude | ||
.firstWhereOrNull((e) => e.methodName == methodName); | ||
|
||
if (excludedItem | ||
case AvoidReturningWidgetsExclude( | ||
:final String? className, | ||
)) { | ||
if (className == null) { | ||
return true; | ||
} else { | ||
return returnType.hasIgnoredType(ignoredTypes: {className}); | ||
} | ||
} | ||
|
||
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.
final excludedItem = config.parameters.exclude | |
.firstWhereOrNull((e) => e.methodName == methodName); | |
if (excludedItem | |
case AvoidReturningWidgetsExclude( | |
:final String? className, | |
)) { | |
if (className == null) { | |
return true; | |
} else { | |
return returnType.hasIgnoredType(ignoredTypes: {className}); | |
} | |
} | |
return false; | |
final excludedItem = config.parameters.exclude | |
.firstWhereOrNull((e) => e.methodName == methodName); | |
if (excludedItem == null) return false; | |
final className = excludedItem.className; | |
if (className == null) return false; | |
return returnType.hasIgnoredType(ignoredTypes: {className}); |
I would refactor this part into something like this to make it a bit more readable. What do you think?
- avoid_returning_widgets: | ||
exclude: | ||
- method_name: excludeWidget | ||
class_name: SizedBox |
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.
The class_name
means class in which we are ignoring returning widgets from the method_name
, but not the return type of the ignored method_name
.
for (final item in (json['exclude'] as Iterable?) ?? []) { | ||
if (item is Map && item['method_name'] is String) { | ||
exclude.add(AvoidReturningWidgetsExclude.fromJson(item)); | ||
} | ||
} |
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.
for (final item in (json['exclude'] as Iterable?) ?? []) { | |
if (item is Map && item['method_name'] is String) { | |
exclude.add(AvoidReturningWidgetsExclude.fromJson(item)); | |
} | |
} | |
final excludeList = json['exclude'] as Iterable? ?? []; | |
for (final item in excludeList) { | |
if (item is Map) { | |
exclude.add(AvoidReturningWidgetsExclude.fromJson(item)); | |
} | |
} |
I don't think we need to check the item structure here since it is not a responsibility of this class.
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.
LGTM, thanks! Feel free to update changelog and merge it.
No description provided.