Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Add rules for formatting attributes #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add rules for formatting attributes #64

wants to merge 1 commit into from

Conversation

terrajobst
Copy link
Member

This adds two additional rules for dealing with attributes:

Removing superfluous parentheses

It's conventional to omit parentheses when the attribute doesn't take any arguments, for example:

[target: SomeAtt()]

becomes

[target: SomeAtt]

Separating attribute lists

Most folks only use a single attribute in an attribute list, although the syntax supports multiple attributes. In most cases, putting attributes in separate lists is beneficial because it improves readability and allows better diffs.

This changes code like this:

[Serializable, Category("Catagory"), DefaultValue(1)]

to

[Serializable]
[Category("Catagory")]
[DefaultValue(1)]

The only exception are attributes for parameters. In interop code, it's quite common to mark parameters with [In] and [Out]. Since the attributes are usually written inline, i.e. not on separate lines, it's actually beneficial to no split them into separate lists.

This means that code like this is left as-is:

void NativeFun([In, Out] int* target)

@terrajobst
Copy link
Member Author

@jaredpar

a.ArgumentList.Arguments.Count == 0 &&
(!a.ArgumentList.OpenParenToken.IsMissing || !a.ArgumentList.CloseParenToken.IsMissing));

return syntaxRoot.ReplaceNodes(attributes, (a, n) => a.WithArgumentList(null));

This comment was marked as spam.

This comment was marked as spam.

@jaredpar
Copy link
Member

👍

Gave some feedback on a couple of small issues to consider.

@terrajobst
Copy link
Member Author

Sorry, but I can't change the code anymore as I have the perfect number of lines being added! :-)

Just kidding, I'll take a look.

Base automatically changed from master to main March 11, 2021 16:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants