Stop formatter from inserting a new line at the beginning of a class decorator

Answered

I have recently started using IntelliJ IDEA and I am having trouble finding the right option to change the following behaviour of the Kotlin formatter. Given a class `Foo` with decorator `Decorator` that accepts multiple arguments, I would like the code to be formatted as

@Decorator(argument1, argument2, """
A long description
""")
Class Foo {
...
}

However, the Kotlin formatter uses the following format instead

@Decorator(
argument1, argument2, """
A long description
"""
)
Class Foo {
...
}

I have tried playing around with all the likely options I could find in Editor -> Code Style -> Kotlin, in particular the wrapping options for annotations in Wrapping and Braces, but none had any effect on this behaviour.

 

IntelliJ IDEA Ultimate version: 2020.3.1

Kotlin plugin version: 203-1.4.21-release-IJ6682.9

0
3 comments

Hello Alessandro,

Can't reproduce this on my setup.

What do you have as the Hard Wrap At value in the following places?

  • File | Settings | Editor | Code Style
  • File | Settings | Editor | Code Style | Kotlin > Wrapping and Braces

Do you have EditorConfig support enabled (File | Settings | Editor | Code Style)?

0
Avatar
Permanently deleted user

Hi Arina,

The Hard Wrap At values are 120 in both instances. I tried disabling EditorConfig support, but nothing changed. It might help to know that I am running IDEA on macOS Catalina 10.15.7.

 

Edit: I also tried to create a new project (with File | New | Project from existing sources) from a directory containing only the above snippet in a file called Foo.kt and I was still able to reproduce the behaviour, so it shouldn't be due to any project-specific option. I also didn't touch any of the Code Style options from my fresh install before noticing the issue.

 

Edit 2: The problem persisted after downgrading to version 203-1.4.21-release-IJ5981.133 of the Kotlin plugin. I was also able to reproduce the issue with a fresh install of the IntelliJ IDEA Community Edition version 2020.3.1 on my Arch Linux laptop, with both versions of the Kotlin plugin. I even tried to reset the Code Style in Settings | Editor | Code Style | Kotlin | Set from... | Kotlin style guide, but that also had no effect.

0

Hi Alessandro,

Could you export your code style scheme and attach it here (or upload to https://uploads.jetbrains.com/)?

0

Please sign in to leave a comment.