Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade swiftformat and swiftlint #250

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,44 @@
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"state": {
"branch": null,
"revision": "07cad52573bad19d95844035bf0b25acddf6b0f6",
"version": "0.15.0"
"revision": "2cd0210f897fe46c6ce42f52ccfa72b3bbb621a0",
"version": "0.16.0"
}
},
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
"version": "1.2.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
"version": "1.2.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
"version": "7.3.4"
"revision": "6abeb3f5c03beba2b9e4dbe20886e773b5b629b6",
"version": "8.0.4"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "f2b5a06440ea87eba1a167cab37bf6496646c52e",
"version": "1.3.4"
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
"version": "2.2.0"
}
},
{
Expand All @@ -42,53 +60,53 @@
"repositoryURL": "https://github.com/jpsim/SourceKitten.git",
"state": {
"branch": null,
"revision": "176f04295a09324673245d8ec0afcce21ace8722",
"version": "0.22.0"
"revision": "cc1f16acc70630d27498e81078789f5fa55d7463",
"version": "0.26.0"
}
},
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat.git",
"state": {
"branch": null,
"revision": "8e0f9569415605082d0b6306f0b3dbde4facb74d",
"version": "0.39.3"
"revision": "4cd3fab23a9ca3524bcd8ef044c1c22403a8a0d2",
"version": "0.40.12"
}
},
{
"package": "SwiftLint",
"repositoryURL": "https://github.com/realm/SwiftLint.git",
"state": {
"branch": null,
"revision": "b2d428a4e24abd4f7cfeb0cd610b1656fb48c4a9",
"version": "0.30.1"
"revision": "2dcaf3ee7803e25c8163e2fbbb9b8ac2be722a2d",
"version": null
}
},
{
"package": "SwiftyTextTable",
"repositoryURL": "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state": {
"branch": null,
"revision": "7b8661865f0d9590a4b7c146237fecd99f3d8406",
"version": "0.8.2"
"revision": "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version": "0.9.0"
}
},
{
"package": "SWXMLHash",
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
"state": {
"branch": null,
"revision": "9ba116841126f6c63435beef21a4cd247c32d2e7",
"version": "4.7.6"
"revision": "a4931e5c3bafbedeb1601d3bb76bbe835c6d475a",
"version": "5.0.1"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "26ab35f50ea891e8edefcc9d975db2f6b67e1d68",
"version": "1.0.1"
"revision": "c947a306d2e80ecb2c0859047b35c73b8e1ca27f",
"version": "2.0.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PackageDescription
let package = Package(
name: "plank",
dependencies: [
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.39.3"),
.package(url: "https://github.com/realm/SwiftLint.git", from: "0.30.1"),
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.40.12"),
.package(url: "https://github.com/realm/SwiftLint.git", .revision("2dcaf3ee7803e25c8163e2fbbb9b8ac2be722a2d")),
],

targets: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/FileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public func generateFiles(urls: Set<URL>, outputDirectory: URL, generationParame
_ = loadSchemasForUrls(urls: urls)
var processedSchemas = Set<URL>([])
repeat {
_ = FileSchemaLoader.sharedInstance.refs.map({ (url: URL, schema: Schema) -> Void in
_ = FileSchemaLoader.sharedInstance.refs.map { (url: URL, schema: Schema) -> Void in
if processedSchemas.contains(url) {
return
}
Expand All @@ -499,7 +499,7 @@ public func generateFiles(urls: Set<URL>, outputDirectory: URL, generationParame
default:
assert(false, "Incorrect Schema for root.") // TODO: Better error message.
}
})
}
} while
generationParameters[.recursive] != nil && processedSchemas.count != FileSchemaLoader.sharedInstance.refs.keys.count
if generationParameters[.includeRuntime] != nil {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/JavaFileRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension JavaFileRenderer {
}
}

func unwrappedTypeFromSchema(_ param: String, _ schema: Schema) -> String {
func unwrappedTypeFromSchema(_ param: String, _ schema: Schema) -> String {
switch schema {
case .array(itemType: .none):
return "List<Object>"
Expand Down
15 changes: 7 additions & 8 deletions Sources/Core/JavaIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum JavaURIType: String, CaseIterable {
case string = "String"

static var options: String {
return allCases.map({ "\"\($0.rawValue)\"" }).joined(separator: ", ")
return allCases.map { "\"\($0.rawValue)\"" }.joined(separator: ", ")
}

var type: String {
Expand Down Expand Up @@ -327,17 +327,17 @@ public struct JavaIR {
return [
"try {",
-->`try`,
"} catch (\(`catch`.argument)) {", // TODO allow for multiple catches
"} catch (\(`catch`.argument)) {", // TODO: allow for multiple catches
-->`catch`.body,
"}",
].joined(separator: "\n")
}

struct Catch {
let argument: String
let body: [String]
}

static func switchBlock(variableToCheck: String, defaultBody: [String], cases: () -> [Case]) -> String {
return [
"switch (" + variableToCheck + ") {",
Expand All @@ -347,18 +347,17 @@ public struct JavaIR {
].joined(separator: "\n")
}


struct Case {
let variableEquals: String
let body: [String]
let shouldBreak: Bool

init(variableEquals: String, body: [String], shouldBreak: Bool = true) {
self.variableEquals = variableEquals
self.body = body
self.shouldBreak = shouldBreak
}

func render() -> [String] {
var lines = [
"case (" + variableEquals + "):",
Expand Down Expand Up @@ -446,7 +445,7 @@ public struct JavaIR {
if !innerClasses.isEmpty {
lines.append(-->innerClasses.flatMap { [""] + $0.render() })
}

if !interfaces.isEmpty {
lines.append(-->interfaces.flatMap { [""] + $0.render() })
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/JavaModelRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ public struct JavaModelRenderer: JavaFileRenderer {
}.reduce(into: []) {
$0.append(contentsOf: $1)
}

var additionalImports = propertyTypeImports
additionalImports += uriType.imports
additionalImports += (unknownPropertyLogging?.imports ?? [])
additionalImports += (decorations.imports ?? [])

let imports = [
JavaIR.Root.imports(names: Set([
"com.google.gson.Gson",
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/ObjCADTRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ extension ObjCModelRenderer {

let props = [internalTypeProp] + schemas.enumerated().map { ("value\($0)", $1) }

let properties = props.reduce([String: SchemaObjectProperty](), { (acc: [String: SchemaObjectProperty], type: (String, SchemaObjectProperty)) -> [String: SchemaObjectProperty] in
let properties = props.reduce([String: SchemaObjectProperty]()) { (acc: [String: SchemaObjectProperty], type: (String, SchemaObjectProperty)) -> [String: SchemaObjectProperty] in
var mutableDict = acc
mutableDict[type.0] = type.1
return mutableDict
})
}

let root = SchemaObjectRoot(name: adtName,
properties: properties,
Expand Down
14 changes: 7 additions & 7 deletions Sources/Core/ObjCModelRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public struct ObjCModelRenderer: ObjCFileRenderer {
let enumTypeString = enumTypeName(propertyName: param, className: className)
return ObjCIR.method("extern NSString * _Nonnull \(enumTypeString)ToString(\(enumTypeString) enumType)") { [
ObjCIR.switchStmt("enumType") {
enumValues.map({ (val) -> ObjCIR.SwitchCase in
enumValues.map { (val) -> ObjCIR.SwitchCase in
ObjCIR.caseStmt(val.objcOptionName(param: param, className: self.className)) {
["return \(val.defaultValue.objcLiteral());"]
}
})
}
},
] }
}
Expand Down Expand Up @@ -267,10 +267,10 @@ public struct ObjCModelRenderer: ObjCFileRenderer {
(.publicM, self.renderMergeWithModel()),
(.publicM, self.renderMergeWithModelWithInitType()),
(self.isBaseClass ? .publicM : .privateM, self.renderGenerateDictionary()),
] + self.renderIsSetMethods().map { (.publicM, $0) } + self.renderBooleanPropertyAccessorMethods().map { (.publicM, $0) },
] + self.renderIsSetMethods().map { (.publicM, $0) } + self.renderBooleanPropertyAccessorMethods().map { (.publicM, $0) },
properties: properties.map { param, prop in (param, typeFromSchema(param, prop), prop, .readonly) }.sorted { $0.0 < $1.0 },
protocols: protocols
),
),
ObjCIR.Root.classDecl(
name: self.builderClassName,
extends: resolveClassName(self.parentDescriptor).map { "\($0)Builder" },
Expand All @@ -280,11 +280,11 @@ public struct ObjCModelRenderer: ObjCFileRenderer {
["return [[\(self.className) alloc] initWithBuilder:self];"]
}),
(.publicM, self.renderBuilderMergeWithModel()),
] + self.renderBuilderPropertySetters().map { (.privateM, $0) },
] + self.renderBuilderPropertySetters().map { (.privateM, $0) },
properties: properties.map { param, prop in (param, typeFromSchema(param, prop), prop, .readwrite) },
protocols: [:]
),
),
ObjCIR.Root.macro("NS_ASSUME_NONNULL_END"),
]
]
}
}
8 changes: 4 additions & 4 deletions Sources/Core/ObjectiveCBuilderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ extension ObjCModelRenderer {
"if (!(self = [super initWithModel:modelObject])) { return self; }",
"struct \(self.dirtyPropertyOptionName) \(self.dirtyPropertiesIVarName) = modelObject.\(self.dirtyPropertiesIVarName);",

self.properties.map({ (param, _) -> String in
self.properties.map { (param, _) -> String in
ObjCIR.ifStmt("\(self.dirtyPropertiesIVarName).\(dirtyPropertyOption(propertyName: param, className: self.className))") {
["_\(Languages.objectiveC.snakeCaseToPropertyName(param)) = modelObject.\(Languages.objectiveC.snakeCaseToPropertyName(param));"]
}
}).joined(separator: "\n"),
}.joined(separator: "\n"),
"_\(self.dirtyPropertiesIVarName) = \(self.dirtyPropertiesIVarName);",
"return self;",
]
Expand All @@ -40,14 +40,14 @@ extension ObjCModelRenderer {
}
}

return properties.map({ (param, prop) -> ObjCIR.Method in
return properties.map { (param, prop) -> ObjCIR.Method in
ObjCIR.method("- (void)set\(Languages.objectiveC.snakeCaseToCapitalizedPropertyName(param)):(\(typeFromSchema(param, prop)))\(Languages.objectiveC.snakeCaseToPropertyName(param))") {
[
"_\(Languages.objectiveC.snakeCaseToPropertyName(param)) = \(renderBuilderPropertySetter(param, prop.schema))",
"_\(self.dirtyPropertiesIVarName).\(dirtyPropertyOption(propertyName: param, className: self.className)) = 1;",
]
}
})
}
}

func renderBuilderMergeWithModel() -> ObjCIR.Method {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Core/ObjectiveCFileGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ struct ObjCRuntimeHeaderFile: FileGenerator {
return ([self.renderCommentHeader(), "", "#import <Foundation/Foundation.h>", ""] + outputs)
.map { $0.trimmingCharacters(in: CharacterSet.whitespaces) }
.filter { $0 != "" }
.joined(separator: "\n\n") }
.joined(separator: "\n\n")
}
}

struct ObjCRuntimeImplementationFile: FileGenerator {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/ObjectiveCIR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ public struct ObjCIR {
return [
"@implementation \(className)",
methods.flatMap { $1.render() }.joined(separator: "\n"),
protocols.sorted { $0.0 < $1.0 }.flatMap({ (protocolName, methods) -> [String] in
protocols.sorted { $0.0 < $1.0 }.flatMap { (protocolName, methods) -> [String] in
["#pragma mark - \(protocolName)"] + methods.flatMap { $0.render() }
}).joined(separator: "\n"),
}.joined(separator: "\n"),
"@end",
].map { $0.trimmingCharacters(in: CharacterSet.whitespaces) }.filter { $0 != "" }
case let .category(className: className, categoryName: categoryName, methods: methods, properties: properties, variables: variables):
Expand Down
5 changes: 3 additions & 2 deletions Sources/Core/ObjectiveCNSCodingExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extension ObjCModelRenderer {
self.isBaseClass ? "" : "[super encodeWithCoder:aCoder];",
self.properties.map { ($0.0, $0.1.schema) }.map(encodeStatement).joined(separator: "\n"),
self.properties.map { (param, _) -> String in
"[aCoder encodeInt:_\(dirtyPropertiesIVarName).\(dirtyPropertyOption(propertyName: param, className: self.className)) forKey:\((param + "_dirty_property").objcLiteral())];" }.joined(separator: "\n"),
"[aCoder encodeInt:_\(dirtyPropertiesIVarName).\(dirtyPropertyOption(propertyName: param, className: self.className)) forKey:\((param + "_dirty_property").objcLiteral())];"
}.joined(separator: "\n"),
].filter { $0 != "" }
}
}
Expand Down Expand Up @@ -113,7 +114,7 @@ extension ObjCFileRenderer {
fatalError("Bad reference found in schema for class: \(className)")
}
case let .oneOf(types: schemaTypes):
return schemaTypes.map(referencedObjectClasses).reduce(Set(), { set1, set2 in set1.union(set2) })
return schemaTypes.map(referencedObjectClasses).reduce(Set()) { set1, set2 in set1.union(set2) }
}
}

Expand Down
Loading