Open michaeleustace opened 1 month ago
So unfortunately we do only cover the first block - I couldn't find a good way to keep track of the variables through subsequent blocks - see #5498 for discussion. There were no examples of subsequent block usage in the open source projects that SwiftLint gets tested against, so we hoped that this would not affect many people.
If that particular idiom is common in your codebase, you could disable the rule locally, or in your configuration.
While the advice the rule is providing might be misleading in this case, it still highlights an issue in the code. Because it could indeed be rewritten entirely without the .enumerated()
as:
rules.firstIndex { !$0.isValid() }.flatMap { messages[$0] }
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
to be sure)? 0.55.1xcodebuild -version
)? 15.3echo "[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
.