realm / realm/SwiftLint

Exclude Function Builder from `closure_body_length` rule

Open
#3,143 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

New Issue Checklist
Describe the bug

Function Builder (since Swift 5.1) is recognized as closure, and often triggers closure_body_length violation.

Function Builder is used in SwiftUI and usually over 20 lines (here is an official sample code), so it should be excluded.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Environment
  • SwiftLint version (run swiftlint version to be sure)?
    0.39.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Mint
  • Paste your configuration file:
# insert yaml contents here
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)?
  • 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.
// This triggers a violation: closure_body_length
NavigationView {
    Form {
        Picker(selection: $viewModel.form.argument1, label: Text("Argument1")) {
            ForEach(ViewForm.Argument1.allCases, id: \.self) {
                Text($0.name)
            }
        }
        DatePicker(selection: $viewModel.form.argument,
                    in: ...Date(),
                    displayedComponents: [.date, .hourAndMinute]) {
                    Text("Date")
        }
        Picker(selection: $viewModel.form.argument2, label: Text("Argument2")) {
            ForEach(ViewForm.Argument2.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Picker(selection: $viewModel.form.argument3, label: Text("Argument3")) {
            ForEach(ViewForm.Argument3.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Picker(selection: $viewModel.form.argument4, label: Text("Argument4")) {
            ForEach(ViewForm.Argument4.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Picker(selection: $viewModel.form.argument5, label: Text("Argument5")) {
            ForEach(ViewForm.Argument5.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Picker(selection: $viewModel.form.argument6, label: Text("Argument6")) {
            ForEach(ViewForm.Argument6.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Picker(selection: $viewModel.form.argument7, label: Text("Argument7")) {
            ForEach(ViewForm.Argument7.allCases, id: \.self) {
                Text($0.label)
            }
        }
        Toggle(isOn: $viewModel.form.argument8) {
            Text("Argument8")
        }
    }.navigationBarTitle("Title", displayMode: .inline)
        .navigationBarItems(
            trailing: Button(action: { self.submit() },
                                label: { Text("Submit") }))
}

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.

Research direction

Start with the closure_body_length rule and reproduce the reported violation using the SwiftUI sample with swiftlint lint --no-cache --enable-all-rules. Trace how Function Builder closures are identified; done means those closures no longer trigger this rule while ordinary closure body length checks remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.