Add SwiftLint (#49)

This change adds SwiftLint to the project. For now, the rules are tweaked
to match the current state of the code base — but will over time be changed
back to their defaults in several cases.

Some smaller changes (mostly related to code style) were applied to the
project to remove all warnings.
This commit is contained in:
John Sundell 2019-03-11 14:52:46 +01:00 committed by GitHub
parent 892d6ae39c
commit 8bc46cbeb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 81 additions and 72 deletions

7
.swiftlint.yml Normal file
View File

@ -0,0 +1,7 @@
disabled_rules:
- nesting
line_length: 200
function_body_length: 100
type_body_length: 600
file_length: 800
cyclomatic_complexity: 15

View File

@ -11,7 +11,7 @@ import PackageDescription
let package = Package(
name: "Splash",
products: [
.library(name: "Splash", targets: ["Splash"])
.library(name: "Splash", targets: ["Splash"])
],
targets: [
.target(name: "Splash"),

View File

@ -59,7 +59,7 @@ private extension NSMutableAttributedString {
.foregroundColor: color,
.font: font
])
append(attributedString)
}
}

View File

@ -19,15 +19,15 @@ public extension Theme {
blue: 0.74
),
tokenColors: [
.keyword : Color(red: 0.91, green: 0.2, blue: 0.54),
.string : Color(red: 0.98, green: 0.39, blue: 0.12),
.type : Color(red: 0.51, green: 0.51, blue: 0.79),
.call : Color(red: 0.2, green: 0.56, blue: 0.9),
.number : Color(red: 0.86, green: 0.44, blue: 0.34),
.comment : Color(red: 0.42, green: 0.54, blue: 0.58),
.property : Color(red: 0.13, green: 0.67, blue: 0.62),
.dotAccess : Color(red: 0.57, green: 0.7, blue: 0),
.preprocessing : Color(red: 0.71, green: 0.54, blue: 0)
.keyword: Color(red: 0.91, green: 0.2, blue: 0.54),
.string: Color(red: 0.98, green: 0.39, blue: 0.12),
.type: Color(red: 0.51, green: 0.51, blue: 0.79),
.call: Color(red: 0.2, green: 0.56, blue: 0.9),
.number: Color(red: 0.86, green: 0.44, blue: 0.34),
.comment: Color(red: 0.42, green: 0.54, blue: 0.58),
.property: Color(red: 0.13, green: 0.67, blue: 0.62),
.dotAccess: Color(red: 0.57, green: 0.7, blue: 0),
.preprocessing: Color(red: 0.71, green: 0.54, blue: 0)
],
backgroundColor: Color(
red: 0.098,
@ -47,15 +47,15 @@ public extension Theme {
blue: 1
),
tokenColors: [
.keyword : Color(red: 0.828, green: 0.095, blue: 0.583),
.string : Color(red: 1.0, green: 0.171, blue: 0.219),
.type : Color(red: 0.137, green: 1.0, blue: 0.512),
.call : Color(red: 0.137, green: 1.0, blue: 0.512),
.number : Color(red: 0.469, green: 0.426, blue: 1.00),
.comment : Color(red: 0.255, green: 0.801, blue: 0.27),
.property : Color(red: 0.431, green: 0.714, blue: 0.533),
.dotAccess : Color(red: 0.431, green: 0.714, blue: 0.533),
.preprocessing : Color(red: 0.896, green: 0.488, blue: 0.284)
.keyword: Color(red: 0.828, green: 0.095, blue: 0.583),
.string: Color(red: 1.0, green: 0.171, blue: 0.219),
.type: Color(red: 0.137, green: 1.0, blue: 0.512),
.call: Color(red: 0.137, green: 1.0, blue: 0.512),
.number: Color(red: 0.469, green: 0.426, blue: 1.00),
.comment: Color(red: 0.255, green: 0.801, blue: 0.27),
.property: Color(red: 0.431, green: 0.714, blue: 0.533),
.dotAccess: Color(red: 0.431, green: 0.714, blue: 0.533),
.preprocessing: Color(red: 0.896, green: 0.488, blue: 0.284)
],
backgroundColor: Color(
red: 0,
@ -75,15 +75,15 @@ public extension Theme {
blue: 0.84
),
tokenColors: [
.keyword : Color(red: 0.992, green: 0.791, blue: 0.45),
.string : Color(red: 0.966, green: 0.517, blue: 0.29),
.type : Color(red: 0.431, green: 0.714, blue: 0.533),
.call : Color(red: 0.431, green: 0.714, blue: 0.533),
.number : Color(red: 0.559, green: 0.504, blue: 0.745),
.comment : Color(red: 0.484, green: 0.483, blue: 0.504),
.property : Color(red: 0.431, green: 0.714, blue: 0.533),
.dotAccess : Color(red: 0.431, green: 0.714, blue: 0.533),
.preprocessing : Color(red: 0.992, green: 0.791, blue: 0.45)
.keyword: Color(red: 0.992, green: 0.791, blue: 0.45),
.string: Color(red: 0.966, green: 0.517, blue: 0.29),
.type: Color(red: 0.431, green: 0.714, blue: 0.533),
.call: Color(red: 0.431, green: 0.714, blue: 0.533),
.number: Color(red: 0.559, green: 0.504, blue: 0.745),
.comment: Color(red: 0.484, green: 0.483, blue: 0.504),
.property: Color(red: 0.431, green: 0.714, blue: 0.533),
.dotAccess: Color(red: 0.431, green: 0.714, blue: 0.533),
.preprocessing: Color(red: 0.992, green: 0.791, blue: 0.45)
],
backgroundColor: Color(
red: 0.18,
@ -103,15 +103,15 @@ public extension Theme {
blue: 1
),
tokenColors: [
.keyword : Color(red: 0.948, green: 0.140, blue: 0.547),
.string : Color(red: 0.988, green: 0.273, blue: 0.317),
.type : Color(red: 0.584, green: 0.898, blue: 0.361),
.call : Color(red: 0.584, green: 0.898, blue: 0.361),
.number : Color(red: 0.587, green: 0.517, blue: 0.974),
.comment : Color(red: 0.424, green: 0.475, blue: 0.529),
.property : Color(red: 0.584, green: 0.898, blue: 0.361),
.dotAccess : Color(red: 0.584, green: 0.898, blue: 0.361),
.preprocessing : Color(red: 0.952, green: 0.526, blue: 0.229)
.keyword: Color(red: 0.948, green: 0.140, blue: 0.547),
.string: Color(red: 0.988, green: 0.273, blue: 0.317),
.type: Color(red: 0.584, green: 0.898, blue: 0.361),
.call: Color(red: 0.584, green: 0.898, blue: 0.361),
.number: Color(red: 0.587, green: 0.517, blue: 0.974),
.comment: Color(red: 0.424, green: 0.475, blue: 0.529),
.property: Color(red: 0.584, green: 0.898, blue: 0.361),
.dotAccess: Color(red: 0.584, green: 0.898, blue: 0.361),
.preprocessing: Color(red: 0.952, green: 0.526, blue: 0.229)
],
backgroundColor: Color(
red: 0.163,
@ -131,15 +131,15 @@ public extension Theme {
blue: 0
),
tokenColors: [
.keyword : Color(red: 0.161, green: 0.259, blue: 0.467),
.string : Color(red: 0.875, green: 0.027, blue: 0.0),
.type : Color(red: 0.706, green: 0.27, blue: 0.0),
.call : Color(red: 0.278, green: 0.415, blue: 0.593),
.number : Color(red: 0.161, green: 0.259, blue: 0.467),
.comment : Color(red: 0.765, green: 0.455, blue: 0.11),
.property : Color(red: 0.278, green: 0.415, blue: 0.593),
.dotAccess : Color(red: 0.278, green: 0.415, blue: 0.593),
.preprocessing : Color(red: 0.392, green: 0.391, blue: 0.52)
.keyword: Color(red: 0.161, green: 0.259, blue: 0.467),
.string: Color(red: 0.875, green: 0.027, blue: 0.0),
.type: Color(red: 0.706, green: 0.27, blue: 0.0),
.call: Color(red: 0.278, green: 0.415, blue: 0.593),
.number: Color(red: 0.161, green: 0.259, blue: 0.467),
.comment: Color(red: 0.765, green: 0.455, blue: 0.11),
.property: Color(red: 0.278, green: 0.415, blue: 0.593),
.dotAccess: Color(red: 0.278, green: 0.415, blue: 0.593),
.preprocessing: Color(red: 0.392, green: 0.391, blue: 0.52)
],
backgroundColor: Color(
red: 1,
@ -159,15 +159,15 @@ public extension Theme {
blue: 0
),
tokenColors: [
.keyword : Color(red: 0.706, green: 0.0, blue: 0.384),
.string : Color(red: 0.729, green: 0.0, blue: 0.067),
.type : Color(red: 0.267, green: 0.537, blue: 0.576),
.call : Color(red: 0.267, green: 0.537, blue: 0.576),
.number : Color(red: 0.0, green: 0.043, blue: 1.0),
.comment : Color(red: 0.336, green: 0.376, blue: 0.42),
.property : Color(red: 0.267, green: 0.537, blue: 0.576),
.dotAccess : Color(red: 0.267, green: 0.537, blue: 0.576),
.preprocessing : Color(red: 0.431, green: 0.125, blue: 0.051)
.keyword: Color(red: 0.706, green: 0.0, blue: 0.384),
.string: Color(red: 0.729, green: 0.0, blue: 0.067),
.type: Color(red: 0.267, green: 0.537, blue: 0.576),
.call: Color(red: 0.267, green: 0.537, blue: 0.576),
.number: Color(red: 0.0, green: 0.043, blue: 1.0),
.comment: Color(red: 0.336, green: 0.376, blue: 0.42),
.property: Color(red: 0.267, green: 0.537, blue: 0.576),
.dotAccess: Color(red: 0.267, green: 0.537, blue: 0.576),
.preprocessing: Color(red: 0.431, green: 0.125, blue: 0.051)
],
backgroundColor: Color(
red: 1,

View File

@ -19,9 +19,12 @@ public struct Theme {
/// What color to use for the background
public var backgroundColor: Color
/// What color to use for the text's highlighted tokens
public var tokenColors: [TokenType : Color]
public var tokenColors: [TokenType: Color]
public init(font: Font, plainTextColor: Color, tokenColors: [TokenType : Color], backgroundColor: Color = Color(white: 0.12, alpha: 1)) {
public init(font: Font,
plainTextColor: Color,
tokenColors: [TokenType: Color],
backgroundColor: Color = Color(white: 0.12, alpha: 1)) {
self.font = font
self.plainTextColor = plainTextColor
self.tokenColors = tokenColors

View File

@ -27,7 +27,7 @@ public extension Segment {
/// All tokens that have been found so far (excluding the current one)
public var all: [String]
/// The number of times a given token has been found up until this point
public var counts: [String : Int]
public var counts: [String: Int]
/// The tokens that were previously found on the same line as the current one
public var onSameLine: [String]
/// The token that was previously found (may be on a different line)

View File

@ -42,7 +42,7 @@ private extension Tokenizer {
private let code: String
private let delimiters: CharacterSet
private var index: String.Index?
private var tokenCounts = [String : Int]()
private var tokenCounts = [String: Int]()
private var allTokens = [String]()
private var lineTokens = [String]()
private var segments: (current: Segment?, previous: Segment?)

View File

@ -598,10 +598,10 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testDeferDeclaration() {
let components = highlighter.highlight("func hello() { defer {} }")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),
@ -616,10 +616,10 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testFunctionDeclarationWithInOutParameter() {
let components = highlighter.highlight("func swapValues(value1: inout Int, value2: inout Int) { }")
XCTAssertEqual(components, [
.token("func", .keyword),
.whitespace(" "),

View File

@ -134,7 +134,7 @@ final class StatementTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testSwitchStatementWithFallthrough() {
let components = highlighter.highlight("""
switch variable {
@ -143,7 +143,7 @@ final class StatementTests: SyntaxHighlighterTestCase {
callB()
}
""")
XCTAssertEqual(components, [
.token("switch", .keyword),
.whitespace(" "),
@ -260,10 +260,10 @@ final class StatementTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testForStatementWithContinue() {
let components = highlighter.highlight("for value in Enum.allCases { continue }")
XCTAssertEqual(components, [
.token("for", .keyword),
.whitespace(" "),
@ -277,12 +277,12 @@ final class StatementTests: SyntaxHighlighterTestCase {
.whitespace(" "),
.plainText("{"),
.whitespace(" "),
.token("continue",.keyword),
.token("continue", .keyword),
.whitespace(" "),
.plainText("}")
])
}
func testRepeatWhileStatement() {
let components = highlighter.highlight("""
var x = 5
@ -291,7 +291,7 @@ final class StatementTests: SyntaxHighlighterTestCase {
x = x - 1
} while x > 1
""")
XCTAssertEqual(components, [
.token("var", .keyword),
.whitespace(" "),

View File

@ -29,4 +29,3 @@ extension TokenTypeTests {
]
}
}