Skip to content

[0.55.1] False positive on unused_element where element and index are used separately in subsequent blocks #5600

Description

@michaeleustace

New Issue Checklist

Describe the bug

The rule should not trigger when the enumerated index and element are used in separate subsequent blocks

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.55.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Cocoapods
  • Paste your configuration file:
# insert yaml contents here
  • Are you using nested configurations? No
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)? 15.3
  • 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.
protocol Rule {
  func isValid() -> Bool
}

let rules: [Rule] = [rule1, rule2]
let messages = ["msg1", "msg2"]

// This triggers a violation:
rules.enumerated()
    .first { $0.element.isValid() == false }
    .flatMap { messages[$0.offset] }

Metadata

Metadata

Assignees

Labels

bugUnexpected and reproducible misbehavior.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions