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
[27][28] - ktformat not formating indentation correctly #285
Comments
Hi Jared. |
I long for this feature every day. I would love to help @shyiko :D |
@shyiko If I'm correct, that's why the following 8-space intents weren't formatted into 4-space intents in my case: Before and after formatting (code hasn't changed at all): class AwesomeGoogleFit constructor(private val context: Context) :
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private val client: GoogleApiClient = GoogleApiClient.Builder(context, this, this)
.addApi(Fitness.SESSIONS_API)
.addScope(Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.build()
} Expected: class AwesomeGoogleFit constructor(private val context: Context) :
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private val client: GoogleApiClient = GoogleApiClient.Builder(context, this, this)
.addApi(Fitness.SESSIONS_API)
.addScope(Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.build()
} However if I formatted by using Android Studio, it just worked as expected. My Android Studio has been using the code style configs which were changed by |
@shyiko But there's one thing I can't understand is that, data class AwesomeState(
- val a: A? = null,
- val b: Boolean = false,
- val c: Boolean = false,
- val d: D? = null
+ val a: A? = null,
+ val b: Boolean = false,
+ val c: Boolean = false,
+ val d: D? = null
) Why? |
@iboss-ptk that would be great! give it try. https://github.com/shyiko/ktlint#ast & https://plugins.jetbrains.com/plugin/227-psiviewer might be useful (don't be afraid to ask if you hit the wall). @thuytrinh parameter wrapping is handled by ParameterListWrappingRule. |
@shyiko any idea how to determine if two indentation triggers happens to be on the same line eg.
At |
@iboss-ptk not sure I understand the question.
If there is anything after In other words, val a = listOf(1,2,3)
.map { it
.toString()
} piped through IndentRule should produce val a = listOf(1,2,3)
.map {
it
.toString()
} Other rules can decide whether to rewrite that to val a = listOf(1,2,3).map { it.toString() } or val a = listOf(1,2,3)
.map { it.toString() } |
@shyiko shouldn't it produce this? val a = listOf(1,2,3)
.map {
it
.toString()
} And isn't that not about indentation anymore? I can't think of error message about indentation in this case since it looks more like something else. |
And similar case, if addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
override fun onLayoutChange(
)
}) |
@iboss-ptk sorry, I must have had tabs in there (weren't visible on my machine). #285 (comment) updated.
You can leave "If there is anything after { (aside from parameters) in a multi-line block (it in this example) it should be moved to the next line." out of IndentRule if you want (a different rule can handle that). But I expect this can complicate things.
Something like "Newline missing after {" should do it. Regarding addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
override fun onLayoutChange(
)
}) It's indented as expected (+4). |
@shyiko So you would suggest to handle the That aside, I have another question. If there are binary expressions, how should we handle it? Since I see intellij handle it differently. If it's in the
But if not, it will behave like chaining dot
Should we follow that behaviour? |
@iboss-ptk Yep, IndentRule should match IntelliJ as closely as possible (when in doubt - just check what IntelliJ does). |
Moved to #338. |
Before:
After:
Should be:
The text was updated successfully, but these errors were encountered: