Skip to content

force_unwrapping is not fired for trailing closures syntax #2915

@Igor-Palaguta

Description

@Igor-Palaguta

New Issue Checklist

Describe the bug

force_unwrapping is not fired for trailing closures syntax

let value = [1, 3, 5, 6].first { $0.isMultiple(of: 2) }!

Same case but with parentheses around works fine

let value = [1, 3, 5, 6].first({ $0.isMultiple(of: 2) })!
Complete output when running SwiftLint, including the stack trace and command used

E.g. for this case superfluous_disable_command rule is fired

let value = [1, 3, 5, 6].first { $0.isMultiple(of: 2) }! // swiftlint:disable:this force_unwrapping
$ swiftlint lint

Superfluous Disable Command Violation: SwiftLint rule 'force_unwrapping' did not trigger a violation in the disabled region. Please remove the disable command. (superfluous_disable_command)

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.35.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    CocoaPods
  • Paste your configuration file:
opt_in_rules:
  - force_unwrapping
  • Are you using nested configurations?
    no
  • Which Xcode version are you using (check xcode-select -p)?
    Version 11.1 (11A1027)
  • Do you have a sample that shows the issue? Run echo "let value = [1, 3, 5, 6].first { $0.isMultiple(of: 2) }!" | 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.
// This triggers a violation:
let value = [1, 3, 5, 6].first { $0.isMultiple(of: 2) }!

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