Skip to content

empty_count rule triggers on local symbols #5326

@pronebird

Description

@pronebird

New Issue Checklist

Describe the bug

empty_count violation is triggered on extension over IteratorProtocol

Sample code:

extension IteratorProtocol {
    mutating func skip(_ count: Int) {
        guard count > 0 else { return } // ERROR: Empty Count Violation: Prefer checking `isEmpty` over comparing `count` to zero (empty_count)

        for _ in 0..<count {
            _ = next()
        }
    }
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint

Environment

  • SwiftLint version (run swiftlint version to be sure)?
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
  • Paste your configuration file:
# insert yaml contents here
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)?
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions