-
Notifications
You must be signed in to change notification settings - Fork 630
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
organizeDeclarations
custom naming & ordering
#1736
organizeDeclarations
custom naming & ordering
#1736
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1736 +/- ##
===========================================
- Coverage 95.23% 95.20% -0.03%
===========================================
Files 20 20
Lines 23503 23692 +189
===========================================
+ Hits 22383 22556 +173
- Misses 1120 1136 +16 ☔ View full report in Codecov by Sentry. |
Current questions:
|
Sources/Examples.swift
Outdated
[ | ||
beforeMarks, | ||
instanceLifecycle, | ||
open, | ||
public, | ||
package, | ||
internal, | ||
fileprivate, | ||
private | ||
] |
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 I assume the argument itself doesn't allow the [
and ]
characters, maybe we should omit them from the default example?
[ | |
beforeMarks, | |
instanceLifecycle, | |
open, | |
public, | |
package, | |
internal, | |
fileprivate, | |
private | |
] | |
beforeMarks, | |
instanceLifecycle, | |
open, | |
public, | |
package, | |
internal, | |
fileprivate, | |
private |
To me it seems fine to leave this as-is. |
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.
Really cool, nice work! The implementation is really simple. Great to see how this builds on top of #1678.
I left some minor comments but otherwise this looks great to me!
The most important point is probably this discussion related to generating the DeclarationType
for each declaration: #1736 (comment)
c6722bc
to
c9f9e8b
Compare
610e36b
to
15531fd
Compare
0bcca90
to
a9c61c1
Compare
eb89782
to
48c9120
Compare
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 REALLY AWESOME! Nice work! I really like the way you implemented the validation. Great idea!
I left a few minor comments, but otherwise this is looking really good!!
@@ -1291,6 +1291,18 @@ private struct Examples { | |||
""" | |||
|
|||
let organizeDeclarations = """ | |||
Default value for `--visibilityorder`: |
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.
Very nice!
Rules.md
Outdated
|
||
<details> | ||
<summary>Examples</summary> | ||
|
||
Default value for `--visibilityorder`: | ||
`["beforeMarks", "instanceLifecycle", "open", "public", "package", "internal", "fileprivate", "private"]` |
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.
Should we format these defaults in a way that would be accepted by the --visibilityorder
argument?
So, instead, maybe:
`["beforeMarks", "instanceLifecycle", "open", "public", "package", "internal", "fileprivate", "private"]` | |
`beforeMarks, instanceLifecycle, open, public, package, internal, fileprivate, private` |
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.
yeah, thanks! this looks much better
let essentials = Formatter.VisibilityType.essentialCases.map(\.rawValue) | ||
for type in essentials { | ||
guard order.contains(type) else { | ||
throw FormatError.options("--visibilityorder expects \(type) to be included") |
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.
Great idea!
guard let match = type.bestMatches(in: essentials).first else { | ||
throw FormatError.options(errorMessage) | ||
} | ||
throw FormatError.options(errorMessage + ". Did you mean '\(match)?'") |
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.
Great UX here!
Tests/CommandLineTests.swift
Outdated
@@ -262,7 +262,7 @@ class CommandLineTests: XCTestCase { | |||
func testHelpLineLength() { | |||
CLI.print = { message, _ in | |||
for line in message.components(separatedBy: "\n") { | |||
XCTAssertLessThanOrEqual(line.count, 80, line) | |||
XCTAssertLessThanOrEqual(line.count, 100, line) |
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.
We shouldn't change this
XCTAssertLessThanOrEqual(line.count, 100, line) | |
XCTAssertLessThanOrEqual(line.count, 80, line) |
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.
sry, rolled back
Sources/FormattingHelpers.swift
Outdated
switch self { | ||
case .beforeMarks: | ||
return "Before Marks" | ||
"Before Marks" |
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.
You'll need to include the explicit return
here since SwiftFormat supports old Swift versions without this newer feature
"Before Marks" | |
return "Before Marks" |
case .keyword("let"), .keyword("var"), | ||
.keyword("operator"), .keyword("precedencegroup"): | ||
|
||
if isOverriddenDeclaration && availableTypes.contains(.overriddenProperty) { |
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.
Nice! This looks great
Sources/FormattingHelpers.swift
Outdated
let customVisibilityMarks = options.customVisibilityMarks | ||
let customTypeMarks = options.customTypeMarks | ||
|
||
func parseMarks<T: RawRepresentable>( |
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.
Maybe this could put put somewhere else in the file rather than being nested in the categoryOrder
method?
Sources/FormattingHelpers.swift
Outdated
let parsedVisibilityMarks: ParsedVisibilityMarks = parseMarks(for: customVisibilityMarks) | ||
let parsedTypeMarks: ParsedTypeMarks = parseMarks(for: customTypeMarks) | ||
|
||
func flatten<C1: Collection, C2: Collection>( |
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.
Same for this helper, maybe it doesn't need to be nested in this categoryOrder
method
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.
Really great work! This is awesome! Users are going to love it.
This PR adds an ability to parametrize order inside
organizeDeclarations
categories & their respective marks.I'm not sure about the design so it's up to discussion, but long story short:
We have 6 visibility categories (plus 2 for airbnb conventions, but i guess this number can increase without any major changes) and ~15 type groups. By providing parameters
--visibilityorder
we sort visibility categories (the same goes for thetypeorder
), and by--mode
parameter we tell which category will be respected as primary sorting group. Each group either take a defaultmark comment
value or custom parametrized with parameters--visibilitymark
&--typemark
, if provided.