Skip to content

Commit

Permalink
Add os_log to --selfrequired defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jun 9, 2024
1 parent a7675e4 commit eeb37b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/FormattingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extension Formatter {
if let prevIndex = self.index(of: .nonSpaceOrCommentOrLinebreak, before: scopeStart),
isSymbol(at: prevIndex, in: staticSelf ? [] : options.selfRequired.union([
"expect", // Special case to support autoclosure arguments in the Nimble framework
"os_log", // Special case to support string interpolation inside os_log
])) || isAttribute(at: prevIndex)
{
return false
Expand Down
10 changes: 10 additions & 0 deletions Tests/RulesTests+Redundancy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,16 @@ class RedundancyTests: RulesTests {
testFormatting(for: input, rule: FormatRules.redundantSelf, options: options)
}

func testNoRemoveSelfInOSLogFunction() {
let input = """
func testFoo() {
os_log("error: \\(self.bar) is nil")
}
"""
let options = FormatOptions(swiftVersion: "5.4")
testFormatting(for: input, rule: FormatRules.redundantSelf, options: options)
}

func testNoRemoveSelfInExcludedFunction() {
let input = """
class Foo {
Expand Down

0 comments on commit eeb37b5

Please sign in to comment.