mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
* Add Example wrapper in order to display test failures inline when running in Xcode. * Stop using Swift 5.1-only features so we can compile on Xcode 10.2. * Wrap strings in Example. * Add Changelog entry. * Wrap all examples in Example struct. * Better and more complete capturing of line numbers. * Fix broken test. * Better test traceability. * Address or disable linting warnings. * Add documentation comments. * Disable linter for a few cases. * Limit mutability and add copy-and-mutate utility functions. * Limit scope of mutability.
144 lines
8.4 KiB
Swift
144 lines
8.4 KiB
Swift
import SwiftLintFramework
|
|
import XCTest
|
|
|
|
class ColonRuleTests: XCTestCase {
|
|
func testColonWithDefaultConfiguration() {
|
|
// Verify Colon rule with test values for when flexible_right_spacing
|
|
// is false (default).
|
|
verifyRule(ColonRule.description)
|
|
}
|
|
|
|
// swiftlint:disable:next function_body_length
|
|
func testColonWithFlexibleRightSpace() {
|
|
// Verify Colon rule with test values for when flexible_right_spacing
|
|
// is true.
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
Example("let abc: Void\n"),
|
|
Example("let abc: (Void, String, Int)\n"),
|
|
Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("func abc(def: Void) {}\n"),
|
|
Example("let abc = [Void: Void]()\n")
|
|
]
|
|
let triggeringExamples: [Example] = [
|
|
Example("let ↓abc:Void\n"),
|
|
Example("let ↓abc :Void\n"),
|
|
Example("let ↓abc : Void\n"),
|
|
Example("let ↓abc : [Void: Void]\n"),
|
|
Example("let ↓abc : (Void, String, Int)\n"),
|
|
Example("let ↓abc : ([Void], String, Int)\n"),
|
|
Example("let ↓abc : [([Void], String, Int)]\n"),
|
|
Example("let ↓abc :String=\"def\"\n"),
|
|
Example("let ↓abc :Int=0\n"),
|
|
Example("let ↓abc :Int = 0\n"),
|
|
Example("let ↓abc:Int=0\n"),
|
|
Example("let ↓abc:Int = 0\n"),
|
|
Example("let ↓abc:Enum=Enum.Value\n"),
|
|
Example("func abc(↓def:Void) {}\n"),
|
|
Example("func abc(↓def :Void) {}\n"),
|
|
Example("func abc(↓def : Void) {}\n"),
|
|
Example("func abc(def: Void, ↓ghi :Void) {}\n"),
|
|
Example("let abc = [Void↓:Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n")
|
|
]
|
|
let corrections: [Example: Example] = [
|
|
Example("let ↓abc:Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc :Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc : Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc : [Void: Void]\n"): Example("let abc: [Void: Void]\n"),
|
|
Example("let ↓abc : (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let ↓abc : ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let ↓abc : [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let ↓abc :String=\"def\"\n"): Example("let abc: String=\"def\"\n"),
|
|
Example("let ↓abc :Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let ↓abc :Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let ↓abc:Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let ↓abc:Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let ↓abc:Enum=Enum.Value\n"): Example("let abc: Enum=Enum.Value\n"),
|
|
Example("func abc(↓def:Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(↓def :Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(↓def : Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def: Void, ↓ghi :Void) {}\n"): Example("func abc(def: Void, ghi: Void) {}\n"),
|
|
Example("let abc = [Void↓:Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void↓ : Void]()\n"): Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"): Example("let abc = [1: [3: 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3↓ : 2], 3: 4]\n"): Example("let abc = [1: [3: 2], 3: 4]\n")
|
|
]
|
|
let description = ColonRule.description.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(corrections: corrections)
|
|
|
|
verifyRule(description, ruleConfiguration: ["flexible_right_spacing": true])
|
|
}
|
|
|
|
// swiftlint:disable:next function_body_length
|
|
func testColonWithoutApplyToDictionaries() {
|
|
let nonTriggeringExamples = ColonRule.description.nonTriggeringExamples + [
|
|
Example("let abc = [Void:Void]()\n"),
|
|
Example("let abc = [Void : Void]()\n"),
|
|
Example("let abc = [Void: Void]()\n"),
|
|
Example("let abc = [Void : Void]()\n"),
|
|
Example("let abc = [1: [3 : 2], 3: 4]\n"),
|
|
Example("let abc = [1: [3 : 2], 3: 4]\n")
|
|
]
|
|
let triggeringExamples: [Example] = [
|
|
Example("let ↓abc:Void\n"),
|
|
Example("let ↓abc: Void\n"),
|
|
Example("let ↓abc :Void\n"),
|
|
Example("let ↓abc : Void\n"),
|
|
Example("let ↓abc : [Void: Void]\n"),
|
|
Example("let ↓abc : (Void, String, Int)\n"),
|
|
Example("let ↓abc : ([Void], String, Int)\n"),
|
|
Example("let ↓abc : [([Void], String, Int)]\n"),
|
|
Example("let ↓abc: (Void, String, Int)\n"),
|
|
Example("let ↓abc: ([Void], String, Int)\n"),
|
|
Example("let ↓abc: [([Void], String, Int)]\n"),
|
|
Example("let ↓abc :String=\"def\"\n"),
|
|
Example("let ↓abc :Int=0\n"),
|
|
Example("let ↓abc :Int = 0\n"),
|
|
Example("let ↓abc:Int=0\n"),
|
|
Example("let ↓abc:Int = 0\n"),
|
|
Example("let ↓abc:Enum=Enum.Value\n"),
|
|
Example("func abc(↓def:Void) {}\n"),
|
|
Example("func abc(↓def: Void) {}\n"),
|
|
Example("func abc(↓def :Void) {}\n"),
|
|
Example("func abc(↓def : Void) {}\n"),
|
|
Example("func abc(def: Void, ↓ghi :Void) {}\n")
|
|
]
|
|
let corrections: [Example: Example] = [
|
|
Example("let ↓abc:Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc: Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc :Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc : Void\n"): Example("let abc: Void\n"),
|
|
Example("let ↓abc : [Void: Void]\n"): Example("let abc: [Void: Void]\n"),
|
|
Example("let ↓abc : (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let ↓abc : ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let ↓abc : [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let ↓abc: (Void, String, Int)\n"): Example("let abc: (Void, String, Int)\n"),
|
|
Example("let ↓abc: ([Void], String, Int)\n"): Example("let abc: ([Void], String, Int)\n"),
|
|
Example("let ↓abc: [([Void], String, Int)]\n"): Example("let abc: [([Void], String, Int)]\n"),
|
|
Example("let ↓abc :String=\"def\"\n"): Example("let abc: String=\"def\"\n"),
|
|
Example("let ↓abc :Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let ↓abc :Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let ↓abc:Int=0\n"): Example("let abc: Int=0\n"),
|
|
Example("let ↓abc:Int = 0\n"): Example("let abc: Int = 0\n"),
|
|
Example("let ↓abc:Enum=Enum.Value\n"): Example("let abc: Enum=Enum.Value\n"),
|
|
Example("func abc(↓def:Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(↓def: Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(↓def :Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(↓def : Void) {}\n"): Example("func abc(def: Void) {}\n"),
|
|
Example("func abc(def: Void, ↓ghi :Void) {}\n"): Example("func abc(def: Void, ghi: Void) {}\n")
|
|
]
|
|
|
|
let description = ColonRule.description.with(triggeringExamples: triggeringExamples)
|
|
.with(nonTriggeringExamples: nonTriggeringExamples)
|
|
.with(corrections: corrections)
|
|
|
|
verifyRule(description, ruleConfiguration: ["apply_to_dictionaries": false])
|
|
}
|
|
}
|