Skip to content
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

Conversation

4akloon
Copy link
Contributor

@4akloon 4akloon commented Apr 19, 2024

No description provided.

@4akloon 4akloon linked an issue Apr 19, 2024 that may be closed by this pull request
Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool _hasIgnored(Declaration node, DartType returnType) {
bool _shouldIgnore(Declaration node, DartType returnType) {

or

Suggested change
bool _hasIgnored(Declaration node, DartType returnType) {
bool _isIgnored(Declaration node, DartType returnType) {

What do you think about this naming?

Comment on lines 113 to 127
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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.

Comment on lines 18 to 22
for (final item in (json['exclude'] as Iterable?) ?? []) {
if (item is Map && item['method_name'] is String) {
exclude.add(AvoidReturningWidgetsExclude.fromJson(item));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator

@solid-vovabeloded solid-vovabeloded left a 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.

@illia-romanenko illia-romanenko merged commit 9be59e9 into master Apr 22, 2024
2 checks passed
@illia-romanenko illia-romanenko deleted the 131-allow-disabling-avoid_returning_widgets-for-certain-methods branch April 22, 2024 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow disabling avoid_returning_widgets for certain methods
3 participants