codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

[Question] How to prevent newline between property name and curly brace?

Open SpaceOgre opened this issue 1 year ago • 4 comments

Environment

  • Visual Studio version: 2022 Enterprise
  • CodeMaid version: 12.0
  • Code language: C#

Description

I have an older codebase and there are a lot of get only properties that looks like this:

public Guid LanguageId { get { return Language.ValueOrDefault(x => x.Id); } }

When I choose to clean document with CodeMaid it is changed to

public Guid LanguageId
{ get { return Language.ValueOrDefault(x => x.Id); } }

If I just format the document using Visual Studios built in Format document this does not happen so it seems to be a CodeMaid thing. I have tried changing the different settings but can't find the one to change, is it possible to change this behavior?

It is the same if it has a set to.

SpaceOgre avatar Mar 03 '23 08:03 SpaceOgre

It looks like insert explicit modifiers will reformat braces even when the modifier isn't changed 🤷.

You can turn this off via: Code maid-> Options-> Cleaning-> Insert-> Insert explicit access modifier fields on properties

TimothyMakkison avatar Mar 05 '23 00:03 TimothyMakkison

@TimothyMakkison this does indeed work, but I would like if I could keep that feature to 😞

SpaceOgre avatar Mar 10 '23 07:03 SpaceOgre

Yeah it's super annoying, I think this "bug" affects any type that enables insert explicit access modifiers and will insert a new line even when the access modifier isn't changed.

internal struct TempS { }
// Becomes
internal struct TempS 
{ }

I'm guessing the new line insertion is caused by changing the access modifier via the api codemaid uses. I don't understand why it always updates the type (adding a new line) even when it has an access modifier, I suspect the check is broken.

 var propertyDeclaration = CodeElementHelper.GetPropertyDeclaration(codeProperty);

if (!IsAccessModifierExplicitlySpecifiedOnCodeElement(propertyDeclaration, codeProperty.Access))
{
    // Set the access value to itself to cause the code to be added.
    codeProperty.Access = codeProperty.Access;
}

Hopefully #980 is added and fixes this 🤞

TimothyMakkison avatar Mar 10 '23 10:03 TimothyMakkison

Thanks both for all of the details. Yes there is a known issue in the VS SDK introduced in VS2022, more details in #879.

codecadwallader avatar Mar 28 '23 14:03 codecadwallader