diff --git a/Source/SwiftLintFramework/Extensions/File+SwiftLint.swift b/Source/SwiftLintFramework/Extensions/File+SwiftLint.swift index 1cf385c6e2..f1a6aa87b5 100644 --- a/Source/SwiftLintFramework/Extensions/File+SwiftLint.swift +++ b/Source/SwiftLintFramework/Extensions/File+SwiftLint.swift @@ -285,8 +285,9 @@ extension File { return (count > limit, count) } + private typealias RangePatternTemplate = (NSRange, String, String) + internal func correct(legacyRule: R, patterns: [String: String]) -> [Correction] { - typealias RangePatternTemplate = (NSRange, String, String) let matches: [RangePatternTemplate] matches = patterns.flatMap({ pattern, template -> [RangePatternTemplate] in return match(pattern: pattern).filter { range, kinds in diff --git a/Source/SwiftLintFramework/Extensions/String+SwiftLint.swift b/Source/SwiftLintFramework/Extensions/String+SwiftLint.swift index 08ca721aa4..3d3ee5580c 100644 --- a/Source/SwiftLintFramework/Extensions/String+SwiftLint.swift +++ b/Source/SwiftLintFramework/Extensions/String+SwiftLint.swift @@ -70,10 +70,13 @@ extension String { limitedBy: utf16.endIndex) ?? utf16.endIndex let to16 = utf16.index(from16, offsetBy: nsrange.length, limitedBy: utf16.endIndex) ?? utf16.endIndex - if let from = Index(from16, within: self), let to = Index(to16, within: self) { - return from.. String { diff --git a/Source/SwiftLintFramework/Models/Location.swift b/Source/SwiftLintFramework/Models/Location.swift index d07648b4f0..080ceca816 100644 --- a/Source/SwiftLintFramework/Models/Location.swift +++ b/Source/SwiftLintFramework/Models/Location.swift @@ -58,8 +58,8 @@ public struct Location: CustomStringConvertible, Comparable { private func < (lhs: T?, rhs: T?) -> Bool { switch (lhs, rhs) { - case let (l?, r?): - return l < r + case let (lhs?, rhs?): + return lhs < rhs case (nil, _?): return true default: diff --git a/Source/SwiftLintFramework/Models/YamlParser.swift b/Source/SwiftLintFramework/Models/YamlParser.swift index a467f5ce94..efae1755cc 100644 --- a/Source/SwiftLintFramework/Models/YamlParser.swift +++ b/Source/SwiftLintFramework/Models/YamlParser.swift @@ -17,8 +17,8 @@ internal enum YamlParserError: Error, Equatable { internal func == (lhs: YamlParserError, rhs: YamlParserError) -> Bool { switch (lhs, rhs) { - case let (.yamlParsing(x), .yamlParsing(y)): - return x == y + case let (.yamlParsing(lhs), .yamlParsing(rhs)): + return lhs == rhs } } diff --git a/Source/SwiftLintFramework/Rules/CyclomaticComplexityRule.swift b/Source/SwiftLintFramework/Rules/CyclomaticComplexityRule.swift index a96f6a03dd..bc9cdd461c 100644 --- a/Source/SwiftLintFramework/Rules/CyclomaticComplexityRule.swift +++ b/Source/SwiftLintFramework/Rules/CyclomaticComplexityRule.swift @@ -100,10 +100,9 @@ public struct CyclomaticComplexityRule: ASTRule, ConfigurationProviderRule { let bodyOffset = dictionary.bodyOffset ?? 0 let bodyLength = dictionary.bodyLength ?? 0 - let c = file.contents.bridge() - .substringWithByteRange(start: bodyOffset, length: bodyLength) ?? "" + let contents = file.contents.bridge().substringWithByteRange(start: bodyOffset, length: bodyLength) ?? "" - let fallthroughCount = c.components(separatedBy: "fallthrough").count - 1 + let fallthroughCount = contents.components(separatedBy: "fallthrough").count - 1 return complexity - fallthroughCount } diff --git a/Source/swiftlint/Commands/LintCommand.swift b/Source/swiftlint/Commands/LintCommand.swift index 2ce34c0a0a..ac538f7bee 100644 --- a/Source/swiftlint/Commands/LintCommand.swift +++ b/Source/swiftlint/Commands/LintCommand.swift @@ -29,8 +29,8 @@ struct LintCommand: CommandProtocol { let currentViolations: [StyleViolation] if options.benchmark { let start = Date() - let (_currentViolations, currentRuleTimes) = linter.styleViolationsAndRuleTimes - currentViolations = LintCommand.applyLeniency(options: options, violations: _currentViolations) + let (violationsBeforeLeniency, currentRuleTimes) = linter.styleViolationsAndRuleTimes + currentViolations = LintCommand.applyLeniency(options: options, violations: violationsBeforeLeniency) visitorMutationQueue.sync { fileBenchmark.record(file: linter.file, from: start) currentRuleTimes.forEach { ruleBenchmark.record(id: $0, time: $1) } diff --git a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift index 5359d09cfe..713ae01e3e 100644 --- a/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/ConfigurationTests.swift @@ -98,7 +98,9 @@ class ConfigurationTests: XCTestCase { "whitelist_rules": whitelist ] let combinedRulesConfigDict = enabledRulesConfigDict.reduce(disabledRulesConfigDict) { - var d = $0; d[$1.0] = $1.1; return d + var dict = $0 + dict[$1.0] = $1.1 + return dict } var configuration = Configuration(dict: enabledRulesConfigDict) XCTAssertNil(configuration) diff --git a/Tests/SwiftLintFrameworkTests/CyclomaticComplexityRuleTests.swift b/Tests/SwiftLintFrameworkTests/CyclomaticComplexityRuleTests.swift index 61ff806d06..386b174add 100644 --- a/Tests/SwiftLintFrameworkTests/CyclomaticComplexityRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/CyclomaticComplexityRuleTests.swift @@ -14,8 +14,8 @@ class CyclomaticComplexityRuleTests: XCTestCase { private lazy var complexSwitchExample: String = { var example = "func switcheroo() {\n" example += " switch foo {\n" - for i in (0...30) { - example += " case \(i): print(\"\(i)\")\n" + for index in (0...30) { + example += " case \(index): print(\"\(index)\")\n" } example += " }\n" example += "}\n" @@ -25,14 +25,14 @@ class CyclomaticComplexityRuleTests: XCTestCase { private lazy var complexIfExample: String = { let nest = 22 var example = "func nestThoseIfs() {\n" - for i in (0...nest) { - let indent = String(repeating: " ", count: i + 1) + for index in (0...nest) { + let indent = String(repeating: " ", count: index + 1) example += indent + "if false != true {\n" example += indent + " print \"\\(i)\"\n" } - for i in (0...nest).reversed() { - let indent = String(repeating: " ", count: i + 1) + for index in (0...nest).reversed() { + let indent = String(repeating: " ", count: index + 1) example += indent + "}\n" } example += "}\n" diff --git a/Tests/SwiftLintFrameworkTests/Yaml+SwiftLintTests.swift b/Tests/SwiftLintFrameworkTests/Yaml+SwiftLintTests.swift index 09b4a4664c..8a290bc996 100644 --- a/Tests/SwiftLintFrameworkTests/Yaml+SwiftLintTests.swift +++ b/Tests/SwiftLintFrameworkTests/Yaml+SwiftLintTests.swift @@ -35,14 +35,14 @@ class YamlSwiftLintTests: XCTestCase { XCTAssertTrue(array1[2] as? Double == 1.0 && array2[2] as? Double == 1.0) XCTAssertTrue(array1[3] as? String == "string" && array2[3] as? String == "string") - let dict1_1 = (array1[4] as? [Swift.String: Any])! - let dict2_2 = (array2[4] as? [Swift.String: Any])! - XCTAssertTrue(dict1_1["bool"] as? Bool == true && dict2_2["bool"] as? Bool == true) - XCTAssertTrue(dict1_1["int"] as? Int == 1 && dict2_2["int"] as? Int == 1) - XCTAssertTrue(dict1_1["double"] as? Double == 1.0 && - dict2_2["double"] as? Double == 1.0) - XCTAssertTrue(dict1_1["string"] as? String == "string" && - dict2_2["string"] as? String == "string") + let dictFromArray1 = (array1[4] as? [Swift.String: Any])! + let dictFromArray2 = (array2[4] as? [Swift.String: Any])! + XCTAssertTrue(dictFromArray1["bool"] as? Bool == true && dictFromArray2["bool"] as? Bool == true) + XCTAssertTrue(dictFromArray1["int"] as? Int == 1 && dictFromArray2["int"] as? Int == 1) + XCTAssertTrue(dictFromArray1["double"] as? Double == 1.0 && + dictFromArray2["double"] as? Double == 1.0) + XCTAssertTrue(dictFromArray1["string"] as? String == "string" && + dictFromArray2["string"] as? String == "string") } catch { XCTFail(error.localizedDescription) }