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

fix: No warning if the number of elements in the spread operator using the if statement is more than two. #74

Merged
merged 16 commits into from
Nov 13, 2024

Conversation

boywithdv
Copy link
Contributor

@boywithdv boywithdv commented Nov 5, 2024

🔗 Related Issues

🙌 What's Done

  • Do not display a warning if the if statement written to a child element has two or more elements with the spread operator

✍️ What's Not Done

🖼️ Image Differences

not display warnings warning
スクリーンショット 2024-11-05 16 56 34 スクリーンショット 2024-11-05 16 56 47

Both if and else will similarly display a warning message if the number of elements is one.

🤼 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 ///).

@boywithdv boywithdv marked this pull request as ready for review November 5, 2024 08:17
@boywithdv boywithdv requested a review from a team as a code owner November 5, 2024 08:17
@boywithdv boywithdv requested review from riscait and removed request for a team November 5, 2024 08:17
Copy link
Member

@riscait riscait left a comment

Choose a reason for hiding this comment

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

badge
@boywithdv

The issues in the corresponding Issue are as follows:

Even though it contains multiple elements, the avoid_single_child warning appears when using an if condition.

Looking at the PR it looks like another revision, what is the intent?

@boywithdv boywithdv changed the title fix: if statement has multiple elements fix: Do not display warnings if there are multiple elements in an if statement Nov 12, 2024
@boywithdv
Copy link
Contributor Author

Looking at the PR it looks like another revision, what is the intent?

The title and summary description of the PR did not seem to match the revisions.

We have just corrected the title and summary description.

The PR has been modified to display a warning when the number of elements in the if statement described in the child element is two or more, and not when the number is one.

Comment on lines 109 to 114
? [
const Text('Hello World'),
]
: [
const Text('Hello'),
const Text('World'),
],
Copy link
Member

Choose a reason for hiding this comment

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

badge
This is not the subject of this Issue, but this pattern has one element each, so lint is the expected value.

Comment on lines 100 to 104
bool _hasSingleChild(CollectionElement element) {
if (element is SpreadElement && element.expression is ListLiteral) {
final spreadElement = element.expression as ListLiteral;
return spreadElement.elements.length != 1;
}
Copy link
Member

@riscait riscait Nov 12, 2024

Choose a reason for hiding this comment

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

badge
@boywithdv
What does the name _hasSingleChild mean when length != 1, what does the name _hasSingleChild mean?It seems intuitive if length == 1...

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

@boywithdv boywithdv changed the title fix: Do not display warnings if there are multiple elements in an if statement fix: No warning if the number of elements in the spread operator using the if statement is more than two. Nov 12, 2024
@boywithdv boywithdv requested a review from riscait November 13, 2024 00:44
@boywithdv boywithdv requested a review from riscait November 13, 2024 02:45
Copy link
Member

@riscait riscait left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test!
I commented on some of them, so please check them and merge them if they are OK.

Comment on lines 100 to 104
bool _hasSingleChild(CollectionElement element) {
if (element is SpreadElement && element.expression is ListLiteral) {
final spreadElement = element.expression as ListLiteral;
return spreadElement.elements.length != 1;
}
Copy link
Member

Choose a reason for hiding this comment

The 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.

@boywithdv boywithdv merged commit ad65c00 into main Nov 13, 2024
1 check passed
@boywithdv boywithdv deleted the 68-when-using-an-if-condition branch November 13, 2024 06:13
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.

Even though it contains multiple elements, the avoid_single_child warning appears when using an if condition.
2 participants