-
Notifications
You must be signed in to change notification settings - Fork 253
Order conditionally-compiled imports #1077
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
base: main
Are you sure you want to change the base?
Conversation
|
Some questions to consider:
|
|
Thanks for looking into this!
We have to avoid changing the default behavior for anyone who's using the existing default in something like a CI workflow (we've forgotten that before, and it causes some annoyance). One day I want to refactor the settings to make it easier to add new configuration options to existing rules. For now, you could introduce a small
It would be good to have a nested case as well. For example, import A
#if FOO
import D
#if BAR
import F
import E
#else
import H
import G
#endif
import C
#endif
import BI would expect the output to be: import A
import B
#if FOO
import C
import D
#if BAR
import E
import F
#else
import G
import H
#endif
#endif |
|
@allevato I've added an option for enabling ordering conditional imports and the nested conditional imports test. I found some issues with the original implementation related to leading trivia and file header which I fixed and added some test cases for. I also updated the documentation. Please recheck. 🙏🏼 |
| if let firstLine = fileHeader.first, firstLine.type == .blankLine { | ||
| fileHeader.removeFirst() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This handles the case in testPreservesHeaderCommentInConditionalCompilationBlock.
Previously, the newline separating the comment and #if FOO was printed as is as part of fileHeader resulting in an extra newline separating the comment and #if FOO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for regular file headers if for some reason file header comments have a newline before them. I don't think this is a behavior we need to maintain. What do you think?
Recursively sort conditionally-compiled imports the same way other imports are ordered.
Conditionally-compiled imports are always placed after normal non-conditional imports as before, they're only sorted relative to the same
#ifblock.Resolves #1027.