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

feat: Improve prefer_sliver_prefix to prefer_to_include_sliver_in_name #58

Merged

Conversation

k-nkmr
Copy link
Contributor

@k-nkmr k-nkmr commented Sep 20, 2024

🔗 Related Issues

🙌 What's Done

  • Improve prefer_sliver_prefix to prefer_to_include_sliver_in_name
  • update test

✍️ What's Not Done

  • none

🖼️ Image Differences

Before After
image image

🤼 Desired Review Method

  • Correction Commit
  • Pair programming

Note

It is possible that a reviewer's will may cause a method to be implemented that is not selected.

📝 Additional Notes

Pre-launch Checklist

  • I have reviewed my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • I updated/added relevant documentation (doc comments with ///).

@k-nkmr k-nkmr marked this pull request as ready for review September 20, 2024 04:23
@k-nkmr k-nkmr requested a review from a team as a code owner September 20, 2024 04:23
@k-nkmr k-nkmr requested review from naipaka and removed request for a team September 20, 2024 04:23
Copy link
Contributor

@naipaka naipaka left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you for the changes to the README.md as well!🚀

Comment on lines 76 to 90

final className = node.name.lexeme;
final constructorNames = node.members
.whereType<ConstructorDeclaration>()
.map((constructor) => constructor.name?.lexeme)
.whereType<String>();
final hasSliverInClassOrConstructor = className.contains('Sliver') ||
constructorNames.any(
(constructorName) =>
constructorName.toLowerCase().contains('sliver'),
);

if (returnsSliverWidget && !hasSliverInClassOrConstructor) {
reporter.atNode(node, _code);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

badge

The evaluation of returnSliverWidget could be done earlier, allowing for an early return if necessary!

Similarly, the checks for className and constructorNames could also be implemented as early returns, potentially reducing unnecessary member access.

Suggested change
final className = node.name.lexeme;
final constructorNames = node.members
.whereType<ConstructorDeclaration>()
.map((constructor) => constructor.name?.lexeme)
.whereType<String>();
final hasSliverInClassOrConstructor = className.contains('Sliver') ||
constructorNames.any(
(constructorName) =>
constructorName.toLowerCase().contains('sliver'),
);
if (returnsSliverWidget && !hasSliverInClassOrConstructor) {
reporter.atNode(node, _code);
}
if (!returnsSliverWidget) {
return;
}
final className = node.name.lexeme;
if (className.contains('Sliver')) {
return;
}
final constructorNames = node.members
.whereType<ConstructorDeclaration>()
.map((constructor) => constructor.name?.lexeme)
.nonNulls;
final hasSliverConstructor = constructorNames.any(
(name) => name.toLowerCase().contains('sliver'),
);
if (hasSliverConstructor) {
return;
}
reporter.atNode(node, _code);

Copy link
Contributor

Choose a reason for hiding this comment

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

badge
I'd like you to write a test for the positive case as well, demonstrating that no warning is issued when the class name contains 'Sliver' and the named constructor includes 'sliver'. This would show the correct behavior in a valid scenario.

@k-nkmr k-nkmr merged commit 9e9ceb5 into main Sep 24, 2024
1 check passed
@k-nkmr k-nkmr deleted the 36-prefer-sliver-prefix-to-prefer-to-include-sliver-in-name branch September 24, 2024 06:47
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.

Improve prefer_sliver_prefix to prefer_to_include_sliver_in_name
2 participants