Skip to content

Commit

Permalink
Fix swiftlint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquidsoul committed May 7, 2017
1 parent ded7a47 commit c215e4d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Sources/Parsers/ColorsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum ColorsParserError: Error, CustomStringConvertible {
public var description: String {
switch self {
case .invalidHexColor(string: let string, key: let key):
let keyInfo = key.flatMap { k in " for key \"\(k)\"" } ?? ""
let keyInfo = key.flatMap { " for key \"\($0)\"" } ?? ""
return "error: Invalid hex color \"\(string)\" found\(keyInfo)."
case .invalidFile(reason: let reason):
return "error: Unable to parse file. \(reason)"
Expand Down
40 changes: 20 additions & 20 deletions Sources/Parsers/StringsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Foundation
import PathKit

public enum StringsFileParserError: Error, CustomStringConvertible {
case FailureOnLoading(path: String)
case InvalidFormat
case failureOnLoading(path: String)
case invalidFormat

public var description: String {
switch self {
case .FailureOnLoading(let path):
case .failureOnLoading(let path):
return "Failed to load a file at \"\(path)\""
case .InvalidFormat:
case .invalidFormat:
return "Invalid strings file"
}
}
Expand All @@ -33,14 +33,14 @@ public final class StringsFileParser {
// Localizable.strings files are generally UTF16, not UTF8!
public func parseFile(at path: Path) throws {
guard let data = try? path.read() else {
throw StringsFileParserError.FailureOnLoading(path: path.description)
throw StringsFileParserError.failureOnLoading(path: path.description)
}

let plist = try PropertyListSerialization
.propertyList(from: data, format: nil)

guard let dict = plist as? [String: String] else {
throw StringsFileParserError.InvalidFormat
throw StringsFileParserError.invalidFormat
}

for (key, translation) in dict {
Expand All @@ -51,31 +51,31 @@ public final class StringsFileParser {
// MARK: - Public Enum types

public enum PlaceholderType: String {
case Object = "String"
case Float = "Float"
case Int = "Int"
case Char = "Character"
case CString = "UnsafePointer<unichar>"
case Pointer = "UnsafePointer<Void>"
case Unknown = "UnsafePointer<()>"
case object = "String"
case float = "Float"
case int = "Int"
case char = "Character"
case cString = "UnsafePointer<unichar>"
case pointer = "UnsafePointer<Void>"
case unknown = "UnsafePointer<()>"

init?(formatChar char: Character) {
guard let lcChar = String(char).lowercased().characters.first else {
return nil
}
switch lcChar {
case "@":
self = .Object
self = .object
case "a", "e", "f", "g":
self = .Float
self = .float
case "d", "i", "o", "u", "x":
self = .Int
self = .int
case "c":
self = .Char
self = .char
case "s":
self = .CString
self = .cString
case "p":
self = .Pointer
self = .pointer
default:
return nil
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public final class StringsFileParser {
}
if insertionPos > 0 {
while list.count <= insertionPos-1 {
list.append(.Unknown)
list.append(.unknown)
}
list[insertionPos-1] = p
}
Expand Down
18 changes: 9 additions & 9 deletions Tests/SwiftGenKitTests/StringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StringsTests: XCTestCase {
translation: "My awesome title"))
parser.addEntry(StringsFileParser.Entry(key: "Greetings",
translation: "Hello, my name is %@ and I'm %d",
types: .Object, .Int))
types: .object, .int))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "entries.plist", sub: .strings)
Expand Down Expand Up @@ -92,44 +92,44 @@ class StringsTests: XCTestCase {

func testParseStringPlaceholder() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%@")
XCTAssertEqual(placeholders, [.Object])
XCTAssertEqual(placeholders, [.object])
}

func testParseFloatPlaceholder() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%f")
XCTAssertEqual(placeholders, [.Float])
XCTAssertEqual(placeholders, [.float])
}

func testParseDoublePlaceholders() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%g-%e")
XCTAssertEqual(placeholders, [.Float, .Float])
XCTAssertEqual(placeholders, [.float, .float])
}

func testParseFloatWithPrecisionPlaceholders() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%1.2f : %.3f : %+3f : %-6.2f")
XCTAssertEqual(placeholders, [.Float, .Float, .Float, .Float])
XCTAssertEqual(placeholders, [.float, .float, .float, .float])
}

func testParseIntPlaceholders() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%d-%i-%o-%u-%x")
XCTAssertEqual(placeholders, [.Int, .Int, .Int, .Int, .Int])
XCTAssertEqual(placeholders, [.int, .int, .int, .int, .int])
}

func testParseCCharAndStringPlaceholders() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%c-%s")
XCTAssertEqual(placeholders, [.Char, .CString])
XCTAssertEqual(placeholders, [.char, .cString])
}

func testParsePositionalPlaceholders() {
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: "%2$d-%4$f-%3$@-%c")
XCTAssertEqual(placeholders, [.Char, .Int, .Object, .Float])
XCTAssertEqual(placeholders, [.char, .int, .object, .float])
}

func testParseComplexFormatPlaceholders() {
let format = "%2$1.3d - %4$-.7f - %3$@ - %% - %5$+3c - %%"
let placeholders = StringsFileParser.PlaceholderType.placeholders(fromFormat: format)
// positions 2, 4, 3, 5 set to Int, Float, Object, Char, and position 1 not matched, defaulting to Unknown
XCTAssertEqual(placeholders, [.Unknown, .Int, .Object, .Float, .Char])
XCTAssertEqual(placeholders, [.unknown, .int, .object, .float, .char])
}

func testParseEscapePercentSign() {
Expand Down

0 comments on commit c215e4d

Please sign in to comment.