codemaid
codemaid copied to clipboard
Empty constructor and method formatting
Environment
- Visual Studio version: Microsoft Visual Studio Professional 2019 Version 16.11.8
- CodeMaid version: 12.0
- Code language: C#
Description
Ever since upgrading to v12, auto-formatting files has started moving the brackets of empty constructors and methods to a new line instead of keeping them on a single line like it used to. I'm not sure if this is a bug/regression or if I am just missing a setting somewhere.
Example:
public class MyClass
{
public MyClass() { }
public void MyMethod() { }
}
Will get formatted as:
public class MyClass
{
public MyClass()
{ }
public void MyMethod()
{ }
}
Using the "Format Document" feature of Visual Studio does not do this, so it appears to be something with CodeMaid formatting.
Steps to recreate
See example above.
Current behavior
Formatting places brackets of empty constructors and methods on their own line.
Expected behavior
Brackets of empty constructors and methods should be left on the same line as the method definition.
I would also love a toggle for this similar to the one for single line methods (SA1502).
Thanks for reporting the issue. I have been able to reproduce it.
I would also love a toggle for this similar to the one for single line methods (SA1502).
It would be best if there could also be a possibility to turn on formatting classes/methods to a single line if the body is empty. (opposite behavior to actual)
Would also like the ability to configure this behavior to leave empty constructor braces on the same line.
VS version: 2022 Community
If you change the option at CodeMaid->Options->Cleaning->Update->Update single line methods by placing braces on separate lines (SA1502), do you still the same behavior?
I have that option checked in my settings. For this instance, regardless of whether it was checked or unchecked, the empty constructor braces got moved to the next line.
This is a similar problem to #983. Disabling Code maid-> Options-> Cleaning-> Insert-> Insert explicit access modifier fields on methods, will fix this. Note if Update->Update single line methods by placing braces on separate lines (SA1502), is enabled then brackets will be moved to separate lines. If Insert explicit method is enabled then (SA1502) will not do anything as it overriden.
// Insert explicit disabled, SA1502 enabled.
public class MyClass
{
public MyClass()
{
}
public void MyMethod()
{
}
}
// Insert explicit disabled, SA1502 disabled.
public class MyClass
{
public MyClass() { }
public void MyMethod() { }
}
Yes, thank you @TimothyMakkison, that worked. Disabling both of these left the empty constructor braces on the same line.
Sorry necroing this issue, but in my opinion this is a bug that should be looked into. The explicit access modifiers have nothing to do with putting those curly braces to a separate line, and for my case (and I think many of the other users, too) I want CodeMaid to yes, insert explicit access modifiers, but don't move the empty curly braces to a separate line.