what should a string template containing JSON look...
# ktlint
e
what should a string template containing JSON look like?
Copy code
val request =
            """
                {
                    "fileName" : "foo.pdf",
                    "contentLength" : 1234,
                    "contentType" : "application/pdf"
                }
            """.trimIndent()
detekt (using ktlint) is complaining about every possible way I can think of to format that block
p
Remove the indent inside the raw literal.
Copy code
val foo =
    """
    Foo
    """.trimIndent()
e
yeah, but with JSON, it doesn't like that
Copy code
val request =
            """
            {
                "fileName" : "foo.pdf",
                "contentLength" : 1234,
                "contentType" : "application/pdf"
            }
            """.trimIndent()
but maybe that's a detekt setting... checking
p
I don't know about detekt but this is a format that Ktlint accepts depending on its code style.
e
yeah, the reality is that the detekt rule and ktlint rule conflict with each other
p
Then either disable the detekt rule or ktlint's string-temlate-indent rule
e
yeah, i think i'll disable detekt's rule. thanks. or just suppress it for now
b
That's not ktlint related. That's full detekt. It wants 4 more spaces for each line.
e
well... i can format it multiple ways. one ktlint complains, the other detekt complains
e
I would not use both detekt-formatting and ktlint at the same time
a
@Brais Gabin we should give option for indentation in detekt rule? What’s your thoughts?
b
I don't think so. I think that both tools should align. Which one? No idea. We should check if there is any documentation that promotes one of them.
a
Currently they don’t provide it and in their docs they are using different formatting 😅
p
Indeed there is no strict rule in the guidelines about whether raw string literals should have an inner indentation. So that is the reason that the ktlint rule is only enabled by default when using the new
ktlint_official
code style or whenever enabled explicitly.