From dfb447490e25995e8ba06525a8a7d39946f4cb40 Mon Sep 17 00:00:00 2001 From: Marcelo Fabri Date: Tue, 11 Sep 2018 09:31:54 -0700 Subject: [PATCH] Enable collection_alignment on SwiftLint --- .swiftlint.yml | 3 ++- .../Reporters/JUnitReporter.swift | 6 ++++-- .../Rules/Metrics/NestingRule.swift | 10 ++++++---- .../Rules/Style/TrailingWhitespaceRule.swift | 16 +++++++++++----- .../CustomRulesTests.swift | 16 ++++++++++------ .../LineLengthRuleTests.swift | 6 ++++-- .../RuleConfigurationTests.swift | 2 +- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index f5fa023bf8..c7f247ff2f 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -12,6 +12,7 @@ opt_in_rules: - attributes - closure_end_indentation - closure_spacing + - collection_alignment - contains_over_first_not_nil - empty_count - empty_string @@ -23,6 +24,7 @@ opt_in_rules: - file_header - file_name - first_where + - identical_operands - joined_default_parameter - let_var_whitespace - literal_expression_end_indentation @@ -51,7 +53,6 @@ opt_in_rules: - untyped_error_in_catch - vertical_parameter_alignment_on_call - yoda_condition - - identical_operands identifier_name: excluded: diff --git a/Source/SwiftLintFramework/Reporters/JUnitReporter.swift b/Source/SwiftLintFramework/Reporters/JUnitReporter.swift index c18e5818ea..f28fa85534 100644 --- a/Source/SwiftLintFramework/Reporters/JUnitReporter.swift +++ b/Source/SwiftLintFramework/Reporters/JUnitReporter.swift @@ -13,9 +13,11 @@ public struct JUnitReporter: Reporter { let severity = violation.severity.rawValue + ":\n" let message = severity + "Line:" + String(violation.location.line ?? 0) + " " let reason = violation.reason.escapedForXML() - return ["\n\t\n", + return [ + "\n\t\n", "" + message + "", - "\t"].joined() + "\t" + ].joined() }).joined() + "\n" } } diff --git a/Source/SwiftLintFramework/Rules/Metrics/NestingRule.swift b/Source/SwiftLintFramework/Rules/Metrics/NestingRule.swift index 0c5ea87631..a52f8a6d3e 100644 --- a/Source/SwiftLintFramework/Rules/Metrics/NestingRule.swift +++ b/Source/SwiftLintFramework/Rules/Metrics/NestingRule.swift @@ -16,15 +16,17 @@ public struct NestingRule: ASTRule, ConfigurationProviderRule, AutomaticTestable "and statements should be nested at most 5 levels deep.", kind: .metrics, nonTriggeringExamples: ["class", "struct", "enum"].flatMap { kind -> [String] in - ["\(kind) Class0 { \(kind) Class1 {} }\n", + [ + "\(kind) Class0 { \(kind) Class1 {} }\n", "func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " + - "func func5() {\n}\n}\n}\n}\n}\n}\n"] + "func func5() {\n}\n}\n}\n}\n}\n}\n" + ] } + ["enum Enum0 { enum Enum1 { case Case } }"], triggeringExamples: ["class", "struct", "enum"].map { kind -> String in return "\(kind) A { \(kind) B { ↓\(kind) C {} } }\n" } + [ - "func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " + - "func func5() {\n↓func func6() {\n}\n}\n}\n}\n}\n}\n}\n" + "func func0() {\nfunc func1() {\nfunc func2() {\nfunc func3() {\nfunc func4() { " + + "func func5() {\n↓func func6() {\n}\n}\n}\n}\n}\n}\n}\n" ] ) diff --git a/Source/SwiftLintFramework/Rules/Style/TrailingWhitespaceRule.swift b/Source/SwiftLintFramework/Rules/Style/TrailingWhitespaceRule.swift index 64dc107bfd..91c31026f1 100644 --- a/Source/SwiftLintFramework/Rules/Style/TrailingWhitespaceRule.swift +++ b/Source/SwiftLintFramework/Rules/Style/TrailingWhitespaceRule.swift @@ -13,11 +13,17 @@ public struct TrailingWhitespaceRule: CorrectableRule, ConfigurationProviderRule name: "Trailing Whitespace", description: "Lines should not have trailing whitespace.", kind: .style, - nonTriggeringExamples: [ "let name: String\n", "//\n", "// \n", - "let name: String //\n", "let name: String // \n" ], - triggeringExamples: [ "let name: String \n", "/* */ let name: String \n" ], - corrections: [ "let name: String \n": "let name: String\n", - "/* */ let name: String \n": "/* */ let name: String\n"] + nonTriggeringExamples: [ + "let name: String\n", "//\n", "// \n", + "let name: String //\n", "let name: String // \n" + ], + triggeringExamples: [ + "let name: String \n", "/* */ let name: String \n" + ], + corrections: [ + "let name: String \n": "let name: String\n", + "/* */ let name: String \n": "/* */ let name: String\n" + ] ) public func validate(file: File) -> [StyleViolation] { diff --git a/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift b/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift index bf19594161..6df5512005 100644 --- a/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift +++ b/Tests/SwiftLintFrameworkTests/CustomRulesTests.swift @@ -6,11 +6,15 @@ import XCTest class CustomRulesTests: XCTestCase { func testCustomRuleConfigurationSetsCorrectly() { - let configDict = ["my_custom_rule": ["name": "MyCustomRule", - "message": "Message", - "regex": "regex", - "match_kinds": "comment", - "severity": "error"]] + let configDict = [ + "my_custom_rule": [ + "name": "MyCustomRule", + "message": "Message", + "regex": "regex", + "match_kinds": "comment", + "severity": "error" + ] + ] var comp = RegexConfiguration(identifier: "my_custom_rule") comp.name = "MyCustomRule" comp.message = "Message" @@ -132,7 +136,7 @@ class CustomRulesTests: XCTestCase { private func getCustomRulesWithTwoRules() -> ((RegexConfiguration, RegexConfiguration), CustomRules) { let config1 = ["regex": "pattern", - "match_kinds": "comment"] + "match_kinds": "comment"] var regexConfig1 = RegexConfiguration(identifier: "custom1") do { diff --git a/Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift b/Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift index 7988a0390c..02b2df0aee 100644 --- a/Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift +++ b/Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift @@ -51,8 +51,10 @@ class LineLengthRuleTests: XCTestCase { func testLineLengthWithIgnoreURLsEnabled() { let url = "https://github.com/realm/SwiftLint" let triggeringLines = [String(repeating: "/", count: 121) + "\(url)\n"] - let nonTriggeringLines = ["\(url) " + String(repeating: "/", count: 118) + " \(url)\n", - "\(url)/" + String(repeating: "a", count: 120)] + let nonTriggeringLines = [ + "\(url) " + String(repeating: "/", count: 118) + " \(url)\n", + "\(url)/" + String(repeating: "a", count: 120) + ] let baseDescription = LineLengthRule.description let nonTriggeringExamples = baseDescription.nonTriggeringExamples + nonTriggeringLines diff --git a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift index 21b7cdfe0a..7b59e99812 100644 --- a/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift +++ b/Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift @@ -135,7 +135,7 @@ class RuleConfigurationTests: XCTestCase { func testSeverityLevelConfigParams() { let severityConfig = SeverityLevelsConfiguration(warning: 17, error: 7) XCTAssertEqual(severityConfig.params, [RuleParameter(severity: .error, value: 7), - RuleParameter(severity: .warning, value: 17)]) + RuleParameter(severity: .warning, value: 17)]) } func testSeverityLevelConfigPartialParams() {