CodeNarc / CodeNarc

CodeNarc source
Apache License 2.0
304 stars 132 forks source link

False-positive in UnnecessaryGetter for isEmpty() on maps #459

Open Vampire opened 4 years ago

Vampire commented 4 years ago

CodeNarc 1.4 complains about an isEmpty() call on a map and suggests to use empty instead. But that cannot work, as that gets the value for the key 'empty' and does not query the isEmpty() method.

Work-around is to use the ignoreMethodNames property.

chrismair commented 4 years ago

Another workaround is to set checkIsMethods to false on that rule. But I acknowledge that still is not great.

The challenge is that this is a simple rule that does not know the types of the objects on which the methods are being called. I think we'd have to switch it to an enhanced (or hybrid) rule to get the information needed to know whether it was acting upon a Map.