Questions tagged [ktlint]

ktlint is the most used linter for kotlin code. It is currently maintained by pinterest. it has integration with both maven and gradle.

37 questions
2
votes
1 answer

KtLint Execution failed for task ':app:ktlintAndroidTestDebugSourceSetCheck'

I am using gradle version 7.0.0-beta01 and following this guide to setup KtLint to my project. But I am facing error while running following command ./gradlew ktlintFormat Running with -stacktrace etc also doesn't seem to help much. Here is the…
Anuj Garg
  • 959
  • 10
  • 12
2
votes
0 answers

How to prevent !! via ktlint?

I have enabled ktlint im my Android Studio project and its running fine. Since there are standard Kotlin rules enabled, I would like to extend its standard rule set in order to prevent !!? I do not want to have any !! occurences in my…
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
2
votes
2 answers

ktlint not checking kotlin file

I want my project to perform ktlintCheck on all kotlin file, but it only check on build.gradle.kts file. build.gradle.kts file as below ktlint { version.set("9.4.0") debug.set(true) verbose.set(true) android.set(false) …
KY Lau
  • 21
  • 1
  • 3
2
votes
1 answer

Run Ktlint for all modules by executing single task command

I have multiple modules in my android project. I have one Gradle file which having code for ktlint. I applied that Gradle file to every module by writing this in the project Gradle file. subprojects { subProject -> apply from:…
Happy Singh
  • 1,334
  • 9
  • 23
1
vote
0 answers

Is there a way to tell kotlin compiler (via gradle) to fail when some package isn't matching file location?

I've seen multiple cases in which my lazy coworkers copy paste a file without changing the package. Kotlin is cool about it, and the only one issuing a warning is the IDE. Is there a way so that the compiler fails on THAT warning? or maybe... via…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
0 answers

How can I enforce my code conventions on line breaks in Kotlin?

Is there any formatting options available in either ktlint, ktfmt, diktat, prettier or other linter that can help me achieve this (see below)? This is the format that I desire (rewritten for this purpose, focus on formatting - not the logic): fun…
Alix
  • 2,630
  • 30
  • 72
1
vote
0 answers

How can I set up reviewdog for android and jetpack compose?

name: reviewdog on: [ pull_request ] jobs: ktlint: name: Ktlint Check Code Quality runs-on: ubuntu-latest steps: - name: Clone repo uses: actions/checkout@main with: …
c-an
  • 3,543
  • 5
  • 35
  • 82
1
vote
0 answers

How can I check the filename of a file being linted by ktlint?

I am trying to prevent certain imports in files with "ViewModel" in their filename but have so far only found a way to use ktlint to check for classes with ViewModel in their name. Does anyone know how to leverage ktlint to write a lint rule that…
teamcode
  • 11
  • 1
1
vote
1 answer

ktLintFormat fails with an error: Process 'command '/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/bin/java'' (macOS w/ Apple M1 chip)

Installed ktLint on my Android Studio project but when running I get the following error: Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ExceptionInInitializerError at…
Ambran
  • 2,367
  • 4
  • 31
  • 46
1
vote
1 answer

Use ktlint to format during maven build

I used the following settings for ktlint which allowed auto-formatting for all files during a local maven build but never triggered a pipeline failure if formatting was incorrect: com.github.gantsign.maven
nykon
  • 504
  • 4
  • 18
1
vote
1 answer

Ktlint ignores .editorconfig

I wanted to try out Kotlin and ktlint and I was happy to see that it supports tab indentation via the editorconfig file (since this PR). Sadly it doesn't seem to work for me. I haven't used editorconfig before, I might have made some simple…
findusl
  • 2,454
  • 8
  • 32
  • 51
1
vote
1 answer

Kotlin Linting RuleSetProvider 'trailing-comma'

I been trying to create a Ruleset using Pinterest ktlint Library but I can't remove the part of a children parameter list. https://github.com/pinterest/ktlint/issues/709 Due to the update on Kotlin to support 'trailing-commas', is breaking all my…
Ivor
  • 578
  • 1
  • 11
  • 27
0
votes
1 answer

How to disable ktlint max-line-length standard rule

I'm using ktlint 0.50.0, with Spotless 6.20.0, on AGP 8.1.0. Running spotless as a PreCommit Git hook. Due to the existence of too many old code, I'm trying to disable some rules. The one that gives me trouble is the "max_line_length". How can I…
ivtoto
  • 241
  • 1
  • 9
0
votes
0 answers

Why not disable the Ktlint role from the standard role set?

Why not disable the filename Ktlint role from the standard role set? build.gradle.kts plugins { id("org.jmailen.kotlinter") version "3.14.0" } .editorconfig [*] indent_size = 4 indent_style = space trim_trailing_whitespace =…
Numichi
  • 926
  • 6
  • 14
0
votes
0 answers

Android studio .editorconfig file not overriding the styles

I am currently trying to use ktlint and I want the same style to be followed by all developers so I want to override the AS styles with my own using the **.editorconfig **file but when I run ktlintFormat and then run alt + cmd + L there are new…