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

Weird indentation when chaining calls after a trailing closure. #205

Open
dmitriy-shmilo opened this issue Jun 16, 2019 · 5 comments
Open

Comments

@dmitriy-shmilo
Copy link

Using Swimat Version 1.6.2 (20) with XCode 10.1.

The following is a Swimat output when not using a trailing closure.

        Observable.combineLatest(self.stepName,
            self.stepDuration,
            resultSelector: { name, duration -> Bool in
                return name?.count ?? 0 > 0 && duration > 0
            })
            .bind(to: self.isAddStepAllowed)
            .disposed(by: self.disposeBag)

Swimat correctly indents it, and keeps indentation consistent, which is great. However, if you were to replace resultSelector with a trailing closure, I'd expect an output to look similar to this:

        Observable.combineLatest(self.stepName,
            self.stepDuration) { name, duration -> Bool in
                return name?.count ?? 0 > 0 && duration > 0
            }
            .bind(to: self.isAddStepAllowed)
            .disposed(by: self.disposeBag)

But what actually happens is Swimat formatting it to this:

        Observable.combineLatest(self.stepName,
            self.stepDuration) { name, duration -> Bool in
            return name?.count ?? 0 > 0 && duration > 0
        } // notice how this block is less indented
            .bind(to: self.isAddStepAllowed)
            .disposed(by: self.disposeBag)
@dmitriy-shmilo
Copy link
Author

After playing around with the snippet and placing line breaks in different places, I've found a workaround, which gives a nice formatting:

        Observable // line break here
            .combineLatest(self.stepName, self.stepDuration) {
                name, duration -> Bool in
                return name?.count ?? 0 > 0 && duration > 0
            }
            .bind(to: self.isAddStepAllowed)
            .disposed(by: self.disposeBag)

It feels a bit weird to leave a short first line, but at least it works.

@Jintin
Copy link
Owner

Jintin commented Jul 11, 2019

Thanks for report, seems comment block the train of closure work.

@rhkrthdud7
Copy link

@dmitriy-shmilo hey I am currently having the exact same issue can you share your workaround? thanks

@Jintin
Copy link
Owner

Jintin commented Jul 8, 2020

@rhkrthdud7 seems put (self.stepName, self.stepDuration) into same line?

@rhkrthdud7
Copy link

@Jintin oh I don't how I didn't see it... Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants