-
Notifications
You must be signed in to change notification settings - Fork 238
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
🛠 Feature Request: Ignore Trailing Spaces in Comments #920
Comments
Synced to Apple’s issue tracker as rdar://144066894 |
Do you have a concrete example where intentional trailing whitespace in comments helps readability? I'm extremely skeptical. Regarding documentation comments, the Swift compiler expects them to be valid Markdown, and the only use I'm aware of for trailing whitespace in Markdown is that exactly 2 spaces at the end of a line can be used to insert a hard line break (e.g., |
It's not always possible to strictly follow the Markdown-style comment formatting, and if this issue is not ignored, a method is needed to correctly fix it automatically, either through the formatter itself or by another tool. Currently, SwiftFormat only diagnoses the problem but doesn't fix it. Is there a way for it to automatically correct issues in comments? |
I'm still interested in a concrete use case where trailing spaces in a comment are necessary. Can you demonstrate one? |
I agree that in common cases, it is not necessary. However, in some company standards, they could be required (and often it just copy/past). Removing it manually in a large codebase after introducing a new formatter requires using another tool that will do it automatically. |
Is your feature request related to a problem? Please describe.
Currently,
swift-format
removes trailing spaces from all lines, including comments. This behavior can be problematic when formatting documentation-style comments or preserving intentional spacing for readability.Describe the solution you'd like
It would be useful to have an option (e.g.,
"trailingWhitespace": "ignoreInComments"
) that allows trailing spaces to be ignored only in comments, while still removing them from regular code lines.Describe alternatives you've considered
"trailingWhitespace": "ignore"
), but this also affects code formatting, which is not ideal.swift-format
followed by a post-processing script to restore trailing spaces in comments.SwiftFormat
, which has anexcept_comments
option, but this is not an ideal solution for teams usingswift-format
.Additional context
This would help maintain readable comments, especially for documentation-style comments where spacing matters.
The text was updated successfully, but these errors were encountered: