Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Another differences between AndroidStudio and Ktlint formatting #796

Closed
PPetka opened this issue Jun 24, 2020 · 10 comments · Fixed by #833
Closed

Another differences between AndroidStudio and Ktlint formatting #796

PPetka opened this issue Jun 24, 2020 · 10 comments · Fixed by #833

Comments

@PPetka
Copy link

PPetka commented Jun 24, 2020

The fix on the issue I've posted here #685 indeed fixed a lot of inconsistencies between formatting via ktlint and AndroidStudio, however, I found another bug.

This is the code before formatting, (ktlint sees no issues)
Screenshot 2020-06-24 at 10 54 20

After formatting via Android Studio
Screenshot 2020-06-24 at 10 54 29

ktlint version 0.37.2

@PPetka
Copy link
Author

PPetka commented Jul 21, 2020

Found another bug, Idk if, that's the same cause. Should I create separate PR for that?
Before:
Screenshot 2020-07-21 at 14 39 38
After:
Screenshot 2020-07-21 at 14 40 36

@AlexWink
Copy link

Hello,
I have the same issue here, the indents of the if () and the function call are stacking together with Android Studio formatting which I think is normal but ktlint wants only one indent:

Android Studio formatting:
image

ktlint formatting:
image

@jai
Copy link

jai commented Aug 10, 2020

Not sure if I should be dropping this here or in a separate issue, imports ordering is also off:

Android Studio

import android.os.Bundle
import android.view.View
import com.honestbank.android.apply.presentation.R
import com.honestbank.android.apply.presentation.common.setFieldListener
import com.honestbank.android.common.presentation.di.ViewModelProvidersWrapper
import com.honestbank.android.common.presentation.livedata.nonNull
import com.honestbank.android.common.presentation.livedata.observe
import com.honestbank.android.common.presentation.view.BaseFragment
import com.honestbank.android.common.presentation.view.updateView
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailNavigateButton
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailPassword
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailText
import kotlinx.android.synthetic.main.fragment_apply_email_layout.load_indicator
import javax.inject.Inject

vs

ktlint 0.37.0

import android.os.Bundle
import android.view.View
import com.honestbank.android.apply.presentation.R
import com.honestbank.android.apply.presentation.common.setFieldListener
import com.honestbank.android.common.presentation.di.ViewModelProvidersWrapper
import com.honestbank.android.common.presentation.livedata.nonNull
import com.honestbank.android.common.presentation.livedata.observe
import com.honestbank.android.common.presentation.view.BaseFragment
import com.honestbank.android.common.presentation.view.updateView
import javax.inject.Inject
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailNavigateButton
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailPassword
import kotlinx.android.synthetic.main.fragment_apply_email_layout.emailText
import kotlinx.android.synthetic.main.fragment_apply_email_layout.load_indicator

@romtsn
Copy link
Collaborator

romtsn commented Aug 10, 2020

@jai are you running ktlint with --android option? If so, then it's expected behavior, as per android styleguide the imports should be sorted alphabetically

@jai
Copy link

jai commented Aug 10, 2020

thanks @romtsn so for happy coexistence between ktlint and Android Studio I'm going to have to disable the android option it seems?

@romtsn
Copy link
Collaborator

romtsn commented Aug 10, 2020

Either that or you could add kotlin_imports_layout=idea to your .editorconfig as mentioned here, and they will happily coexist even with --android option :)

@jai
Copy link

jai commented Aug 10, 2020

@romtsn so I created a .editorconfig file in the project root with the following contents:

[*.{kt,kts}]
kotlin_imports_layout=idea

Running ktlint ended up throwing a bunch of errors:

/android-app/app/src/test/kotlin/com/honestbank/android/model/CampaignTest.kt:0:0: Internal Error (import-ordering). Please create a ticket at https://github.com/pinterest/ktlint/issues (if possible, provide the source code that triggered an error) (cannot be auto-corrected)

I'll try and dig deeper to see what's going on. This is ktlint running via a Gradle plugin so will try the command line ktlint and see if that makes a difference.

@romtsn
Copy link
Collaborator

romtsn commented Aug 10, 2020

This might be a bug (also please try to use 0.37.2 as there were some fixes for the import-ordering rule). If this still isn't working, feel free to open a new issue with code sample

@jai
Copy link

jai commented Aug 10, 2020

Looks like still having issues even with 0.37.2. Opened #826

@romtsn
Copy link
Collaborator

romtsn commented Aug 21, 2020

@PPetka the first issue is fixed by #833 but the second one is unfortunately not that easy to fix - please track it in #816

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants