csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Invalid formatting when parameters have attributes with many values

Open johan-lindqvist opened this issue 1 year ago • 2 comments

Input:

public void Method(
	[Attribute(
		Something.Other,
		SomethingElse.Other,
		Something = Value,
		SomeString = "String",
		SomeNumber = 1
	)]
	IReadOnlyList<SomethingObject> somethingObjects,
	SomethingObject somethingObject)

Output:

public void Method(
	[Attribute(
		Something.Other,
		SomethingElse.Other,
		Something = Value,z
		SomeString = "String",
		SomeNumber = 1
	)]
		IReadOnlyList<SomethingObject> somethingObjects,
	SomethingObject somethingObject
)

Expected behavior: Both parameters, the one with attribute and the one without should have the same indentation

public void Method(
	[Attribute(
		Something.Other,
		SomethingElse.Other,
		Something = Value,
		SomeString = "String",
		SomeNumber = 1
	)]
	IReadOnlyList<SomethingObject> somethingObjects,
	SomethingObject somethingObject
)

johan-lindqvist avatar Jul 15 '24 11:07 johan-lindqvist

This was done intentially, but changing it is open to debate. If the attributes line up with the parameters it is less clear how many parameters you are dealing with in an example like below. My guess is I ran into some examples from https://github.com/belav/csharpier-repos that I thought looked better with the parameters indented.

// lined up attributes and parameters
    public void Method(
        [Attribute(_________________________longValue, _________________________longValue)]
        IReadOnlyList<SomethingObject> somethingObjects,
        SomethingObject somethingObject,
        SomethingObject somethingObject,
        [Attribute(_________________________longValue, _________________________longValue)]
        IReadOnlyList<SomethingObject> somethingObjects,
        SomethingObject somethingObject
    ) { }

// indentation of parameters that have a long attribute
    public void Method(
        [Attribute(_________________________longValue, _________________________longValue)]
            IReadOnlyList<SomethingObject> somethingObjects,
        SomethingObject somethingObject,
        SomethingObject somethingObject,
        [Attribute(_________________________longValue, _________________________longValue)]
            IReadOnlyList<SomethingObject> somethingObjects,
        SomethingObject somethingObject
    ) { }

belav avatar Jul 15 '24 18:07 belav

My personal opinion is that indentation doesn't make sense there since it's not a block and there's no nesting of any kind (i.e. the attribute declaration does not "contain" the parameter).

I also think it's pretty similar to the following example with properties instead of parameters, which doesn't introduce any indentation on formatting:

[Attribute(
    Something.Other,
    SomethingElse.Other,
    Something = Value,
    SomeString = "String",
    SomeNumber = 1
)]
public object Prop1 { get; }

[Attribute(
    Something.Other,
    SomethingElse.Other,
    Something = Value,
    SomeString = "String",
    SomeNumber = 1
)]
public object Prop2 { get; }

Tyrrrz avatar Aug 11 '24 23:08 Tyrrrz