Hi, I tried `./ktlint -F app/src/**/*.kt` from my ...
# ktlint
e
Hi, I tried
./ktlint -F app/src/**/*.kt
from my Android project root directory. All works and it corrected the file format. However it is not following AndroidStudio default rule. So I tried
./ktlint --android applyToIDEA -F app/src/**/*.kt
, but it crashes as below.
Copy code
Exception in thread "main" picocli.CommandLine$UnmatchedArgumentException: Unknown options: -F, app/src/androidTest/java/com/example/pdfreader/ExampleInstrumentedTest.kt, app/src/main/java/com/example/pdfreader/FileDownloader.kt, app/src/main/java/com/example/pdfreader/MainActivity.kt, app/src/main/java/com/example/pdfreader/PageAdaptor.kt, app/src/main/java/com/example/pdfreader/PageHolder.kt, app/src/main/java/com/example/pdfreader/PdfReader.kt, app/src/test/java/com/example/pdfreader/ExampleUnitTest.kt
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:7283)
	at picocli.CommandLine$Interpreter.processArguments(CommandLine.java:7357)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:7257)
	at picocli.CommandLine$Interpreter.parse(CommandLine.java:7147)
	at picocli.CommandLine.parseArgs(CommandLine.java:836)
	at com.pinterest.ktlint.Main.main(Main.kt:55)
What did I do wrong? I tried remove the
-F
, it is not working as well? I think I might have miss something…. any help? 🙏
r
Reading the docs (https://github.com/pinterest/ktlint#usage) it looks like you should be trying:
./ktlint -F "app/src/**/*.kt"
Note the quotation marks - I guess without them your shell is expanding the glob expression before calling ktlint?
r
applyToIDEA
is actually a cli subcommand that applies ktlint’s code style to your
.idea/codeStyles
so has nothing to do with formatting
so you have to just run
ktlint applyToIDEA
separately and then run your format command
but I have to warn you that the integration with idea is not perfect and it’s missing some rules, therefore you will still have misalignments with AS default formatting
e
Thanks @romtsn. Just got to learn that
applyToIDEA
is actually adding KtLint code style to Android Studio. Is there the other way round? i.e applying Android Studio default/project rule to Ktlint?
t
--android
cli swith uses Android flavor of code style
there is work in progress to move IDE integration via
.editorconfig
file