Skip to content

Reduce line-length to 160 characters #1714

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

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 30, 2023

I played around withs some maximum line lengths and 160 seems to strike a good balance of prohibiting excessively long lines while not forcing line wraps on lines that are more clearly represented on a single line.


This was motivated by swiftlang/swift#66044 (comment). To repeat some of the data points from that comment.

Here’s a chart of the line lengths in non-generated SwiftSyntax code.

Screenshot 2023-05-26 at 10 31 06

Some key data points:

  • ≤160 characters: 99.9%
  • ≤150 characters: 99.8%
  • ≤140 characters: 99.7%
  • ≤130 characters: 99.5%
  • ≤120 characters: 99.1%
  • ≤110 characters: 98.6%
  • ≤100 characters: 97.9%
  • ≤90 characters: 96.7%
  • ≤80 characters: 94.4%

@ahoppen ahoppen requested a review from bnbarham May 30, 2023 16:46
@ahoppen ahoppen requested a review from DougGregor as a code owner May 30, 2023 16:46
@ahoppen
Copy link
Member Author

ahoppen commented May 30, 2023

@swift-ci Please test

Copy link
Contributor

@kimdv kimdv left a comment

Choose a reason for hiding this comment

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

A more general comment:
Some places methods are split after the last parameter so ) -> someReturnValue is on a new line.
That looks a bit odd to me and doesn't read that well IMHO.

Same for choices in Nodes where some elements of the list is on a newline and others are not.

Comment on lines 302 to 306
.token(tokenKind: "IdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .keyword(text: "init"), .keyword(text: "self"),
.keyword(text: "Self"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add a newline for all these .token() as it looks a bit odd to me to only have the last on a newline?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion on whether each should be on a newline or there should be lines of multiple tokens, but it is odd that the format will format any past 160 onto a line per token 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

@bnbarham, that was an artifact of how I kept reducing the line length to see the effect and then just re-ran swift-format, which respected existing line breaks.

I changed these long lists to be on new lines now. I agree that it makes scanning the lists easier.

@@ -322,7 +325,8 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .derivativeRegistrationAttributeArguments,
base: .syntax,
nameForDiagnostics: "attribute arguments",
documentation: "The arguments for the '@derivative(of:)' and '@transpose(of:)' attributes: the 'of:' label, the original declaration name, and an optional differentiability parameter list.",
documentation:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a swift-format option for making the string multiline?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, there isn’t. Really these doc comments should just be multi-line strings so that the generated documentation also has newlines to improve readability. But if we want to change that, I’d like to do it in a follow-up PR.

@ahoppen ahoppen force-pushed the ahoppen/line-length branch from 332eb9a to 8a5738a Compare May 30, 2023 19:09
Comment on lines 422 to 424
mutating func at<SpecSet1: TokenSpecSet, SpecSet2: TokenSpecSet>(anyIn specSet1: SpecSet1.Type, or specSet2: SpecSet2.Type) -> (
spec: TokenSpec, handle: TokenConsumptionHandle, matchedSubset: Any.Type
)? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this also be on a newline to match the style of returns?

@ahoppen ahoppen force-pushed the ahoppen/line-length branch from 8a5738a to 45b8578 Compare May 30, 2023 19:47
@ahoppen
Copy link
Member Author

ahoppen commented May 30, 2023

@swift-ci Please test

@ahoppen ahoppen force-pushed the ahoppen/line-length branch 3 times, most recently from 8dcd599 to f796dfe Compare May 31, 2023 16:42
@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2023

@swift-ci Please test

I played around withs some maximum line lengths and 160 seems to strike a good balance of prohibiting excessivly long lines while not forcing line wraps on lines that are more clearly represented on a single line.
@ahoppen ahoppen force-pushed the ahoppen/line-length branch from f796dfe to 9626030 Compare May 31, 2023 19:54
@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 31, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 1a7ae03 into swiftlang:main Jun 1, 2023
@ahoppen ahoppen deleted the ahoppen/line-length branch June 1, 2023 16:41
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.

3 participants