swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.38k stars 216 forks source link

Split comments if they exceed the line limit #723

Closed ahoppen closed 2 months ago

ahoppen commented 2 months ago

Formatting the following leaves the line comment as a single line even though it exceeds the line limit. We should break it up into multiple lines.

// some very long comment that just goes on and on and one without providing any real value but it reaches past the end of the line limit

Other interesting cases to consider are

End of line comments

I’m honestly not sure how to break this best, would make sense to check what eg. clang-format does

print("Hello, world!")  // some very long comment that just goes on and on and one without providing any real value but it reaches past the line limit

Indented comment parts

Here we should probably wrap the comment at the same indentation level that the line already has (ie. the wrapped line should also have 3 spaces after //)

// - some very long comment in a markdown list 
//   that just goes on and on and one without providing any real value but it reaches past line limit

Here, the wrapped line should also be aligned with some, not entirely sure what the general rule should be.

// - some very long comment in a markdown list that just goes on and on and one without providing any real value but it reaches past the line limit
ahoppen commented 2 months ago

Synced to Apple’s issue tracker as rdar://126967198

allevato commented 2 months ago

Duplicate of https://github.com/apple/swift-format/issues/469?