Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trailing_closure conflicts with multiple_closures_with_trailing_closure #5988

Open
2 tasks done
hongping-quora opened this issue Feb 3, 2025 · 0 comments
Open
2 tasks done

Comments

@hongping-quora
Copy link

hongping-quora commented Feb 3, 2025

New Issue Checklist

Bug Description

func myFunc1(
    a1 _: Int,
    a2 _: (Int) -> Void,
    a3 _: String,
    a4 _: (String) -> Void
) {}

// This function triggers a violation:
// warning: Trailing Closure Violation: Trailing closure syntax should be used whenever possible (trailing_closure)
func myFunc2() {
    myFunc1(
        a1: 1,
        a2: { _ in },
        a3: "2",
        a4: { _ in }
    )
}

// If I try using trailing closure, I get:
// Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than
// one closure argument (multiple_closures_with_trailing_closure)
func myFunc3() {
    myFunc1(
        a1: 1,
        a2: { _ in },
        a3: "2"
    ) { _ in }
}

Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.

Removed some file paths to shorten the output lines

$ swiftlint 
Linting Swift files in current working directory
Linting 'Closure.swift' (1/3)
Linting 'TrailingClosureApp.swift' (2/3)
Linting 'ContentView.swift' (3/3)
Closure.swift:27:7: warning: Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument (multiple_closures_with_trailing_closure)
Closure.swift:15:13: warning: Trailing Closure Violation: Trailing closure syntax should be used whenever possible (trailing_closure)
Done linting! Found 2 violations, 0 serious in 3 files.

Environment

  • SwiftLint version (run swiftlint version to be sure)
    • 0.58.2
  • Xcode version (run xcodebuild -version to be sure)
    • Xcode 16.2, Build version 16C5032a
  • Installation method used (Homebrew, CocoaPods, building from source, etc)
    • brew install swiftlint
  • Configuration file:
opt_in_rules:
  - trailing_closure

Are you using nested configurations? If so, paste their
relative paths and respective contents.
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant