-
Notifications
You must be signed in to change notification settings - Fork 243
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
Bump the deployment target to macOS 13 🚀 #957
Conversation
.macOS("12.0"), | ||
.iOS("13.0"), | ||
.macOS("13.0"), | ||
.iOS("16.0"), |
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 also raised the iOS deployment target to 16 to use Swift Regex
.
One thing I'm curious about—does swift-format
need to support iOS?
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.
Someone added it a while back. I guess theoretically you could write an editor for iPad and want to format Swift code in it.
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.
Oh, I see! That could be a possible use case.
.macOS("12.0"), | ||
.iOS("13.0"), | ||
.macOS("13.0"), | ||
.iOS("16.0"), |
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.
Someone added it a while back. I guess theoretically you could write an editor for iPad and want to format Swift code in it.
/// Regex pattern to match an ignore directive comment. | ||
/// - Capture group #1 captures the rule names if `":"` is present. | ||
fileprivate func makeRegex() -> Regex<(Substring, Substring?)> { | ||
let pattern = #"^\s*\/\/\s*"# + description + #"(?:\s*:\s*(.+))?$"# |
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.
If we can't use RegexBuilder here because of platform limitations, it would still be nice to use real regex literals.
I don't remember from the previous PR, but if the description
property is only used here, you could lift the regexes up into that instead, something like:
var regex: Regex {
switch self {
case .node: return /...swift-format-ignore.../
case .file: return /...swift-format-ignore-file.../
}
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.
It would also be great to use named capture groups so that the result tuples elsewhere get labels, to make it more readable.
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.
description
is used in OrderedImports
to distinguish directives.
Also, after modifying it to use regex literals and running the CI, I found that, as @ahoppen mentioned below, regex literals are not supported on Windows Swift 5.9 (5.10). Given this, it seems best to keep the current implementation 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.
It would also be great to use named capture groups so that the result tuples elsewhere get labels, to make it more readable.
I have utilized the named capture group in the regex to add the label ruleNames
.
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.
Every time we try to do some good, Windows is there lurking in the background. 🙁
Thanks for checking!
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
/// - Capture group #1 captures the rule names if `":"` is present. | ||
fileprivate func makeRegex() -> Regex<(Substring, Substring?)> { | ||
let pattern = #"^\s*\/\/\s*"# + description + #"(?:\s*:\s*(.+))?$"# | ||
return try! Regex(pattern) |
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.
Could you add a comment that we can’t use regex literals here because Windows didn’t have support for regex literals until Swift 5.10 (at least I think it was 5.10)? Just so we don’t go back and wonder why we aren’t using regex literals 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.
Sure, I've added it.
a51d245
to
9757b67
Compare
9757b67
to
4e51ade
Compare
- Bump the deployment target to macOS 13 - Relax regex restrictions to allow rules containing _ or other special characters - Drop NSRegularExpression and migrate to Swift Regex
4e51ade
to
af6f7ab
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.
Thanks!
This change regressed performance of swift-format by 3% in release mode To reproduce this regression, run
@TTOzzi Could you check if there’s a good way to recover that performance regression? |
Oh, I see! Thank you for letting me know. |
Thank you ❤️ |
This PR addresses the follow-up work discussed in #950 (comment).
_
or other special charactersNSRegularExpression
and migrate to SwiftRegex