Skip to content

Undocumented rule for adding spaces before inline comments? #525

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

Closed
ghost opened this issue May 10, 2023 · 6 comments
Closed

Undocumented rule for adding spaces before inline comments? #525

ghost opened this issue May 10, 2023 · 6 comments

Comments

@ghost
Copy link

ghost commented May 10, 2023

In our codebase, the linter complains about hundreds of instances such as:

title: "Settings", // TODO: ....

and

CustomSection(title: "App Info") { // TODO: ...

It is always about having only 1 space before the inline comment forward slashes (//). The linter wants to have 2 spaces, as in

title: "Settings",  // TODO: ....

Why ? And what undocumented rule is enforcing that? And why is it undocumented?

@rikner
Copy link

rikner commented Jan 2, 2024

I also think there should be a configurable rule for this in order to be able to align this with other formatters in multi-language codebases.

@ephemer
Copy link

ephemer commented Jan 3, 2024

Agreed, to me the current behaviour looks like an error. Why randomly enforce two spaces?

@allevato
Copy link
Member

allevato commented Jan 3, 2024

I'm happy to review a PR that adds a configuration setting to change the number of spaces enforced before an end-of-line comment if someone wants to implement it. I think it should be a fairly straightforward change to TokenStreamCreator.

@ahoppen
Copy link
Member

ahoppen commented Apr 23, 2024

Tracked in Apple’s issue tracker as rdar://126948345

@ZachNagengast
Copy link

For anyone finding this before it gets released, @dduan added a PR to make this configurable #776 with "spacesBeforeEndOfLineComments": 1,🙏 you can enable it by installing the HEAD version of swift-format, here's an example using Homebrew

brew uninstall swift-format
brew install swift-format --HEAD

Previously it was hardcoded to 2 https://github.com/swiftlang/swift-format/pull/776/files#diff-c6c2e2a43fac11c6c1cda074a1e1b01693672cc219a2259994b2630c15e628dfL3174

@allevato
Copy link
Member

Closing as fixed by #776.

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

No branches or pull requests

5 participants