-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 empty_count false-positives #827
Comments
A workaround would be using : mapTable.objectEnumerator()!.allObjects.isEmpty |
How about extension NSMapTable {
var isEmpty:Bool { return count == 0 }
} |
Of course, but as an other workaround. Because of Swiftlint is an integration tool, you could expect to not being required to add some extra code. |
Note that this rule is opt-in because of the false positives. You can always disable it. There's no easy way to know a variable type without compiling the code (as far as I know) and SwiftLint does not compile any code currently. |
@marcelofabri is exactly right, the reason why the Until then, be aware of the false-positives, and don't use opt-in rules unless you're aware of their tradeoffs and find them acceptable. |
Well i think we make the empty_rule useless just to support an edge case in extensions. |
From issue #1080, the rule is triggered on (This would miss cases in subclasses that implement count, but this seems a much smaller corner case, and the ability to use |
This is intentional, as extensions to collection types implementing |
@jpsim do you have any data on the number of extension code using isEmpty vs non extension code using it? If the numbers are too different then it would be good to reconsider this "intentional" behaviour. |
Matching only |
Given that However, I'd be happy to accept a PR that made the rule configurable to only trigger when used as a property lookup with a period ( |
@jpsim Well, I'd say the covered surface area suffers when people turn the rule off due to false positives. A more focused rule is a more used rule. |
Please see my last comment about being open to support the mode you want if a PR is submitted. |
Sorry about the duplicate issue #1241 Needless to say I think this should be fixed. Obviously multiple developers are running into this issue. Being configurable so that it only warns on .count would be a viable workaround that I would certainly enable. |
@phoney Feel free to send a PR |
Hi, my issue was a duplicate of this one, so I just created this PR to fix it: #1608 |
Still no fix for this? A working regex should trigger for |
So is the position of the maintainers that one shouldn't use "count" as a variable name? |
The position of this maintainer is that the false positives do prove useful for catching more violations of this, and that we would ideally solve this by making the empty count rule configurable to avoid these false positives by default while being able to opt in to behavior that can catch more violations, at the expense of false positives. |
I ran into this problem using PHFetchResult for Photo Kit I was able to get the extension solution to work with a couple of needed changes
extension PHFetchResult {
} |
This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions! |
When using a NSMapTable variable and test number of elements with count statement, Empty Count Violation is thrown whereas it should not. Indeed NSMapTable hasn't any isEmpty property.
XCode 7.3.1, iOS 9.3, swiftlint 0.11.1
The text was updated successfully, but these errors were encountered: