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

Suggestion: Avoid breaking Attributes with only one parameter #1365

Open
timlindeberg opened this issue Oct 23, 2024 · 2 comments
Open

Suggestion: Avoid breaking Attributes with only one parameter #1365

timlindeberg opened this issue Oct 23, 2024 · 2 comments

Comments

@timlindeberg
Copy link

Input:

[Obsolete("Will be removed in a future version. Please replace any use of this class with some other class.")]

Output:

[Obsolete(
    "Will be removed in a future version. Please replace any use of this class with some other class."
)]

Expected behavior:

[Obsolete("Will be removed in a future version. Please replace any use of this class with some other class.")]

For cases like this breaking the statement up into multiple lines is not really helpful even if it surpasses the maximum line length. It's not possible to break up the string expression so you only end up indenting it slightly less and using three lines instead of one without really reducing the length of the line.

Could there maybe be an exception for attributes or methods with a single argument where the argument itself surpasses the line length? It could be limited to attributes but I've also seen method calls like this where it might make more sense to keep everything on one line:

Debug.Log(
     "A veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery long string"
);

Thanks for the great work on CSharpier! :)

@belav
Copy link
Owner

belav commented Oct 23, 2024

Great suggestion, I've gotten a bit annoyed with attributes breaking this way.

Treating method calls the same way seems reasonable. I feel like I may have implemented a similar rule for an if condition when it only contains a single operator.

The csproj/xml formatting I have in progress has similar rules about not breaking an empty element with a single attribute, and an element with no attributes and just a single line of text within it.

@belav belav added this to the Planned milestone Oct 23, 2024
@Hona
Copy link

Hona commented Oct 23, 2024

I would agree that multiline attributes is kinda annoying.
My personal opinion is usually keep them one line.

However, for csharpier, would the rule be that IF the attribute line is longer than max length AND after breaking onto multiple lines there is an overflowing line (e.g. the string), then just keep it all on one line?

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