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

vertical_parameter_alignment_on_call shouldn't trigger after blocks #1630

Closed
marcelofabri opened this issue Jun 19, 2017 · 3 comments
Closed
Labels
bug Unexpected and reproducible misbehavior.

Comments

@marcelofabri
Copy link
Collaborator

// shouldn't trigger
UIView.animate(withDuration: 0.4, animations: {
    blurredImageView.alpha = 1
}, completion: { _ in
    self.hideLoading()
})
@marcelofabri marcelofabri added the bug Unexpected and reproducible misbehavior. label Jun 19, 2017
@ileitch
Copy link

ileitch commented Jun 20, 2017

I personally quite like the new format of

UIView.animate(
    withDuration: 0.4,
    animations: {
        blurredImageView.alpha = 1
    },
    completion: { _ in
        self.hideLoading()
    }
)

However, what is problematic is last argument closures:

transition(
    from: fromController,
    to: toController,
    duration: 0.75,
    options: options.union([.curveEaseInOut]),
    animations: {
        toController.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
) { _ in
    fromController.removeFromParentViewController()
    toController.didMove(toParentViewController: self)
    self.changeRightBarButtonItem(to: newRightButton)
}

If I do indent the { _ in line to satisfy the rule, the opening_brace rule then triggers for the same line. I could explicitly label the last argument, but I feel the lint rule should change rather than my code in this instance.

@ileitch
Copy link

ileitch commented Jun 20, 2017

Here's another erroneous case:

collectionView?.performBatchUpdates({ [weak self] in
        guard let strongSelf = self else { return }
        strongSelf.performChanges()
    },
    completion: { [weak self] (_) in
        guard let strongSelf = self else { return }

        strongSelf.delegate?.collectionViewBatchUpdaterDidCompleteBatchUpdates?(strongSelf)
    }
)

As in my previous example, moving the first closure to a newline triggers the opening_brace rule.

An argument label cannot be added to the first closure argument as this is a UIKit function which is exposed in Swift as func performBatchUpdates(_ updates: ...

@marcelofabri
Copy link
Collaborator Author

@ileitch even Xcode loses itself on your latest example 😅

anyway, I opened #1635 for the trailing closure indentation, because I think that's another issue.

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

2 participants