Skip to content

Commit

Permalink
Enable collection_alignment on SwiftLint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelofabri committed Sep 11, 2018
1 parent 8610f83 commit dfb4474
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .swiftlint.yml
Expand Up @@ -12,6 +12,7 @@ opt_in_rules:
- attributes
- closure_end_indentation
- closure_spacing
- collection_alignment
- contains_over_first_not_nil
- empty_count
- empty_string
Expand All @@ -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
Expand Down Expand Up @@ -51,7 +53,6 @@ opt_in_rules:
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- yoda_condition
- identical_operands

identifier_name:
excluded:
Expand Down
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Reporters/JUnitReporter.swift
Expand Up @@ -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<testcase classname='Formatting Test' name='\(fileName)\'>\n",
return [
"\n\t<testcase classname='Formatting Test' name='\(fileName)\'>\n",
"<failure message='\(reason)\'>" + message + "</failure>",
"\t</testcase>"].joined()
"\t</testcase>"
].joined()
}).joined() + "\n</testsuite></testsuites>"
}
}
10 changes: 6 additions & 4 deletions Source/SwiftLintFramework/Rules/Metrics/NestingRule.swift
Expand Up @@ -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"
]
)

Expand Down
16 changes: 11 additions & 5 deletions Source/SwiftLintFramework/Rules/Style/TrailingWhitespaceRule.swift
Expand Up @@ -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] {
Expand Down
16 changes: 10 additions & 6 deletions Tests/SwiftLintFrameworkTests/CustomRulesTests.swift
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions Tests/SwiftLintFrameworkTests/LineLengthRuleTests.swift
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftLintFrameworkTests/RuleConfigurationTests.swift
Expand Up @@ -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() {
Expand Down

0 comments on commit dfb4474

Please sign in to comment.