i just upgraded to latest ktfmt and it reformats c...
# ktfmt
c
i just upgraded to latest ktfmt and it reformats code from
Copy code
throw OrmException(
                    "error binding parameter"
                )
to
Copy code
throw OrmException(
                    "error binding parameter")
putting the closing bracket on the same line. is that documented somewhere?
j
I have seen this too, which is a bit weird on the Kotlinlang format, cc @Nivaldo H Bondança
Probably expected on the Google format tho
c
I always like more compact formatting but now it looks a bit asymetric because the opening bracket is on its own line
c
Noticed this change as well. In my case it takes code like:
Copy code
throw NullPointerException(
            "something"
        )
…and collapses it to:
Copy code
throw NullPointerException("something")
which I find preferable, there were many cases where one/two/three/four closing parentheses were on their own lines, that’s just noise wasting a line for a paren.
in your example did it perhaps wrap the parameter due to overall line length?
which seems like a bad wrapping, it doesn’t shrink the line length…
j
That is normal Chris, if something enters on a line, it is going to be collapsed
c
its normal now 😉 for previous ktfmt it didn’t do that.
j
I am seeing that since the very beginning of ktfmt 🤔 like 4-5 years ago
Are you referring to your snippet without
,
or with
,
Copy code
throw NullPointerException(
            "something",
        )
c
from ktfmt-gradle 0.18.0 to 0.19.0 it started collapsing those right parens. No, there are no trailing commas in all the code I saw reformatted.
j
Oh but that is a too old release indeed
c
yea, it was quite a gap in ktfmt versions, wish ktfmt-gradle kept up to date.
j
Current one is
0.51
,
0.19
is from 2020 indeed
In my case I am using spotless, it allows specifying a ktfmt version, so I can get it on the last version automatically with renovate
c
no, not ktfmt 0.19, ktfmt-gradle 0.19, which is now ktfmt 0.51. ktfmt-gradle 0.18.0 looked to use ktfmt 0.47. Tried spotless, it was problematic wrt Gradle configuration cache so a non-starter for us.
c
here is a more real life example:
Copy code
assert(
                         result[0] ==
-                            mapOf("id" to 1L, "name" to "belle", "email" to null, "bio" to bio)
-                    )
+                            mapOf("id" to 1L, "name" to "belle", "email" to null, "bio" to bio))
c
^^^ yep. have many similar ones that new ktfmt collapsed the parens.
c
I like it but it does not really feel like the kotlin formatting I’m used to
c
agreed.
c
so I wondered if theres docs somewhere with an explanation. and I wanted to makes sure that ist not going away in the next version before I merge the reformatting.
c
I looked in the ktfmt release notes, couldn’t find something relevent. For us it was ktfmt-gradle 0.18-0.19, which equates to ktfmt 0.47 - 0.51.
c
same for me.
g
Could you open an issue?
c
but is it a bug?
j
Looks like a bug in Kotlinlang IMO, probably a leak from some fix on Google format
c
^ so there are already two issues about it and it is already fixed in master
👍 1
in my project that uses
com.ncorti.ktfmt.gradle
the ktfmt check tasks fails on CI, but when i run it locally on the same branch it works. does anyone have an idea what could be the reason and how i could troubleshoot it?
j
Is it running on it is up to date or from cache?
Try with
--rerun-tasks
If it works, there is a problem in the Gradle plugin with the inputs/outputs/cache
c
it works
j
cc @gammax
c
this is the pr that fails: https://github.com/christophsturm/failgood-idea/pull/145 main branch which has the same ktfmt version works. EDIT: no it does not have the same version.
maybe its happens because I forgot to add the
Copy code
ktfmt { kotlinLangStyle() }
line to my build file? but it should always use the same default.
g
What’s up?
c
ktfmt check complained about wrong formatting but only on ci. I think it could be because i did not set a lang style in my build file.
🤔 1
my problem is fixed for now by adding the style line back in but its possible that there is a bug with selecting the code style when none is configured
and I’m going to stay on the 0.18 plugin anyway and wait for a ktfmt version where the kotlin style is not reformatting everything.
197 Views