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

Unexpected Multiline Arguments Violation in function call with completion block #3399

Closed
2 tasks done
DamascenoRafael opened this issue Oct 30, 2020 · 6 comments
Closed
2 tasks done
Labels
bug Unexpected and reproducible misbehavior.

Comments

@DamascenoRafael
Copy link

New Issue Checklist

Describe the bug

It seems that in a specific case of a function call with a completion block where the function's arguments are one per line, a violation is triggered if the final parentheses of the arguments are on the same line.

// This triggers a violation:
// Multiline Arguments Violation: Arguments should be either on the same line, or one per line. (multiline_arguments)
UIView.animate(withDuration: 1,
               delay: 0) {
    // sample
    print("a")
} completion: { _ in
    // sample
    print("b")
}

Sorry if I'm missing something. I looked at the rules for Multiline Arguments and looked for issues but it seems to me that my example that triggers the violation should not occur.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths 
...
/path/file.swift:527:76: warning: Multiline Arguments Violation: Arguments should be either on the same line, or one per line. (multiline_arguments)
Done linting! Found 2 violations, 0 serious in 29 files.

Environment

  • SwiftLint version 0.40.3
  • Installation method used: Homebrew
  • Paste your configuration file:
opt_in_rules:
- attributes
- closure_end_indentation
- closure_spacing
- contains_over_first_not_nil
- empty_count
- empty_string
- explicit_init
- fallthrough
- file_header
- first_where
- force_unwrapping
- implicit_return
- implicitly_unwrapped_optional
- joined_default_parameter
- missing_docs
- multiline_arguments
- multiline_function_chains
- multiline_parameters
- operator_usage_whitespace
- overridden_super_call
- redundant_nil_coalescing
- redundant_type_annotation
- sorted_first_last
- switch_case_on_newline
- toggle_bool
- unneeded_parentheses_in_closure_argument
- vertical_whitespace_closing_braces
- yoda_condition

disabled_rules:
- trailing_whitespace

attributes:
  always_on_same_line:
  - '@objc'
  - '@IBAction'

implicit_return:
  included:
  - closure

line_length:
  error: 300
  ignores_urls: true

multiline_arguments:
  only_enforce_after_first_closure_on_first_line: true

custom_rules:
  comments_space:
    name: "Space After Comment"
    regex: '(^ *//\w+)'
    message: "There should be a space after //"
    severity: warning
  double_space:
    include: "*.swift"
    name: "Double space"
    regex: '([a-z,A-Z] \s+)'
    message: "Don't use double space between keywords"
    match_kinds: keyword
    severity: warning
  empty_commented_line:
    name: "Empty Commented Out Line"
    regex: '(\t+| +)//\n'
    message: "Remove useless comment lines or use /* format */"
    severity: warning
  missing_closure_name:
    name: "Missing closure name"
    regex: '^\s*\}\) \{.*'
    message: "Add the missing closure name"
    severity: warning
  • Are you using nested configurations? No
  • Which Xcode version are you using? Xcode 12.1 Build version 12A7403

example that trigger a violation:

// This triggers a violation:
// Multiline Arguments Violation: Arguments should be either on the same line, or one per line. (multiline_arguments)
UIView.animate(withDuration: 1,
               delay: 0) {
    // sample
    print("a")
} completion: { _ in
    // sample
    print("b")
}

examples that do not trigger a violation:

// The violation is not triggered.
UIView.animate(withDuration: 1,
               delay: 0
) {
    // sample
    print("a")
} completion: { _ in
    // sample
    print("b")
}
// The violation is not triggered.
UIView.animate(withDuration: 1,
               delay: 0) {
    // sample
    print("a")
}
@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Nov 7, 2020
@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Jan 6, 2021
@DamascenoRafael
Copy link
Author

It is still a bug in version 0.42.0

@stale stale bot removed the wontfix Issues that became stale and were auto-closed by a bot. label Jan 7, 2021
@Jeehut
Copy link
Collaborator

Jeehut commented Apr 11, 2022

Just ran into this, too with the following SwiftUI code:

Picker(selection: viewStore.binding(\.$someProperty)) {
   ForEach(SomeEnum.allCases, id: \.rawValue) { someCase in
      Text(someCase.rawValue)
         .tag(someCase)
   }
} label: {
   EmptyView()
}

@417-72KI
Copy link
Contributor

It is still a bug in version 0.49.1

@drspoton
Copy link

drspoton commented Dec 5, 2022

Still a but in 0.50.1

@rberggreen
Copy link

Still a bug in version 0.50.3. I always get some false positive warning when using multiple trailing closures along with other parameters, regardless of whether I place those other parameters on multiple lines.

TestView(
    param1: "something",
    param2: 0
) { // Vertical Parameter Alignment On Call Violation
    Text("Some view 1")
} closure2: {
    Text("Some view 2")
}
TestView(param1: "something", param2: 0) { // Multiline Arguments Violation
    Text("Some view 1")
} closure2: {
    Text("Some view 2")
}

No warnings:

TestView {
    Text("Some view 1")
} closure2: {
    Text("Some view 2")
}

marcelofabri added a commit that referenced this issue Feb 6, 2023
marcelofabri added a commit that referenced this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

6 participants