[0.55.1] False positive on `unused_element` where element and index are used separately in subsequent blocks
Open
@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
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
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 versionto 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 useswiftlint 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.