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

function_default_parameter_at_end false positive #2788

Closed
jshier opened this issue Jun 26, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@jshier
Copy link
Contributor

commented Jun 26, 2019

New Issue Checklist

Describe the bug

Running SwiftLint on the following function results in a false positive for the function_default_parameter_at_end rule:

static func alertWithSingleAction(buttonTitle: String, title: String? = nil, message: String? = nil, buttonHandler: @escaping AlertActionHandler = { _ in }) -> UIAlertController {
    let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
    let defaultAction = UIAlertAction(title: buttonTitle, style: .default, handler: buttonHandler)
    controller.addAction(defaultAction)
    return controller
}

Strangely, other functions with default closures at the end work just fine. Perhaps the multiple default parameters throw it off?

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
/Users/jshier/Desktop/Code/project/Project/source/UIAlertController.swift:32:5: warning: Function Default Parameter at End Violation: Prefer to locate parameters with defaults toward the end of the parameter list. (function_default_parameter_at_end)

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.33.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
included:
  - Project
  - ProjectTests
  - Project UI Tests
  - DesignableUI
excluded:
  - Pods
disabled_rules:
  - file_length
  - force_cast
  - force_try
  - function_body_length
  - function_parameter_count
  - identifier_name # Configure minimum and maximum length.
  - line_length
  - nesting
  - sorted_imports # SwiftFormat will automatically sort them for us.
  - todo
  - trailing_whitespace
  - type_body_length
opt_in_rules:
  - anyobject_protocol
  - array_init
  - attributes
  - block_based_kvo
  - closure_end_indentation
  - closure_spacing
  - collection_alignment
  - contains_over_first_not_nil
  - convenience_type
  - discouraged_object_literal
  - empty_count
  - empty_string
  - empty_xctest_method
  - explicit_init
  - extension_access_modifier
  - fallthrough
  - fatal_error_message
  - first_where
  - for_where
  - function_default_parameter_at_end
  - identical_operands
  - implicit_return
  - joined_default_parameter
  - legacy_random
  - let_var_whitespace
  - literal_expression_end_indentation
  - lower_acl_than_parent
  - modifier_order
  - multiline_parameters
  - operator_usage_whitespace
  - overridden_super_call
  - pattern_matching_keywords
  - prohibited_super_call
  - redundant_nil_coalescing
  - sorted_first_last
  - sorted_imports
  - strong_iboutlet
  - toggle_bool
  - trailing_closure
  - unused_import
  - unused_private_declaration
  - vertical_parameter_alignment_on_call
  
modifier_order:
  preferred_modifier_order: [acl, override]
  • Are you using nested configurations? No.
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcode-select -p)? 10.2.1
  • 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:
static func alertWithSingleAction(buttonTitle: String, title: String? = nil, message: String? = nil, buttonHandler: @escaping AlertActionHandler = { _ in }) -> UIAlertController {
    let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
    let defaultAction = UIAlertAction(title: buttonTitle, style: .default, handler: buttonHandler)
    controller.addAction(defaultAction)
    return controller
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.