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 ?

0
7 comments
Hi there, 

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.
0

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

 

0
Thank you. With the same settings in .editorconfig, the code is reformatted correctly on my end. Could you please share the list of the plugins you use?
0

Is there an easy way to grab the list?

0
You can go to Help - Diagnostic Tools - Collect Troubleshooting Information and send me the resulting file. Thank you!
0

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):

  • Multi Project Workspace
  • Plugin Devkit
  • Jump to line
  • HOCON
  • Resource Bundle Editor
  • Spectral
  • GitHub
  • Maven Helper
  • MapStruct Support
  • .env files support
  • Kotest
  • Exposed
  • Security Analysis by Quodana
  • K6
  • Sonarqube for IDE
  • Git Toolbox
  • Import from Postman collection (disabled)
  • Azure DevOps (disabled)
  • JPA Buddy (disabled)
  • Jetbrains Academy (disabled)
  • Space (disabled)
  • Jetbrains AI Assistant
  • Rider UI Themepack
0

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:

ij_kotlin_align_multiline_parameters_in_calls = false
0

Please sign in to leave a comment.