Skip to content

Commit

Permalink
Apply code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ornithocoder committed Aug 7, 2017
1 parent 99c93f1 commit 3252673
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4850,7 +4850,12 @@ let foo = bar.joined(separator: toto)
<summary>Triggering Examples</summary>

```swift
let foo = bar.joined(separator: "")
let foo = bar.joined(separator: "")
```

```swift
let foo = bar.filter(toto)
.joined(separator: "")
```

</details>
Expand Down
18 changes: 12 additions & 6 deletions Source/SwiftLintFramework/Rules/JoinedDefaultRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public struct JoinedDefaultParameterRule: ASTRule, ConfigurationProviderRule, Op
"let foo = bar.joined(separator: toto)"
],
triggeringExamples: [
"let foo = bar.joined(separator: \"\")",
"let foo = bar.joined(separator: \"\")",
"let foo = bar.filter(toto)\n" +
" .joined(separator: \"\")"
" .joined(separator: \"\")"
]
)

Expand All @@ -49,10 +49,16 @@ public struct JoinedDefaultParameterRule: ASTRule, ConfigurationProviderRule, Op

private func defaultSeparatorOffset(dictionary: [String: SourceKitRepresentable], file: File) -> Int? {
guard
let bodyOffset = dictionary.bodyOffset,
let bodyLength = dictionary.bodyLength else { return nil }
dictionary.enclosedArguments.count == 1,
let argument = dictionary.enclosedArguments.first,
let argumentBodyOffset = argument.bodyOffset,
let argumentBodyLength = argument.bodyLength,
argument.name == "separator"
else {
return nil
}

let body = file.contents.bridge().substringWithByteRange(start: bodyOffset, length: bodyLength)
return body == "separator: \"\"" ? bodyOffset : nil
let body = file.contents.bridge().substringWithByteRange(start: argumentBodyOffset, length: argumentBodyLength)
return body == "\"\"" ? argumentBodyOffset : nil
}
}

0 comments on commit 3252673

Please sign in to comment.