Problem with formatting unit tests in Kotlin with Kotest's FunSpec
已回答
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 ?
请先登录再写评论。
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 = disabledktlint_standard_no-empty-first-line-in-class-body = disabledktlint_standard_wrapping = disabledktlint_standard_argument-list-wrapping = disabledktlint_standard_multiline-expression-wrapping = disabledktlint_standard_function-signature = disabledktlint_standard_function-naming = disabledktlint_standard_string-template-indent = disabledktlint_standard_trailing-comma-on-declaration-site = disabledktlint_standard_no-wildcard-imports = disabledij_kotlin_code_style_defaults = KOTLIN_OFFICIALij_continuation_indent_size = 4ij_kotlin_keep_blank_lines_before_right_brace = 0ij_kotlin_keep_blank_lines_in_code = 1ij_kotlin_keep_blank_lines_in_declarations = 1ij_kotlin_blank_lines_after_class_header = 0ij_kotlin_blank_lines_around_block_when_branches = 0ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1ij_kotlin_keep_line_breaks = falseij_kotlin_method_call_chain_wrap = split_into_linesij_kotlin_enum_constants_wrap = split_into_linesMaybe 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: