Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid formatting when parameters have attributes with many values #1304

Open
johan-lindqvist opened this issue Jul 15, 2024 · 2 comments
Open

Comments

@johan-lindqvist
Copy link

johan-lindqvist commented Jul 15, 2024

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
)
@belav
Copy link
Owner

belav commented Jul 15, 2024

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
    ) { }

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Aug 11, 2024

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; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants