Skip to content

Format the swift-syntax repository using swift-format#1113

Merged
ahoppen merged 3 commits intoswiftlang:mainfrom
ahoppen:ahoppen/format
Dec 15, 2022
Merged

Format the swift-syntax repository using swift-format#1113
ahoppen merged 3 commits intoswiftlang:mainfrom
ahoppen:ahoppen/format

Conversation

@ahoppen
Copy link
Copy Markdown
Member

@ahoppen ahoppen commented Dec 5, 2022

This does not format the generated files because it’s harder to debug generator changes if the newly generated files need to be formatted to get a meaningful diff.

This PR is intended to spark the discussion whether we want to format all files in SwiftSyntax using swift-format. If we agree that we should do this, I will add a verification pass in CI to assure that all files are formatted.

I personally think that we should do this. In most cases I agree with the new format and not having to care about formatting when writing the code is a big win IMO.

rdar://103251585

@CodaFi
Copy link
Copy Markdown
Contributor

CodaFi commented Dec 5, 2022

The styling with the trailing ) on a new line looks odd to me. I think we ought to hew to the Swift standard library's whitespace conventions where possible.

Comment on lines +73 to +74
case // '0'-'9'
48, 49, 50, 51, 52, 53, 54, 55, 56, 57:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worse IMO. Is something weird going on because of the comment trivia here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allevato Do you know if this is a bug in swift-format or whether this formatting is intentional?

We can always turn off formatting for some of these lines with // swift-format-ignore as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug; we have some logic that tries to determine whether a comment is an end-of-line comment or some other inline comment so that we can do something that looks reasonable with it, and it looks like it's falling over in this case. At the very least we shouldn't be dedenting that next line.

Comment on lines -164 to +170
lastElement = self.parseSequenceExpressionElement(flavor,
forDirective: forDirective,
pattern: pattern)
lastElement = self.parseSequenceExpressionElement(
flavor,
forDirective: forDirective,
pattern: pattern
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about always requiring the latter here. Sometimes the former is better. I don't feel super strongly either way though.

Comment on lines +370 to +376
let unexpectedAfterArrow =
effectModifiersAfterArrow.isEmpty
? nil
: RawUnexpectedNodesSyntax(
elements: effectModifiersAfterArrow.map { RawSyntax($0) },
arena: self.arena
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO worse but I probably would have use an if here so... 🤷

Comment on lines -91 to +94
return (other.baseAddress! <= self.baseAddress! &&
self.baseAddress! + count <= other.baseAddress! + other.count)
return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allevato is this one intended because of the line length, or a bug?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the current implementation only allows breaking on the left-hand side of an infix operator (with the exception of assignment operators, which may only break on the right). So we remove the break after the && and then continue laying out the rest of the line, which never breaks again because of the high column limit.

With a lower line length, this would "auto-correct" because we would see that the && and the text after it doesn't fit and we would force the break before the && instead, but the high column limit is interfering here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so:

    return (other.baseAddress! <= self.baseAddress!
            && self.baseAddress! + count <= other.baseAddress! + other.count)

would have remained split?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a setting for that? I personally like them the other way 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a configuration option for that today. It probably wouldn't be difficult to add, but to date we haven't had the resources to maintain a large matrix of configurability options and make sure they all work well together, so we mainly prioritize the default style that we use within Google. (PRs welcome 😄)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks 🙇

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Dec 14, 2022

swiftlang/swift#62584

@swift-ci Please test

1 similar comment
@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Dec 14, 2022

swiftlang/swift#62584

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Dec 15, 2022

swiftlang/swift#62584

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Dec 15, 2022

swiftlang/swift#62584

@swift-ci Please test

@ahoppen
Copy link
Copy Markdown
Member Author

ahoppen commented Dec 15, 2022

swiftlang/swift#62584

@swift-ci Please test

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

Successfully merging this pull request may close these issues.

4 participants