0

I have a Swift project in which is used swiftlint and my local version is 0.50.03.

My problem is with styling on closure after running swiftlint lint --fix --format command.

Here is the scenario:

I have a closure that will be formatted like this after applying Xcode formatting rules (cmd + I):

ASStoreManager.shared.makeRegisterAPIRequest(withEmail: emailInputView.formattedText,
                                                 withPassword: passwordInputView.formattedText,
                                                 withFullName: fullNameInputView.formattedText,
                                                 completion: { errors in
        ASLoaderUtils.shared.hide()
        
        if let errors = errors {
            ASAlertUtils.shared.presentAlert(withErrors: errors)
        } else {
            ASFirebaseManager.logEvent(withEventName: ASFirebaseConstants.Events.User.signUp,
                                       withParameters: ASFirebaseManager.getUserParameters())
            
            let viewController = ASConfirmationViewController(withConfirmationViewControllerType: .Register)
            viewController.callbacks.buttonDidTap = {
                ASStoreManager.shared.makeLogIn()
            }
            
            let navigationController = viewController.embedToNavigationController()
            navigationController.modalPresentationStyle = .fullScreen
            
            self.present(navigationController, animated: true)
        }
    })

After running the swiftlint command will be formatted like this:

        ASStoreManager.shared.makeRegisterAPIRequest(withEmail: emailInputView.formattedText,
                                                 withPassword: passwordInputView.formattedText,
                                                 withFullName: fullNameInputView.formattedText,
                                                 completion: { errors in
                                                    ASLoaderUtils.shared.hide()

                                                    if let errors = errors {
                                                        ASAlertUtils.shared.presentAlert(withErrors: errors)
                                                    } else {
                                                        ASFirebaseManager.logEvent(withEventName: ASFirebaseConstants.Events.User.signUp,
                                                                                   withParameters: ASFirebaseManager.getUserParameters())

                                                        let viewController = ASConfirmationViewController(withConfirmationViewControllerType: .Register)
                                                        viewController.callbacks.buttonDidTap = {
                                                            ASStoreManager.shared.makeLogIn()
                                                        }

                                                        let navigationController = viewController.embedToNavigationController()
                                                        navigationController.modalPresentationStyle = .fullScreen

                                                        self.present(navigationController, animated: true)
                                                    }
                                                 })

I tried with the next swiftlint configurations params in both disabled_rules & opt_in_rules or just in opt_in_rules or just in disabled_rules but nothing is working from stopping swiftlint to format my closure style:

disabled_rules:
  - closure_body_length
  - closure_end_indentation
  - closure_parameter_position
  - closure_spacing
  - multiple_closures_with_trailing_closure
  - trailing_closure

opt_in_rules:
  - closure_body_length
  - closure_end_indentation
  - closure_parameter_position
  - closure_spacing
  - multiple_closures_with_trailing_closure
  - trailing_closure

My question: How can I stop swiftlint from formatting my closure and keep the Xcode format style?

poPaTheGuru
  • 1,009
  • 1
  • 13
  • 35
  • You need to [edit] your question to include all relevant code as text, using proper code formatting - and not as a screenshot -, in the form of a [mcve] in order to make the question on-topic. – Dávid Pásztor Jan 20 '23 at 09:35
  • As for the formatting, just start the function input argument on a new line, then they won't be indented so much and Xcode's and swiftlint's formatting will match. – Dávid Pásztor Jan 20 '23 at 09:36
  • Indeed, if i start with the function input argument on a new line, the Xcode's formatting will match swiftlint's formatting, but would be there any way to keep the first input argument on the same line with the function and just prevent the formatting on closure? – poPaTheGuru Jan 20 '23 at 09:54
  • 1
    Unfortunately I don't think there is a way to achieve that. Putting the function input arguments on a new line also makes it easier to view the code on smaller screens and smaller windows, such as during code review, since it removes the need for horizontal scrolling. – Dávid Pásztor Jan 20 '23 at 10:05

0 Answers0