https://kotlinlang.org logo
#feed
Title
# feed
g

gammax

03/15/2021, 11:54 AM
Hey all 👋 Sharing a small Gradle G plugin I wrote recently that lets you run #ktfmt on your project without having to download the CLI or setup an IntelliJ Plugin: https://github.com/cortinico/ktfmt-gradle/
👍 1
💪 3
🔝 3
🎉 2
y

yschimke

03/15/2021, 12:57 PM
If we are using spotless for ktfmt is there any differences making it compelling to switch?
g

gammax

03/15/2021, 1:04 PM
That plugin exposes a couple of fields that I believe spotless is not exposing. Other than that, no major reasons.
👍 1
r

rtsketo

03/15/2021, 6:49 PM
Sorry for newbie question here. In all my projects I get this error:
Copy code
Execution failed for task ':core:ktfmtFormatMainJavaSource'.
> 132:46: error: did not generate token ";"
What am I doing wrong?
g

gammax

03/15/2021, 6:51 PM
Sorry for newbie question here.
You should not be sorry for asking 🙏 Seems like a bug, potentially in #ktfmt rather than the gradle plugin 🧐 Could you open an issue (if you could also provide the file where it’s failing that would be awesome)
r

rtsketo

03/15/2021, 6:57 PM
I can't provide the whole file as it isn't my personal project. How can I find which file the error is referring to though? (File: 132? Line: 46?).
g

gammax

03/15/2021, 7:01 PM
If you rerun with
--info
the tool prints out what is doing.
r

rtsketo

03/15/2021, 7:30 PM
It doesn't show more info than that. With `--info`:
Copy code
> Task :core:ktfmtFormatMainJavaSource
Caching disabled for task ':core:ktfmtFormatMainJavaSource' because:
  Build cache is disabled
Task ':core:ktfmtFormatMainJavaSource' is not up-to-date because:
  Task has failed previously.

> Task :core:ktfmtFormatMainJavaSource FAILED
:core:ktfmtFormatMainJavaSource (Thread[Daemon worker,5,main]) completed. Took 12.826 secs.

Execution failed for task ':core:ktfmtFormatMainJavaSource'.
> 132:46: error: did not generate token ";"
With `--stacktrace`: https://pastebin.com/Jk3hHk50
I tried spotless and it did return a better error.
Copy code
Step 'ktfmt' found problem in 'app\src\main\java\-someting-\main\fragment\home\account\cards\CardAdapter.kt':
32:45: error: did not generate token ";"
So it turns out, it can't handle a
;
in a when, for example (changed names):
Copy code
icon.setImageResource(when (issuerID) {
                "Something1" -> something1; "Something2" -> somethings2
                "" -> something3.also { \* some other code in here *\ }
                else -> something4
            })
g

gammax

03/15/2021, 8:38 PM
Oh that’s interesting 👀 thanks for investigating
Just a couple of follow ups: • I’ve reported the
;
issue upstream here. That needs to be addressed by ktfmt maintainers. • I’ve fixed the error message as when ktfmt was crashing, the gradle plugin was not reporting on which file failed. That’s merged here
r

rtsketo

03/17/2021, 1:06 PM
Awesome!
🙏 1
c

Carmi Grushko

03/19/2021, 5:27 PM
ktfmt 0.22 is now out, fixing the semicolon issue.
👍🏼 1
g

gammax

03/20/2021, 3:47 PM
I’ve also update the plugin to ship this fix: https://github.com/cortinico/ktfmt-gradle/releases/tag/0.5.0
❤️ 2
5 Views