Problem with formatting unit tests in Kotlin with Kotest's FunSpec
Answered
I'm writing unit tests for my Kotlin application using Kotest 5.9.1 using the FunSpec flavor. When I reformat the code it looks like this:
class MyUnitTests : FunSpec({
fun runTest(testRunBlock: suspend ApplicationTestBuilder.(client: HttpClient) -> Unit) {
// my testcode here
}
})
But i want to eliminate the extra indent and have the code look like this:
class MyUnitTests : FunSpec({
fun runTest(testRunBlock: suspend ApplicationTestBuilder.(client: HttpClient) -> Unit) {
// my testcode here
}
})
The only way i have found to achieve this is to use the ktLint formatter. Is there any way to reduce the indent with the code formatting options of IntelliJ ?
Please sign in to leave a comment.
This is not the Kotlin IntelliJ plugin's default behavior. Usually, the formatting looks like your desired behavior.
Could you please change the code style to the 'Default' and use the 'Code' - 'Reformat Code' action to see if it formats correctly?
Thank you.
The code style for Kotlin is already set to “Default”, but i have a .editorconfig which overrides some properties:
[*.{kt,kts}]
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_wrapping = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_function-naming = disabled
ktlint_standard_string-template-indent = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_no-wildcard-imports = disabled
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_continuation_indent_size = 4
ij_kotlin_keep_blank_lines_before_right_brace = 0
ij_kotlin_keep_blank_lines_in_code = 1
ij_kotlin_keep_blank_lines_in_declarations = 1
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_keep_line_breaks = false
ij_kotlin_method_call_chain_wrap = split_into_lines
ij_kotlin_enum_constants_wrap = split_into_lines
Maybe here is a problem?
Thanks in advance
Andreas
Is there an easy way to grab the list?
Sorry, but i don't see “Collect Troubleshooting Information” under Help - Diagnostic tools. So i provide the list manually. Beneath the buindled plugins i have installed the following ones (all in the latest vresion):
Meanwhile i found a solution myself. In another project i have a sligthly different .editorconfig where the code is formatted as expected. Setting this to false to do the trick: