Keep existing formatting option for force_attribute_style

There are cases when I would prefer to join attributes into same brackets, in other cases I'd like to have attributes places separately depending on the attributes themselves and the attribute length. For example in unit tests if I have `Theory` with single `Conventions` attribute I'd like to have them placed in the same brackets. When I have more conventions I'd like to have each attribute in separate brackets on new line:

 

```csharp

[Theory, Conventions]

public async Task Should(Injected parameter) {}

 

[Theory]

[Conventions(1)]

[Conventions(2)]

public async Task Should(Injected parameter) {}

```

Same applies to places like api controllers, R# `SuppressMessage` attributes, etc. Currently there's only option to either split or join attributes https://www.jetbrains.com/help/rider/EditorConfig_CSHARP_CSharpCodeStylePageImplSchema.html#resharper_csharp_force_attribute_style. Is there a way to split based on attributes count/length and/or keep existing formatting?

0
5 comments

Hello Andrii Litvinov, for different users mixed attributes formatting cases, we have added an option to Keep existing arrangement of attributes in Preferences | Editor | Code Style | C# | Line Breaks and Wrappings | Arrangement of Attributes. In the same section, there is also an option to limit length of attribute section on a single line. Let me know if that helps. 

0

Hi Olga, thanks for a reply! It doesn't really help, because with `keep_existing_attribute_arrangement=true` engine still reformats attributes:

Before:

[SuppressMessage("", ""), SuppressMessage("", "")]

After:

[SuppressMessage("", "")] [SuppressMessage("", "")]

Note that after reformatting the attributes are split into separate brackets.

0

Apparently, there is an issue in Rider that Keep existing arrangement of attributes doesn't work for some cases: https://youtrack.jetbrains.com/issue/RSRP-474909. I have added this scenario to the comments section.

1

Sorry, my previous comment is not correct. Actually, there is a way to prevent Rider from arranging attributes. The solution is to create a custom Cleanup profile via `File | Settings | Editor | Code Cleanup`. Here is the how-to:

1. Clone the default profile (Built-in full cleanup)

2. Rename it, and set is as default for silent cleanup

3. Uncheck C# -> Syntax styles -> Arrange attributes

4. That's it. From now on Code Cleanup won't arrange attributes in your code.

 

 

0

Thank you Julia for this workaround! Still it would be great to have the setting `keep_existing_attribute_arrangement` working.

0

Please sign in to leave a comment.