https://kotlinlang.org logo
Join Slack
Powered by
# ktfmt
  • a

    Ali Naqvi

    12/18/2023, 5:35 PM
    Maybe a longshot but is it anyway possible in ktfmt to not keep chained methods on single line (when under 100 chars)? As in always keep newlines/put method chains with line breaks. This doesn't work too well for modifiers in compose for us
    j
    g
    • 3
    • 5
  • j

    Javier

    03/28/2024, 11:53 AM
    https://github.com/facebook/ktfmt/discussions/446
    K 5
  • n

    Nivaldo H Bondança

    05/03/2024, 1:41 PM
    I put up a proposal for 1.0.0 that includes this request there @Javier. Thanks for all your contributions 🙂 https://github.com/facebook/ktfmt/discussions/451#discussioncomment-9305741
  • s

    snowe

    06/11/2024, 4:52 PM
    Is there specific setup I need to do in order to get the ktfmt tests to run in intellij in order to contribute? Running any tests results in really weird errors.
    n
    • 2
    • 11
  • t

    Trey

    06/17/2024, 5:06 PM
    I'm trying to configure my project to just check the staged files in a git pre-commit hook, but I'm struggling on the syntax for --include-only. Can somebody provide an example of how to pass the results of
    git diff --name-only --cached
    to the pre-commit script?
    n
    • 2
    • 2
  • s

    snowe

    06/17/2024, 8:50 PM
    I’m having trouble understanding how BlankLineWanted, genSym(), and breakOp all work together. How do I tell if an expression like
    Copy code
    blah(
      name = a.b.c.d.e.f.g.h
    )
    is going to break at any point? It seems that this is partially handled by breaking the expression into parts and then grouping, but I don’t understand the grouping. Also the doc comments are quite confusing in places. or here where I’m confused as to what the groupings actually accomplish. Why is a paired with b, but c is paired with d, with no group between b and c?
    n
    d
    • 3
    • 9
  • r

    Robin PokornĂ˝

    07/05/2024, 8:16 AM
    Hey, I spend some time yesterday to add an MaxWidth override to the IDEA plugin: https://github.com/facebook/ktfmt/pull/492 Waiting for the maintainers to pick it up 😊 It seems that this particular setting is a dealbreaker for many. I can imagine that the plugin settings could get more detailed. I see this one option as a first step. Any feedback is welcome!
    👍 1
    g
    • 2
    • 3
  • c

    christophsturm

    07/17/2024, 2:32 PM
    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
    c
    g
    • 4
    • 41
  • c

    christophsturm

    08/07/2024, 10:51 AM
    is there going to be a new ktfmt release anytime soon, since in the latest release the kotlin style is broken?
    ☝️ 2
    n
    • 2
    • 3
  • s

    seb

    08/07/2024, 4:51 PM
    The IntelliJ Gradle plugin is also broken on IJ 242, which became stable today
    n
    • 2
    • 3
  • s

    seb

    08/08/2024, 10:39 AM
    @Nivaldo H Bondança would you be interested if I contributed a "custom" style setting for the IJ plugin, to set the few parameters available? This way one could align the style to @gammax's Gradle plugin.
    c
    n
    g
    • 4
    • 30
  • n

    Nivaldo H Bondança

    08/13/2024, 1:04 PM
    @christophsturm, to answer your question regarding why we allow configuration on gradle/maven plugin, that is there because those configurations are shareable as they are usually committed (and I think it would be a mistake not to) to the repository. This should prevent bikeshedding discussions about the code formatting, unless people are affecting that configuration file (
    build.gradle
    /
    pom.xml
    )
  • n

    Nivaldo H Bondança

    08/14/2024, 1:40 PM
    New release 0.52 is rolling out now! https://github.com/facebook/ktfmt/releases/tag/v0.52
    🦜 1
  • n

    Nivaldo H Bondança

    08/14/2024, 2:10 PM
    Or not... Release failed and I don't have time to look into this now and for the next couple of weeks. I'll see if someone else from the team can take a look, but feel free to chime in in case you know what's up https://github.com/facebook/ktfmt/actions/runs/10388724255/job/28765014936
    😢 1
    s
    c
    g
    • 4
    • 13
  • c

    christophsturm

    09/18/2024, 7:24 AM
    when i set manageTrailingCommas to false, they are not added, but also not removed. how can i set it to always remove them?
  • i

    ivanmorgillo

    09/18/2024, 3:45 PM
    Hi all 🙂
  • i

    ivanmorgillo

    09/18/2024, 3:46 PM
    Just as a followup and for visibility, have you ever experienced different outputs on Windows and Max? https://github.com/facebook/ktfmt/issues/516
    ➕ 1
  • s

    seb

    09/18/2024, 4:15 PM
    Would be great to figure out what's going on. In this case Ivan got different import ordering on Windows compared to macOS
  • i

    ivanmorgillo

    09/18/2024, 4:15 PM
    Oh yeah, thank you for mentioning it. The diff was indeed a couple of imports.
    👍 1
  • c

    Chris Lee

    09/18/2024, 9:34 PM
    it looks like the import sorting is done as below, though not obvious why that would be different on Win/Mac. Link.
    Copy code
    fun canonicalText(importDirective: KtImportDirective) =
            importDirective.importedFqName?.asString() +
                " " +
                importDirective.alias?.text?.replace("`", "") +
                " " +
                if (importDirective.isAllUnder) "*" else ""
    
        val sortedImports = importList.imports.sortedBy(::canonicalText).distinctBy(::canonicalText)
  • g

    GreyhairRedbear

    09/19/2024, 7:16 PM
    Well, it would seem odd to me that this would affect import ordering and this hasn't been noticed yet, but there is this section a few lines down:
    Copy code
    return code.replaceRange(
            importList.startOffset,
            importList.endOffset,                   importsWithComments.joinToString(separator = "\n") { imprt -> imprt.text } + "\n")
    (Sorry if the formatting is messed up there, currently on mobile) Adding
    \n
    instead of something like
    System.lineSeparator()
    seems a bit suspicious to me.
  • g

    GreyhairRedbear

    09/19/2024, 7:18 PM
    But as mentioned, it's more like something that caught my attention and might be working fine anyways, but since Windows is using CR+LF instead of just LF...
  • c

    Chris Lee

    09/20/2024, 12:10 AM
    that’s even trickier - while Windows uses CRLF the given file may not - or may perhaps (sadly) have mixed line endings. In any event, it looks like the sorting is done prior build the code string that include the eol character.
  • i

    ivanmorgillo

    11/25/2024, 2:50 PM
    Hi, any update on this https://github.com/facebook/ktfmt/issues/516 please? @gammax PLEEZ 🙏
    g
    n
    • 3
    • 3
  • j

    Javier

    11/28/2024, 11:12 AM
    Is ktfmt compatible with the latest 2024.3? I think it is always crashing by default but I do not see any open issue about it 👀
    n
    • 2
    • 3
  • g

    Gopal S Akshintala

    03/12/2025, 11:49 AM
    ktfmt 0.54 is not working with Multi-dollar string interpolation. It is flagging it as
    error: Expecting an expression
    . Is this a known issue? Sample project to replicate where it's configured through spotless: DynamicVariableGenerator.kt
    c
    n
    • 3
    • 2
  • s

    seb

    05/01/2025, 5:26 PM
    Hi folks, not sure if anyone noticed, but ktfmt is (indirectly?) using some deprecated Unsafe APIs that will be removed from the JDK https://github.com/facebook/ktfmt/issues/533
    👀 2
    g
    • 2
    • 8
  • u

    ursus

    05/24/2025, 1:05 AM
    I'm a ktfmt noob. Is this really the way fluent chains are supposed to look like? Even if the chain is longer than the max width?
    g
    n
    • 3
    • 17
  • n

    Nivaldo H Bondança

    08/07/2025, 9:06 PM
    We want to add a special case formatting to multiline strings with
    trimIndent()
    /
    trimMargin()
    and wanted to hear your thoughts about it. We'll use the poll results to guide our approach. Feel free to suggest alternatives as well, but do keep in mind this has to work with all the different use cases, which the represented code here for sure does not cover. Option 1
    Copy code
    val a =
        """
            a multiline
              string
            """
            .trimIndent()
            .nextMethod()
    
    val b =
        """
            |a multiline
            |  string
            |"""
            .trimMargin()
            .nextMethod()
    Option 2
    Copy code
    val a =
        """
        a multiline
          string
        """
            .trimIndent()
            .nextMethod()
    
    val b =
        """
        |a multiline
        |  string
        |"""
            .trimMargin()
            .nextMethod()
    Option 3
    Copy code
    val a =
        """
        a multiline
          string
        """
        .trimIndent()
            .nextMethod()
    
    val b =
        """
        |a multiline
        |  string
        |"""
        .trimMargin()
            .nextMethod()
    Option 4
    Copy code
    val a =
        """
        a multiline
          string
        """.trimIndent()
            .nextMethod()
    
    val b =
        """
        |a multiline
        |  string
        |""".trimMargin()
            .nextMethod()
    1️⃣ 1
    2️⃣ 3
    3️⃣ 1
    4️⃣ 3
    p
    s
    • 3
    • 13
  • c

    Colton Idle

    08/23/2025, 5:26 PM
    Updating from .46 to .57 noticed the biggest change was trailing commas... any way to opt out of them? 😅
    j
    • 2
    • 8