realm / realm/SwiftLint

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

Open
#5,600 2 comments 0 reactions 1 assignee View on GitHub

@mildm8nnered is already working on this.

Since May 23, 2024.

bug
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

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] }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.