-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feature: sort imports access level handling #6377
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: sort imports access level handling #6377
Conversation
Generated by 🚫 Danger |
SimplyDanny
left a comment
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 makes sense to me, especially if the rule behaved like that before the rewrite. Apparently, there didn't exist enough tests to cover that. Thanks for the fix!
We'd need violating examples/tests that proof the right ordering after correction (in addition to the non-triggering ones).
881a1c8 to
d998649
Compare
|
Thanks, I thought I had an edge case I couldn't solve for when the access level and attributes were combined but I couldn't remember it. This should be a good improvement to merge in nonetheless 🙏🏻 I think I have included sufficient coverage in the examples and corrections now. Let me know! PS: As a side note, we'd appreciate even a pre-release of SwiftLint since we use the artifactbundle it is a pain for us to use commits that are untagged. Thanks for the consideration! |
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.
Pull request overview
This PR reinstates handling of access level modifiers in the sorted_imports rule, addressing issue #6374. When the grouping: attributes configuration is enabled, imports are now sorted by attributes first, then by access level modifiers (public, package, internal, fileprivate, private), and finally by module name.
Key Changes
- Added access level modifier detection and sorting logic for Swift imports when using the
attributesgrouping mode - Imports are sorted with more restrictive access levels (public) appearing before less restrictive ones (private), with plain imports appearing last
- Added comprehensive test examples covering various combinations of attributes and access level modifiers
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Source/SwiftLintBuiltInRules/Rules/Style/SortedImportsRule.swift | Adds modifier field to Import struct and implements modifier extraction and comparison logic for access-level sorting |
| Source/SwiftLintBuiltInRules/Rules/Style/SortedImportsRuleExamples.swift | Adds non-triggering, triggering, and correction examples demonstrating the new access level modifier sorting behavior |
| CHANGELOG.md | Documents the bug fix in the Main section with proper credit and issue reference |
Source/SwiftLintBuiltInRules/Rules/Style/SortedImportsRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Style/SortedImportsRule.swift
Outdated
Show resolved
Hide resolved
07559e5 to
b4b9a13
Compare
|
Providing CI passes and copilot is happy this is good for review 🙏🏻 |
Source/SwiftLintBuiltInRules/Rules/Style/SortedImportsRuleExamples.swift
Show resolved
Hide resolved
b4b9a13 to
3c2d1e0
Compare
There you go! 🎁 |
Attempts to resolve #6374.