csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Could we have enum values on the same line as any applied attributes? (up to a reasonable line length)

Open fschwiet opened this issue 10 months ago • 3 comments

As it is now, enum definitions end up taking a lot of lines quickly if you start using custom attributes.

Input:

[AttributeUsage(AttributeTargets.Field)]
public class TestAttribute : Attribute { }

enum TestEnum
{
	[Test] Foo,
	Bar,
	[Test] Baz,
	Quz,
}

Output:

[AttributeUsage(AttributeTargets.Field)]
public class TestAttribute : Attribute { }

enum TestEnum
{
	[Test]
	Foo,
	Bar,

	[Test]
	Baz,
	Quz,
}

Expected behavior:

[AttributeUsage(AttributeTargets.Field)]
public class TestAttribute : Attribute { }

enum TestEnum
{
	[Test] Foo,
	Bar,
	[Test] Baz,
	Quz,
}

fschwiet avatar Feb 19 '25 20:02 fschwiet

I'm not opposed, but I'm not sure how others would feel about this change.

I tried to get an idea of how often code would be formatted with the attribute on the same line. Across all the code in https://github.com/belav/csharpier-repos these are the numbers for enum members with attributes, and how many of them had the attribute on the same line. It doesn't really account for length of the attribute.

Matching:                   83
Total:                     784
Percent:                10.59%

If I narrow that to an attribute that is < 12 characters the numbers are a bit higher. But it still seems like attributes on their own line is more common.

Matching:                   66
Total:                     174
Percent:                37.93%

Attributes on enum members don't seem to be super common, so the sample size isn't the greatest.

belav avatar Feb 23 '25 23:02 belav

Hmm, that is interesting and seems like an objective reason to not do it for now. Or one could push the change and see if anyone complains.

FWIW after creating the issue I found I could use csharpier-ignore-start & csharpier-ignore-end and that has been sufficient for me. CSharpier is still a great help overall.

fschwiet avatar Feb 23 '25 23:02 fschwiet