From be2c121071c3facf78681507e78d568addc1f54a Mon Sep 17 00:00:00 2001 From: Ornithologist Coder Date: Mon, 7 Aug 2017 11:24:04 +0200 Subject: [PATCH] Apply code review changes --- .../Rules/JoinedDefaultRule.swift | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/SwiftLintFramework/Rules/JoinedDefaultRule.swift b/Source/SwiftLintFramework/Rules/JoinedDefaultRule.swift index e153cfbfde8..7f30677ed66 100644 --- a/Source/SwiftLintFramework/Rules/JoinedDefaultRule.swift +++ b/Source/SwiftLintFramework/Rules/JoinedDefaultRule.swift @@ -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: ↓\"\")" ] ) @@ -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 } }