realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.7k stars 2.23k forks source link

Using NSSet.count > 0 causes empty_count violation #848

Closed chris-wickens closed 8 years ago

chris-wickens commented 8 years ago

Unfortunately, neither NSSet or NSOrderedSet have an isEmpty property.

VFUC commented 8 years ago

I don't think SourceKitten has access to specific type information of a variable, AFAIK you need to actually compile code for that. If anything, I could imagine checking if SourceKitten's "complete" command suggests "isEmpty" on the variable, but I'm unsure as to if and how this is accessible for us in the SwiftLint source code.

soleares commented 8 years ago

+1

nhgrif commented 8 years ago

I've seen this on my own types where I've added a count property but not an isEmpty property. In my use-cases, I opted to simply added the isEmpty property to my types, but it seems ideal for SwiftLint to first verify whether or not isEmpty is a thing for that variable.

jpsim commented 8 years ago

Please see https://github.com/realm/SwiftLint/issues/827#issuecomment-263009822.