https://kotlinlang.org logo
Join SlackCommunities
Powered by
# ktlint
  • d

    David Kubecka

    09/17/2024, 9:27 AM
    What's the level support for context receivers in ktlint? Currently, ktlint accepts this formatting:
    Copy code
    fun fetchStandingOrdersAuths(info: RequestOriginInfo, productHashedId: String): CustomerRelevantOperationsResponse =
            fetchStandingOrdersAuths(info, setOf(productHashedId))
    But once I "annotate" that with
    context(Raise<ApiError>)
    like this
    Copy code
    context(Raise<ApiError>)
        fun fetchStandingOrdersAuths(info: RequestOriginInfo, productHashedId: String): CustomerRelevantOperationsResponse =
            fetchStandingOrdersAuths(info, setOf(productHashedId))
    it reports that "First line of body expression fits on same line as function signature (standard:function-signature" rule is violated.
    p
    d
    • 3
    • 5
  • d

    David Kubecka

    09/17/2024, 12:03 PM
    I understand that ktlint relaxes certain rules (e.g. function naming) in tests based on the presence of specific imports (e.g. junit). What is the best way to keep that relaxes behavior even if the imports are moved to a common testing library?
    p
    • 2
    • 2
  • n

    nuhkoca

    09/18/2024, 4:28 PM
    Hello! Does anybody know how can I apply
    ktlint
    to a composite builds? ideally
    build-logic
    c
    h
    • 3
    • 8
  • r

    Rob Elliot

    10/06/2024, 4:02 PM
    Using the kotlinter gradle plugin v 4.4.1 - it's not linting build.gradle.kts or settings.gradle.kts (or indeed kts files in src/main/kotlin). Should it?
    p
    w
    • 3
    • 3
  • p

    Paul Dingemans

    10/24/2024, 7:19 PM
    Ktlint version
    1.4.0
    has been released. https://github.com/pinterest/ktlint/releases/tag/1.4.0
    🎉 2
    kodee happy 2
    👌 2
  • r

    Rahul kumar

    10/26/2024, 6:28 AM
    Hi, i have been trying to add a custom ktlint rule from buildSrc project, but its not triggering my custom rule, i am attaching the screenshots for project structure, can anyone help me on this, whats the issue
    p
    • 2
    • 5
  • j

    Johan

    10/29/2024, 8:38 PM
    What is the reason to have
    max-line-length
    set to
    off
    for intellij-idea settings? https://pinterest.github.io/ktlint/1.4.0/rules/standard/#max-line-length With 1.4.0,
    intellij-idea
    or max-line-length set to off changes
    Copy code
    private fun erReellArbeidssøker(periode: SummertInfotrygdPeriodeDto): Boolean =
            periode.aktivitet == InfotrygdAktivitetstype.TILMELDT_SOM_REELL_ARBEIDSSØKER
    To a long one-liner, is that as expected?
  • p

    Paul Dingemans

    10/29/2024, 8:42 PM
    The short answer is backward compatibility, and it is not defined in Kotlin Coding conventions. And yes, the one-liner is a result of that. I would recommend to set the max-line-length yourselves.
    j
    • 2
    • 1
  • r

    Rafs

    10/30/2024, 10:47 AM
    Is there a way to specify multiple baseline files for ktlint cli tool? I have a multi module project with several baseline files for each module.
    p
    • 2
    • 1
  • r

    Rahul kumar

    11/03/2024, 10:04 AM
    .editorconfig if placed inside buildSrc resource/config/ktlint/.editorconfig not recognized by ktlint, Does anyone know if its necessary to put .editorconfig on root level of project to get its recognized, because i see there is no method where we can set .editorconfig path in ktlint, also i see when i put ktlint_code_style = intellij_idea inside .editorconfig its not recognized. ktlint version used is 1.1.4
    p
    v
    • 3
    • 7
  • s

    Steven Zeck

    11/04/2024, 6:48 PM
    Possible stupid question. Does ktlint not offer autocomplete for rules when editing
    .editorconfig
    in Android Studio?
    p
    • 2
    • 1
  • d

    David Kubecka

    11/05/2024, 12:13 PM
    Is ktlint 1.4.0 available in the latest ktlint IDEA plugin? I see only this in the plugin config. Not sure what the default is, though.
    v
    p
    • 3
    • 3
  • d

    Dieter Vaesen

    11/07/2024, 12:53 PM
    Hey guys, a quick question. I would like to configure the KtLintExtension for KtLint so it filters out certain folders. But I would like to configure this in one of my own ConventionPLugins in a BuildConfig module. But It seems like I don't have access to the KtLintExtension class. I can do the following in my build.gradle.kts files but not in my plugin. Am I doing something stupid? Or overseeing something?
    Copy code
    configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
      filter {
        exclude { it.file.path.contains("generated") }
      }
    }
    v
    • 2
    • 15
  • a

    ansman

    11/12/2024, 2:12 PM
    I'm updating ktlint to the latest version and it wants to format like this:
    Copy code
    foo
      .bar {
        ...
      }.baz {
        ...
      }
    whereas I want to format like this (so that you can remove an operator without affecting the closing
    }
    ):
    Copy code
    foo
      .bar {
        ...
      }
      .baz {
        ...
      }
    I can disable the "Chain method continuation" rule but then you get no enforcement at all. Has anyone solved the same issue?
    p
    b
    • 3
    • 4
  • p

    Piotr Krzemiński

    11/29/2024, 11:26 AM
    if you were hit by kotlinter/ktlint's incompatibility with Kotlin 2.1.0, here's a corresponding issue: [pinterest/ktlint#2882] Kotlin 2.1 Compatibility Issue
  • j

    James

    12/05/2024, 8:22 AM
    Is there a way to force the
    .
    in a chain to be on a newline instead of after
    )
    or
    }
    ? I'm not sure I see a way to do this in Chain method continuation
    👍 1
    p
    • 2
    • 5
  • p

    Paul Dingemans

    12/05/2024, 8:31 AM
    Ktlint 1.5, including support for Kotlin 2.1 has been released. https://github.com/pinterest/ktlint/releases/tag/1.5.0
    🙌 4
    🙌🏼 1
    d
    • 2
    • 5
  • w

    wakingrufus

    12/08/2024, 4:23 PM
    Are there docs on which kotlin versions each version of ktlint is compatible with?
    p
    • 2
    • 6
  • a

    atticus

    12/20/2024, 11:41 AM
    Hi! Could anyone help me? I have the following code:
    Copy code
    class Test(
        val test1: String,
        val test2: String, // comment
        val test3: String
    )
    And I received the error: 'A comment in a 'value_parameter_list' is only allowed when placed on a separate line (cannot be auto-corrected).' I want to write the code like this. How can I disable this rule?
    p
    • 2
    • 4
  • m

    Mez Pahlan

    12/20/2024, 6:34 PM
    Hello everyone, lovely to meet you 👋 Can I get your thoughts on this please. I have the following class - note the opening squiggly bracket is outside of the character limit by 1:
    Copy code
    // Assume that the last allowed character is at the X character on the right                                                               X
    internal open class OkHttpClientAdapter(private val url: String, private val httpClient: OkHttpClient = OkHttpClient()) : HttpClientAdapter {
      ... // Some code of no interest.
    }
    Which, when formatted, turns into this:
    Copy code
    // Assume that the last allowed character is at the X character on the right                                                               X
    internal open class OkHttpClientAdapter(private val url: String, private val httpClient: OkHttpClient = OkHttpClient()) :
      HttpClientAdapter {
      ... // Some code of no interest.
    }
    I'm using
    ktlint_code_style = intellij_idea
    and would like something that does the following when format:
    Copy code
    // Assume that the last allowed character is at the X character on the right                                                               X
    internal open class OkHttpClientAdapter(
      private val url: String,
      private val httpClient: OkHttpClient = OkHttpClient(),
    ) : HttpClientAdapter {
      ... // Some code of no interest.
    }
    I can achieve this (sort of) by setting
    ktlint_standard_class-signature = disabled
    along with the code style, but unless I go round and fix all instances of the first formatting I can't benefit from an autofix in any way. It's fine once it is formatted but Ktlint doesn't automatically format in this way. IntelliJ has the ability to do this with the
    Put parameters on separate lines
    autofix and I was wondering if Ktlint could do something similar if it detects the max character count has been exceeded? In plain words: • For a class signature. • Whose character limit has been exceeded. • Put all parameters on separate lines. • With the closing class constructor bracket on the next line. • And ensure the supertype is on the same line as the closing class bracket. Is there some way I can achieve this via Ktlint? Thanks again for your time 🐱 .
  • p

    Paul Dingemans

    12/20/2024, 8:12 PM
    The class signature can do exactly what you want. See configuration option in docs: https://pinterest.github.io/ktlint/latest/rules/standard/#class-signature
    m
    • 2
    • 9
  • e

    eygraber

    01/02/2025, 5:57 PM
    @Paul Dingemans If the IDE settings for trailing commas becomes more configurable would ktlint as well? If so, should I file an issue to track that?
    p
    • 2
    • 1
  • d

    droidrcc

    02/14/2025, 5:50 PM
    Hi! I'm using ktlint 1.5.0 and was wondering why it doesn't report the below bad formatting:
    Copy code
    if (something == ABC
    ) {
      ...
    } else {
      ...
    }
    ) {
    should be on the same line of the if statement...
    Copy code
    if (something == ABC) {
    Do you have any insight?
    p
    • 2
    • 2
  • a

    andrew

    02/20/2025, 1:58 AM
    Is it normal for Ktlint to be slow to respond to
    .editorconfig
    changes when using spotless?
  • b

    Blaž Vantur

    02/20/2025, 9:00 AM
    Is it possible to ignore
    max_line_length
    for specific methods that are Annotated with
    @Test
    ?
    We are using back ticks for naming and we like having our names descriptive. But because of that the line length always exceed our defined limit for
    max_line_length
    . Is there a way to ignore it in some other global way without a need of adding suppress annotation directly where it happens?
    e
    h
    p
    • 4
    • 5
  • a

    Aditya Bhaskar

    03/03/2025, 12:45 PM
    (This is not strictly
    ktlint
    related) Does anyone know of any migration notes or discussions when updating to
    5.0.x
    of Kotlinter-gradle? I just made the update and the
    lintKotlin
    task is throwing 100s of lint errors. I’ve confirmed it’s not a ktlint issue by changing the
    ktlintVersion
    to previously working version. The release notes don’t suggest anything that could impact this. I have a feeling that the
    .editorconfig
    is not being used. As an example, one frequent error is due to the
    function-signature
    rule saying “First line of body expression fits on same line as function signature”. But that seems to ignore
    max-line-length
    set to 100 in editorconfig.
    • 1
    • 2
  • k

    Klitos Kyriacou

    03/03/2025, 6:25 PM
    I'm very confused about the indentation rules related to the superclass constructor call in subclass definitions. It seems that the indentation superclass constructor parameters depends on whether the subclass has any parameters. See code in thread.
    p
    • 2
    • 2
  • m

    Malte

    03/27/2025, 7:49 AM
    Hi! can ktlint detect usages for the
    else
    branch for
    when
    that have an enum as subject? i.e. i want to make ktlint recognize
    when(someEnum) {else -> … }
    - and raise an issue of course
    p
    k
    • 3
    • 7
  • z

    zt

    04/10/2025, 11:07 PM
    Some ktlint rule is bothering me by pointlessly wrapping the extended interfaces like this
    Copy code
    public class Hook(public override val replyUserData: Long) : MpvEvent, Reply
    into this
    Copy code
    public class Hook(public override val replyUserData: Long) :
        MpvEvent,
        Reply
    I cannot figure out what rule is doing this. There really should be an easier way to just quickly see a list of violations in the IDE
    r
    • 2
    • 1
  • k

    Klitos Kyriacou

    05/02/2025, 2:24 PM
    For
    [standard:import-ordering]
    if I have 100 imports and the 50th one is out of order, it gives the message "Imports must be ordered in lexicographic order" at the start of the first line of import. It would be very useful if it put the message on the first line that was out of order.