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

ignoring prefer_is_not_empty doesn't work #57817

Closed
zoechi opened this issue Oct 29, 2018 · 4 comments
Closed

ignoring prefer_is_not_empty doesn't work #57817

zoechi opened this issue Oct 29, 2018 · 4 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@zoechi
Copy link
Contributor

zoechi commented Oct 29, 2018

I run into https://github.com/dart-lang/sdk/issues/34798 and tried to ignore it
but // ignore: prefer_is_not_empty didn't work

image

it turned out I could ignore it with prefer_is_empty, but that seems wrong to me.

image

@pq
Copy link
Member

pq commented Oct 29, 2018

Verified here too.

@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Oct 29, 2018
@srawlins
Copy link
Member

Hmm, what to do about this one, the lint text seems pretty clear:

prefer_is_empty:

DON'T use length to see if a collection is empty.
...
Instead, there are faster and more readable getters: isEmpty and isNotEmpty. Use the one that doesn't require you to negate the result.

prefer_is_not_empty:

PREFER x.isNotEmpty to !x.isEmpty for Iterable and Map instances.

I agree, it's not intuitive what each rule does. But the rule names are just short, unique identifiers. What to do.

@zoechi
Copy link
Contributor Author

zoechi commented Oct 30, 2018

@srawlins

I agree, it's not intuitive what each rule does.

I don't see a problem here.

The actual issue is that both prefer_is_empty and prefer_is_not_empty are silenced by the same ignore

// ignore: prefer_is_empty

while this should only apply to the former and the later should be silenced by

// ignore: prefer_is_not_empty 

but isn't.

To me this looks like a copy-paste error.

@pq
Copy link
Member

pq commented Apr 29, 2019

The actual issue is that both prefer_is_empty and prefer_is_not_empty are silenced by the same ignore

Looking again, I think they aren't actually but the messages are confusing.

In your case, you are seeing a flagging of prefer_is_empty, it's just that it covers both the isEmpty and isNotEmpty case for collections.

The prefer_is_not_empty lint flags things like !sources.isEmpty.

In the end, I think we could probably have picked better names?

Feel free to re-open if you think I missed something or you have ideas for how to make this actionable...

@pq pq closed this as completed Apr 29, 2019
@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants