$ echo "private func upcomingRequests(count: Int) {\nguard count > 0 else {" | swiftlint lint --no-cache --use-stdin --enable-all-rules
Loading configuration from '.swiftlint.yml'
<nopath>:2:7: error: Empty Count Violation: Prefer checking `isEmpty` over comparing `count` to zero. (empty_count)
Done linting! Found 1 violation, 1 serious in 1 file.
.swiftlint.yml:opt_in_rules:
- empty_count
This code triggers error message:
private func upcomingRequests(count: Int) {
guard count > 0 else {
return
}
// ...
}

Duplicate of #827.
@marcelofabri I did search before opening this issue and I did found the one you referenced and that one didn't seem to be the same. That issue is about the fact that NSMapTable doesn't have isEmpty, so the SwiftLint should warn about switching to isEmpty for it. While the issue I'm experiencing is that I'm getting lint error if I have a variable called count and if I compare it with zero. Maybe consider updating that PR's description to mention both bugs. Hope it helps. And sorry again if it felt as duplicate.
@yas375, the underlying issue is the same. (Though it is admittedly not obvious until further into the comments, so do not worry about it.)
Basically, SwiftLint only has access to the name of the symbol count; it has no way of knowing what the symbol describes (i.e. Variable or property? Property on what type?). This makes both issues unfixable.
The only thing to do is follow @jpsim鈥檚 advice,
[B]e aware of the false鈥恜ositives, and don鈥檛 use opt鈥恑n rules unless you鈥檙e aware of their tradeoffs and find them acceptable.
Please know that we marked this as a duplicate to help organize the list of issues, not to label you as too lazy to search. ;) We are thankful for your report.
Thanks Jeremy 馃憤
FYI: I run into the same linter error when checking against NSDictionary.count. Switching to NSDictionary.allKeys.isEmpty workaround the problem.
Most helpful comment
@yas375, the underlying issue is the same. (Though it is admittedly not obvious until further into the comments, so do not worry about it.)
Basically, SwiftLint only has access to the name of the symbol
count; it has no way of knowing what the symbol describes (i.e. Variable or property? Property on what type?). This makes both issues unfixable.The only thing to do is follow @jpsim鈥檚 advice,
Please know that we marked this as a duplicate to help organize the list of issues, not to label you as too lazy to search. ;) We are thankful for your report.