Skip to content

Commit

Permalink
Update for 0.51.14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Aug 5, 2023
1 parent 1a075f9 commit db0c7cb
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 249 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.51.14](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.51.14) (2023-08-05)

- Fixed regression in `unusedArguments` rule that caused used parameters to be marked unused
- Fixed some additional cases where regex literal was mistaken for `/` operator
- Vertical tab and form feed characters in source file no longer cause spurious errors

## [0.51.13](https://github.com/nicklockwood/SwiftFormat/releases/tag/0.51.13) (2023-07-18)

- Fixed bug where importing a type caused the `redundantSelf` rule to be silently disabled
Expand Down
Binary file modified CommandLineTool/swiftformat
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Formatter.swift
// SwiftFormat
//
// Version 0.51.13
// Version 0.51.14
//
// Created by Nick Lockwood on 12/08/2016.
// Copyright 2016 Nick Lockwood
Expand Down
12 changes: 3 additions & 9 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4083,7 +4083,7 @@ public struct _FormatRules {
wasDeclaration = false
}
let token = formatter.tokens[i]
outer: switch token {
switch token {
case .keyword("guard"):
isGuard = true
case .keyword("let"), .keyword("var"), .keyword("func"), .keyword("for"):
Expand All @@ -4103,14 +4103,8 @@ public struct _FormatRules {
formatter.currentScope(at: i) == .startOfScope("[")
{
if isDeclaration {
switch formatter.next(.nonSpaceOrCommentOrLinebreak, after: i) {
case .endOfScope(")")?, .operator("=", .infix)?,
.delimiter(",")? where !isConditional || formatter.currentScope(at: i) == .startOfScope("("):
tempLocals.insert(name)
break outer
default:
break
}
tempLocals.insert(name)
break
}
argNames.remove(at: index)
associatedData.remove(at: index)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import Foundation

/// The current SwiftFormat version
let swiftFormatVersion = "0.51.13"
let swiftFormatVersion = "0.51.14"
public let version = swiftFormatVersion

/// The standard SwiftFormat config file name
Expand Down
37 changes: 10 additions & 27 deletions Sources/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Tokenizer.swift
// SwiftFormat
//
// Version 0.51.13
// Version 0.51.14
//
// Created by Nick Lockwood on 11/08/2016.
// Copyright 2016 Nick Lockwood
Expand Down Expand Up @@ -551,10 +551,6 @@ extension UnicodeScalar {
return false
}
}

var isSpaceOrLinebreak: Bool {
isSpace || "\n\r\u{000B}\u{000C}".unicodeScalars.contains(self)
}
}

// Workaround for horribly slow String.UnicodeScalarView.Subsequence perf
Expand Down Expand Up @@ -732,7 +728,7 @@ private extension UnicodeScalarView {
}

mutating func readToEndOfToken() -> String {
readCharacters { !$0.isSpaceOrLinebreak } ?? ""
readCharacters { !$0.isSpace && !"\n\r".unicodeScalars.contains($0) } ?? ""
}
}

Expand All @@ -742,18 +738,13 @@ private extension UnicodeScalarView {
}

mutating func parseLineBreak() -> Token? {
switch first {
case "\r":
removeFirst()
if read("\r") {
if read("\n") {
return .linebreak("\r\n", 0)
}
return .linebreak("\r", 0)
case "\n", "\u{000B}", "\u{000C}":
return .linebreak(String(removeFirst()), 0)
default:
return nil
}
return read("\n") ? .linebreak("\n", 0) : nil
}

mutating func parseDelimiter() -> Token? {
Expand Down Expand Up @@ -1476,10 +1467,8 @@ public func tokenize(_ source: String) -> [Token] {
return
}
guard let prevNonSpaceIndex = index(of: .nonSpaceOrCommentOrLinebreak, before: i) else {
if string == "/" {
tokens[i] = .startOfScope("/")
} else if tokens.count > i + 1 {
tokens[i] = .operator(string, .prefix)
if tokens.count > i + 1 {
tokens[i] = string == "/" ? .startOfScope("/") : .operator(string, .prefix)
}
return
}
Expand Down Expand Up @@ -1549,8 +1538,11 @@ public func tokenize(_ source: String) -> [Token] {
guard let nextNonSpaceToken =
index(of: .nonSpaceOrCommentOrLinebreak, after: i).map({ tokens[$0] })
else {
if prevToken.isLvalue {
type = .postfix
break
}
if token == .operator("/", .none),
prevToken.isSpaceOrLinebreak ||
prevNonSpaceToken.isOperator(ofType: .infix) || (
prevNonSpaceToken.isUnwrapOperator &&
prevNonSpaceIndex > 0 &&
Expand All @@ -1562,9 +1554,6 @@ public func tokenize(_ source: String) -> [Token] {
].contains(prevNonSpaceToken)
{
tokens[i] = .startOfScope("/")
} else if prevToken.isLvalue {
type = .postfix
break
}
return
}
Expand Down Expand Up @@ -1875,12 +1864,6 @@ public func tokenize(_ source: String) -> [Token] {
token = tokens[count - 1]
switch token {
case .startOfScope("/"):
if let next = characters.first, next.isSpaceOrLinebreak {
// Misidentified as regex
token = .operator("/", .none)
tokens[count - 1] = token
return
}
scopeIndexStack.append(count - 1)
let start = characters
processStringBody(regex: true, hashCount: 0)
Expand Down
4 changes: 2 additions & 2 deletions SwiftFormat.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SwiftFormat",
"version": "0.51.13",
"version": "0.51.14",
"license": {
"type": "MIT",
"file": "LICENSE.md"
Expand All @@ -10,7 +10,7 @@
"authors": "Nick Lockwood",
"source": {
"git": "https://github.com/nicklockwood/SwiftFormat.git",
"tag": "0.51.13"
"tag": "0.51.14"
},
"default_subspecs": "Core",
"subspecs": [
Expand Down
12 changes: 6 additions & 6 deletions SwiftFormat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.SwiftFormat;
Expand Down Expand Up @@ -1144,7 +1144,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.SwiftFormat;
Expand Down Expand Up @@ -1251,7 +1251,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode";
PRODUCT_NAME = "SwiftFormat for Xcode";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1282,7 +1282,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode";
PRODUCT_NAME = "SwiftFormat for Xcode";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1310,7 +1310,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension";
PRODUCT_NAME = SwiftFormat;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1340,7 +1340,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 0.51.13;
MARKETING_VERSION = 0.51.14;
PRODUCT_BUNDLE_IDENTIFIER = "com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension";
PRODUCT_NAME = SwiftFormat;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
54 changes: 38 additions & 16 deletions Tests/RulesTests+Linebreaks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,52 @@ import XCTest
@testable import SwiftFormat

class LinebreakTests: RulesTests {
// MARK: - linebreaks
// MARK: - trailingSpace

func testCarriageReturn() {
let input = "foo\rbar"
// truncateBlankLines = true

func testTrailingSpace() {
let input = "foo \nbar"
let output = "foo\nbar"
testFormatting(for: input, output, rule: FormatRules.linebreaks)
testFormatting(for: input, output, rule: FormatRules.trailingSpace)
}

func testCarriageReturnLinefeed() {
let input = "foo\r\nbar"
let output = "foo\nbar"
testFormatting(for: input, output, rule: FormatRules.linebreaks)
func testTrailingSpaceAtEndOfFile() {
let input = "foo "
let output = "foo"
testFormatting(for: input, output, rule: FormatRules.trailingSpace)
}

func testVerticalTab() {
let input = "foo\u{000B}bar"
let output = "foo\nbar"
testFormatting(for: input, output, rule: FormatRules.linebreaks)
func testTrailingSpaceInMultilineComments() {
let input = "/* foo \n bar */"
let output = "/* foo\n bar */"
testFormatting(for: input, output, rule: FormatRules.trailingSpace)
}

func testFormfeed() {
let input = "foo\u{000C}bar"
let output = "foo\nbar"
testFormatting(for: input, output, rule: FormatRules.linebreaks)
func testTrailingSpaceInSingleLineComments() {
let input = "// foo \n// bar "
let output = "// foo\n// bar"
testFormatting(for: input, output, rule: FormatRules.trailingSpace)
}

func testTruncateBlankLine() {
let input = "foo {\n // bar\n \n // baz\n}"
let output = "foo {\n // bar\n\n // baz\n}"
testFormatting(for: input, output, rule: FormatRules.trailingSpace)
}

func testTrailingSpaceInArray() {
let input = "let foo = [\n 1,\n \n 2,\n]"
let output = "let foo = [\n 1,\n\n 2,\n]"
testFormatting(for: input, output, rule: FormatRules.trailingSpace, exclude: ["redundantSelf"])
}

// truncateBlankLines = false

func testNoTruncateBlankLine() {
let input = "foo {\n // bar\n \n // baz\n}"
let options = FormatOptions(truncateBlankLines: false)
testFormatting(for: input, rule: FormatRules.trailingSpace, options: options)
}

// MARK: - consecutiveBlankLines
Expand Down
45 changes: 0 additions & 45 deletions Tests/RulesTests+Redundancy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6482,34 +6482,6 @@ class RedundancyTests: RulesTests {
testFormatting(for: input, output, rule: FormatRules.unusedArguments)
}

func testClosureArgumentUsedInGuardNotRemoved() {
let input = """
bar(for: quux) { _, _, foo in
guard
let baz = quux.baz,
foo.contains(where: { $0.baz == baz })
else {
return
}
}
"""
testFormatting(for: input, rule: FormatRules.unusedArguments)
}

func testClosureArgumentUsedInIfNotRemoved() {
let input = """
foo = { reservations, _ in
if let reservations, eligibleToShow(
reservations,
accountService: accountService
) {
coordinator.startFlow()
}
}
"""
testFormatting(for: input, rule: FormatRules.unusedArguments)
}

// init

func testParameterUsedInInit() {
Expand Down Expand Up @@ -7095,23 +7067,6 @@ class RedundancyTests: RulesTests {
testFormatting(for: input, output, rule: FormatRules.unusedArguments)
}

func testFunctionArgumentUsedInGuardNotRemoved() {
let input = """
func scrollViewDidEndDecelerating(_ visibleDayRange: DayRange) {
guard
store.state.request.isIdle,
let nextDayToLoad = store.state.request.nextCursor?.lowerBound,
visibleDayRange.upperBound.distance(to: nextDayToLoad) < 30
else {
return
}
store.handle(.loadNext)
}
"""
testFormatting(for: input, rule: FormatRules.unusedArguments)
}

// functions (closure-only)

func testNoMarkFunctionArgument() {
Expand Down
Loading

0 comments on commit db0c7cb

Please sign in to comment.