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 be2c121
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 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 @@ -48,11 +48,19 @@ public struct JoinedDefaultParameterRule: ASTRule, ConfigurationProviderRule, Op
}

private func defaultSeparatorOffset(dictionary: [String: SourceKitRepresentable], file: File) -> Int? {
let arguments = dictionary.substructure.filter { $0.kind == SwiftExpressionKind.argument.rawValue }

guard
let bodyOffset = dictionary.bodyOffset,
let bodyLength = dictionary.bodyLength else { return nil }
arguments.count == 1,
let argument = arguments.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 be2c121

Please sign in to comment.