Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
Merge #32: Fix swiftlint errors on enum names
Browse files Browse the repository at this point in the history
Fix swiftlint errors on enum names not conforming to the Swift 3 syntax.
  • Loading branch information
djbe authored May 8, 2017
2 parents d8421d3 + c4e8938 commit 436d6ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ _None_

### Internal Changes

_None_
* Fix swiftlint errors on enum names not conforming to the Swift 3 syntax.
[Liquidsoul](https://github.com/liquidsoul)
[#31](https://github.com/SwiftGen/SwiftGenKit/issues/31)

## 1.1.0

Expand Down
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
28 changes: 14 additions & 14 deletions Sources/Parsers/StringsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -28,7 +28,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()
XCTDiffContexts(result, expected: "entries.plist", sub: .strings)
Expand Down Expand Up @@ -78,44 +78,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 436d6ee

Please sign in to comment.