Repository navigation
Conversation
…icklockwood#2672) Co-authored-by: Cal Stephens <cal.stephens@airbnb.com>
…ingAPI` (nicklockwood#2678) Co-authored-by: calda <1811727+calda@users.noreply.github.com>
…assignment pattern (nicklockwood#2681)
…ckwood#2682) Co-authored-by: calda <1811727+calda@users.noreply.github.com>
…ites from classes to structs (nicklockwood#2680) Co-authored-by: calda <1811727+calda@users.noreply.github.com>
…wood#2683) Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2684 +/- ##
===========================================
+ Coverage 95.49% 95.57% +0.07%
===========================================
Files 181 181
Lines 27680 27788 +108
===========================================
+ Hits 26433 26557 +124
+ Misses 1247 1231 -16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Format over-width declaration-level where clauses one requirement per line while preserving comments, formatter directives, partial wrapping, and formatting ranges.
00c0553 to
8b1b9fe
Compare
| } | ||
|
|
||
| extension Formatter { | ||
| func wrapGenericRequirements() { |
There was a problem hiding this comment.
I like this but it should be behind an option, like --list-wrap-threshold. In fact it may make sense to just use --list-wrap-threshold.
| } | ||
|
|
||
| /// Executes a closure without changing the current rule's enablement or options state. | ||
| func withPreservedRuleState<T>(_ body: () throws -> T) rethrows -> T { |
There was a problem hiding this comment.
I would like to avoid introducing something complicated like this. What is the edge case you are trying to fix?
| declarationKeywordIndex = functionKeywordIndex | ||
| whereClauseRange = parsedRange | ||
| } else { | ||
| guard let declaration = declarations.declaration(containing: whereIndex), |
There was a problem hiding this comment.
Instead of iterating over tokens and then finding the containing declaration, it would be better to just use declarations.forEachResursiveDeclaration
There was a problem hiding this comment.
I also believe this check as written won't handle nested types, please include a test case for that. forEachResursiveDeclaration will handle that.
| if tokens[keywordIndex] == .keyword("init"), | ||
| let nextToken = index(of: .nonSpaceOrCommentOrLinebreak, after: keywordIndex), | ||
| tokens[nextToken] == .operator("?", .postfix) | ||
| tokens[nextToken] == .operator("?", .postfix) || tokens[nextToken] == .operator("!", .postfix) |
| endIndex: whereClauseRange.upperBound, | ||
| forceWrap: true, | ||
| leadingDelimiter: .delimiter(","), | ||
| normalizeSpaceAfterDelimiter: false |
There was a problem hiding this comment.
why false? would be simpler to not need to add this extra argument
There was a problem hiding this comment.
Given how many changes it takes to use wrapMultilineStatement here, it seems better to just not attempt to use it and instead implement one-off wrapping code directly in this function
5908303 to
741c3e4
Compare
e668206 to
e67a08f
Compare
|
I feel like this should also have a before-first/after-first wrap option like the other similar rules |
|
@nicklockwood @calda I've been really busy since I made this PR but haven't forgotten. I promise to get around to this asap :) |
Wrap over-width declaration-level
whereclauses one generic requirement per line as part of thewraprule.Before this PR:
After this PR: