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

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

Open
fschwiet opened this issue Feb 19, 2025 · 2 comments

Comments

@fschwiet
Copy link

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,
}
belav added a commit that referenced this issue Feb 23, 2025
@belav
Copy link
Owner

belav commented Feb 23, 2025

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.

@fschwiet
Copy link
Author

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.

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

No branches or pull requests

2 participants