-
Notifications
You must be signed in to change notification settings - Fork 656
[New rule] spacingGuards #1804
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
[New rule] spacingGuards #1804
Conversation
@calda Could you please explain why in my project when I try to get new rule with cocoapods:
I have an error:
Before merging I'd like to test rule in my project and can't understand why it not see my new rule.
|
|
||
/// Formatting linebreaks | ||
/// Setting `linebreaksCount` linebreaks in `indexes` | ||
func leaveOrSetLinebreaksInIndexes(_ indexes: Set<Int>, linebreaksCount: Int) { |
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.
Can we put this in an extension
in SpacingGuards.swift
? Like:
extension Formatter {
/// Formatting linebreaks
/// Setting `linebreaksCount` linebreaks in `indexes`
func leaveOrSetLinebreaksInIndexes(_ indexes: Set<Int>, linebreaksCount: Int) { ... }
}
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 can put it there as fileprivate func. However it could be useful for other rules. If so - better to leave it in common place public extension Formatter
.
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.
Looking good!
I see there are still several failing tests that need to be updated. Let me know if you have any questions about how to fix them or run in to issues!
Sources/Rules/SpacingGuards.swift
Outdated
} | ||
|
||
let isGuard = nextNonSpaceAndNonLinebreakToken == .keyword("guard") | ||
let indexesBetween = Set(endOfScopeOfGuard + 1 ... nextNonSpaceAndNonLinebreakIndex - 1) |
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.
When running the tests locally I hit a crash here from endOfScopeOfGuard + 1
and nextNonSpaceAndNonLinebreakIndex - 1
being the same value, which is not allowed in a ClosedRange
.
You can fix this by using a Range
instead:
let indexesBetween = Set(endOfScopeOfGuard + 1 ... nextNonSpaceAndNonLinebreakIndex - 1) | |
let indexesBetween = Set(endOfScopeOfGuard + 1 ..< nextNonSpaceAndNonLinebreakIndex) |
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 👍
@calda done |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1804 +/- ##
===========================================
- Coverage 95.17% 95.16% -0.01%
===========================================
Files 132 133 +1
Lines 23723 23782 +59
===========================================
+ Hits 22578 22632 +54
- Misses 1145 1150 +5 ☔ View full report in Codecov by Sentry. |
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.
Good stuff
@calda @nicklockwood Could we please add this rule to release? |
I plan on making a new release in the next few weeks |
Would be appreciated) I have a couple of minds about new rules, but don't wont to spend time for them if the rule not releasing.) |
In the mean time, I set up a new nightly build pipeline. Using a nightly build would let you start using new rules / options right away in your projects before they're included in an official release: https://github.com/nicklockwood/SwiftFormat?tab=readme-ov-file#prerelease-builds |
@calda Can I use them via cocoapods? |
We don't have it set up to support Cocoapods. We also just updated Homebrew support so that |
0.56.0 has been released and includes this change: https://github.com/nicklockwood/SwiftFormat/releases/tag/0.56.0 Thanks for your patience @NikKovIos, more rules are always welcome! |
This is a fixed version of #1801
Also added readme for #1777