Fix formatting of import with multiple attributes (fixes #445) and ensure that imports never wrap#501
Merged
allevato merged 1 commit intoswiftlang:mainfrom Apr 10, 2023
Conversation
…they **never** wrap (fixes swiftlang#445)
allevato
approved these changes
Apr 7, 2023
Member
allevato
left a comment
There was a problem hiding this comment.
This looks great, thanks! I agree that the desired behavior (for now, at least) is to forbid imports from wrapping under any circumstances, for consistency.
I'll kick off the CI over in swiftlang/swift-syntax#1086 (since we don't have the checks enabled on this repo yet).
Contributor
Author
|
Great, thank you! Ignore my question about companion PR in another thread, you already explained it here 😅 |
allevato
added a commit
to allevato/swift-syntax
that referenced
this pull request
Apr 10, 2023
This is a companion to swiftlang/swift-format#501, which tweaks the breaking behavior for `import` decls (and also fixes this existing mis-styling).
allevato
added a commit
to allevato/swift-format
that referenced
this pull request
Jun 29, 2023
Fix formatting of import with multiple attributes (fixes swiftlang#445) and ensure that imports never wrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#445 occurs because Swift Format simply just adds a space after the attribute list of import statements.
arrangeAttributeListcan be reused to correctly format the attributes of an import. However, when modifying the test for imports to include an import decl with multiple attributes, I found that attributes with arguments (e.g.@_spi(STP)) get wrapped when the import decl exceeds the line length. The comment included with the existing tests says that import decls shouldn't wrap (and I take this to also mean that discretionary breaks should be removed if present). Thus, I have made additional changes to ensure that import statements never wrap in any situation, please correct me if this is not the desired behaviour.To achieve this behaviour (see snippet below), I had to modify the
disableBreakingprinter control to be able to configure whether discretionary breaks should be allowed when breaks are suppressed (currently they are, but for the case of import decls this needs to be overridden to ensure that imports never wrap).I can see people wanting to be able to write code that wraps between attributes (as is sometimes done with
@resultBuilderon struct decls, or property wrappers). Should this be made configurable, or is it bad style?I also fixed the typo of
isBreakingSupressed(toisBreakingSuppressed) because it was only used in 3 places or so, which imo makes a merge conflict very unlikely. I'm happy to revert that if requested.