Skip to content

Commit

Permalink
Fix preferKeyPath
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jul 30, 2020
1 parent 29f5b65 commit b330357
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4713,7 +4713,7 @@ public struct _FormatRules {
return
} else {
let tokens = formatter.tokens[nextIndex + 1 ... lastIndex]
guard tokens.allSatisfy({ $0.isSpace || !$0.isIdentifier || !$0.isOperator(".") }) else {
guard tokens.allSatisfy({ $0.isSpace || $0.isIdentifier || $0.isOperator(".") }) else {
return
}
replacementTokens = [.operator("\\", .prefix)] + tokens
Expand Down
12 changes: 12 additions & 0 deletions Tests/RulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12397,4 +12397,16 @@ class RulesTests: XCTestCase {
let options = FormatOptions(swiftVersion: "5.1")
testFormatting(for: input, rule: FormatRules.preferKeyPath, options: options)
}

func testNoMapPropertyToKeyPathForFunctionCalls() {
let input = "let foo = bar.map { $0.foo() }"
let options = FormatOptions(swiftVersion: "5.2")
testFormatting(for: input, rule: FormatRules.preferKeyPath, options: options)
}

func testNoMapPropertyToKeyPathForCompoundExpressions() {
let input = "let foo = bar.map { $0.foo || baz }"
let options = FormatOptions(swiftVersion: "5.2")
testFormatting(for: input, rule: FormatRules.preferKeyPath, options: options)
}
}
2 changes: 2 additions & 0 deletions Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ extension RulesTests {
("testNoMangleYodaConditionInTernary", testNoMangleYodaConditionInTernary),
("testNoMangleYodaConditionInTernary2", testNoMangleYodaConditionInTernary2),
("testNoMangleYodaConditionInTernary3", testNoMangleYodaConditionInTernary3),
("testNoMapPropertyToKeyPathForCompoundExpressions", testNoMapPropertyToKeyPathForCompoundExpressions),
("testNoMapPropertyToKeyPathForFunctionCalls", testNoMapPropertyToKeyPathForFunctionCalls),
("testNoMapPropertyToKeyPathForSwiftLessThan5_2", testNoMapPropertyToKeyPathForSwiftLessThan5_2),
("testNoMapSelfToKeyPath", testNoMapSelfToKeyPath),
("testNoMarkFunctionArgument", testNoMarkFunctionArgument),
Expand Down

0 comments on commit b330357

Please sign in to comment.