Skip to content

Commit f0c1de3

Browse files
authored
fix: add new keyword support and fix build (#132)
* fix: add all keywords * fix: issue template * fix: lint * chore: update lint command
1 parent 366666b commit f0c1de3

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

Core/Generator/NameGenerator.swift

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,37 @@ struct NameGenerator {
5050
/// - Parameter currentName: The current name which has to be checked.
5151
/// - Returns: New name for the variable.
5252
static func replaceKeywords(_ currentName: String) -> String {
53-
let keywordsWithReplacements = [
54-
"description": "descriptionValue",
55-
"class": "classProperty",
56-
"struct": "structProperty",
57-
"enum": "enumProperty",
58-
"internal": "internalProperty",
59-
"default": "defaultValue",
60-
]
53+
54+
/// Swift keywords from https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413 as of 2020-10-10
55+
/// Does not include the "sometimes" keywords
56+
/// Thanks to a PR from @TheMadBug.
57+
let swiftKeywords: Set = [
58+
"associatedtype", "class", "deinit",
59+
"enum", "extension", "fileprivate",
60+
"func", "import", "init",
61+
"inout", "internal", "let",
62+
"open", "operator", "private",
63+
"protocol", "public", "rethrows",
64+
"static", "struct", "subscript",
65+
"typealias", "var",
66+
"break", "case", "continue",
67+
"default", "defer", "do",
68+
"else", "fallthrough", "for",
69+
"guard", "if", "in",
70+
"repeat", "return", "switch",
71+
"where", "while",
72+
"as", "Any", "catch",
73+
"false", "is", "nil",
74+
"super", "self", "Self",
75+
"throw", "throws", "true",
76+
"try"
77+
]
78+
79+
var keywordsWithReplacements: [String: String] = [:]
80+
for keyword in swiftKeywords {
81+
keywordsWithReplacements[keyword] = "\(keyword)Value"
82+
}
83+
6184
if let value = keywordsWithReplacements[currentName] {
6285
return value
6386
}

SwiftyJSONAccelerator.xcodeproj/project.pbxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -442,6 +442,7 @@
442442
};
443443
935F7E4722F3852E0003F787 /* Swiftlint */ = {
444444
isa = PBXShellScriptBuildPhase;
445+
alwaysOutOfDate = 1;
445446
buildActionMask = 12;
446447
files = (
447448
);
@@ -456,7 +457,7 @@
456457
);
457458
runOnlyForDeploymentPostprocessing = 0;
458459
shellPath = /bin/sh;
459-
shellScript = "if which swiftlint >/dev/null; then\nswiftlint autocorrect --config .swiftlint.yml\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
460+
shellScript = "if which swiftlint >/dev/null; then\nswiftlint lint --autocorrect --config .swiftlint.yml\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
460461
};
461462
937D9DF122E8962F00A83D84 /* Swiftformat */ = {
462463
isa = PBXShellScriptBuildPhase;

SwiftyJSONAcceleratorTests/ModelGeneratorTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class ModelGeneratorTests: XCTestCase {
3939
"double_value": Double(5.3),
4040
"sub_value_four": "value",
4141
"internal": "renamed_value",
42-
"sub_value_five": ["two_level_down": "value"],
43-
],
42+
"sub_value_five": ["two_level_down": "value"]
43+
]
4444
],
4545
"value_eight": []])
4646
}

0 commit comments

Comments
 (0)