-
Notifications
You must be signed in to change notification settings - Fork 623
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
Support automatic sorting by name pattern for sortDeclarations
rule
#1731
Support automatic sorting by name pattern for sortDeclarations
rule
#1731
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1731 +/- ##
===========================================
- Coverage 95.24% 95.21% -0.03%
===========================================
Files 20 20
Lines 23284 23323 +39
===========================================
+ Hits 22176 22207 +31
- Misses 1108 1116 +8 ☔ View full report in Codecov by Sentry. |
Rules.md
Outdated
Option | Description | ||
--- | --- | ||
`--sortedpatterns` | List of patterns to sort alphabetically without `:sort` mark. | ||
`--sortedtypes` | default: `class,actor,struct,enum,protocol,extension` |
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.
I don't really understand the purpose of the --sortedtypes
option.
Reading the code, it looks like the set of --sortedpatterns
values only trigger a type to be sorted if the declaration kind is also included in --sortedtypes
. Is that right?
Is there a use case you have in mind for this? When would you want --sortedpatterns
to not apply to all kinds of declarations?
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.
tbh I just needed a list of top-level declarations to sort. I've made an array of swiftTypeKeywords
to look at in parsing helpers and something clicked in me to making it into configurable parameter as in organizeDeclarations
if I, for example, don't want to sort protocol
declarations. I guess if it's not the case I can remove this parameter as redundant and just stick with swiftTypeKeywords
, i don't have a strong opinion here
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.
Since we don't have a concrete use case in mind for this, to keep things simple I think it would be better to remove the --sortedtypes
options and just refer to the hardcoded list of swiftTypeKeywords
that you added.
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.
done, thanks for your comments!
@@ -4123,6 +4123,48 @@ class OrganizationTests: RulesTests { | |||
exclude: ["blankLinesAtEndOfScope"]) | |||
} | |||
|
|||
func testSortDeclarationsSortsByNamePattern() { |
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.
Thanks for following up on this!
This comment was marked as off-topic.
This comment was marked as off-topic.
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.
Thanks!
Changes referenced from previous pull request by @calda