Skip to content
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

SwiftLint --fix --format not applying Xcode default formatting #5210

Open
OmranK opened this issue Sep 7, 2023 · 2 comments
Open

SwiftLint --fix --format not applying Xcode default formatting #5210

OmranK opened this issue Sep 7, 2023 · 2 comments
Labels
sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream.

Comments

@OmranK
Copy link

OmranK commented Sep 7, 2023

I would assume that the swiftlint --fix --format command would apply the Xcode default formatting to the file but how Xcode handles empty lines in regards to whitespace differs from the behavior SwiftLint formatting is applying.

Xcode by default aligns empty line indentation to match its scope. The swiftlint --fix --format command removes all indentation so there is no whitespace on any empty lines.

How can I achieve SwiftLint automatically formatting the Xcode default style so when I go into a file in the future do a Command + A followed by a Control + I, there will be no changes?

@CraigSiemens
Copy link
Contributor

I think this is related to the issue I filed in SourceKitten. I probably should have filed it here too for more visibility.

@SimplyDanny SimplyDanny added the sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream. label Nov 11, 2023
@OmranK
Copy link
Author

OmranK commented Dec 5, 2023

Implemented the option in SourceKitten. Can someone help me with the SwiftLint side?

I added a EmptyLineAlignmentStyle enum to Configuration and used it similar to how IndentationStyle was used. I defaulted the enum to Xcode's default in the public initializer of Configuration and used the value leading up to the call site for the SourceKitten method which now has a new Bool parameter.

  • Not sure where/how I would add the option for the user to set their preference then mapping it to the correct enum case. Would this be a CLI option? or coming from SwiftLint.yml ?
  • SourceKitten main branch I worked off of has a new SwiftDeclarationKind enum case which the childsAreExemptFromACL var within ExplicitACLRule.swift file complains about as the switch doesn't cover this case. I added it to return true. Not sure if this is right, please advise.

main...OmranK:SwiftLint:main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sourcekit-issue Issues that are caused by a misbehavior in SourceKit and need to be fixed upstream.
Projects
None yet
Development

No branches or pull requests

3 participants