run swiftformat

This commit is contained in:
Yonas Kolb 2019-01-28 22:19:02 +11:00
parent ac3ba77d07
commit fb3f80d6af
12 changed files with 53 additions and 56 deletions

View File

@ -20,35 +20,35 @@ let package = Package(
], ],
targets: [ targets: [
.target(name: "XcodeGen", dependencies: [ .target(name: "XcodeGen", dependencies: [
"XcodeGenCLI", "XcodeGenCLI",
]), ]),
.target(name: "XcodeGenCLI", dependencies: [ .target(name: "XcodeGenCLI", dependencies: [
"XcodeGenKit", "XcodeGenKit",
"ProjectSpec", "ProjectSpec",
"SwiftCLI", "SwiftCLI",
"Rainbow", "Rainbow",
"PathKit", "PathKit",
]), ]),
.target(name: "XcodeGenKit", dependencies: [ .target(name: "XcodeGenKit", dependencies: [
"ProjectSpec", "ProjectSpec",
"JSONUtilities", "JSONUtilities",
"xcodeproj", "xcodeproj",
"PathKit", "PathKit",
]), ]),
.target(name: "ProjectSpec", dependencies: [ .target(name: "ProjectSpec", dependencies: [
"JSONUtilities", "JSONUtilities",
"xcodeproj", "xcodeproj",
"Yams", "Yams",
]), ]),
.testTarget(name: "XcodeGenKitTests", dependencies: [ .testTarget(name: "XcodeGenKitTests", dependencies: [
"XcodeGenKit", "XcodeGenKit",
"Spectre", "Spectre",
"PathKit", "PathKit",
]), ]),
.testTarget(name: "PerformanceTests", dependencies: [ .testTarget(name: "PerformanceTests", dependencies: [
"XcodeGenKit", "XcodeGenKit",
"Spectre", "Spectre",
"PathKit", "PathKit",
]) ]),
] ]
) )

View File

@ -49,7 +49,7 @@ extension BuildScript: JSONObjectConvertible {
outputFiles = jsonDictionary.json(atKeyPath: "outputFiles") ?? [] outputFiles = jsonDictionary.json(atKeyPath: "outputFiles") ?? []
inputFileLists = jsonDictionary.json(atKeyPath: "inputFileLists") ?? [] inputFileLists = jsonDictionary.json(atKeyPath: "inputFileLists") ?? []
outputFileLists = jsonDictionary.json(atKeyPath: "outputFileLists") ?? [] outputFileLists = jsonDictionary.json(atKeyPath: "outputFileLists") ?? []
if let string: String = jsonDictionary.json(atKeyPath: "script") { if let string: String = jsonDictionary.json(atKeyPath: "script") {
script = .script(string) script = .script(string)
} else { } else {

View File

@ -14,7 +14,7 @@ enum PathProperty {
} }
extension Array where Element == PathProperty { extension Array where Element == PathProperty {
func resolvingPaths(in jsonDictionary: JSONDictionary, relativeTo path: Path) -> JSONDictionary { func resolvingPaths(in jsonDictionary: JSONDictionary, relativeTo path: Path) -> JSONDictionary {
var result = jsonDictionary var result = jsonDictionary

View File

@ -21,7 +21,7 @@ public struct SpecFile {
} else if let dictionary = any as? JSONDictionary, } else if let dictionary = any as? JSONDictionary,
let path = dictionary["path"] as? String { let path = dictionary["path"] as? String {
self.path = Path(path) self.path = Path(path)
self.relativePaths = dictionary["relativePaths"] as? Bool ?? Include.defaultRelativePaths relativePaths = dictionary["relativePaths"] as? Bool ?? Include.defaultRelativePaths
} else { } else {
return nil return nil
} }
@ -91,8 +91,7 @@ public struct SpecFile {
return jsonDictionary.merged(onto: return jsonDictionary.merged(onto:
subSpecs subSpecs
.map { $0.mergedDictionary() } .map { $0.mergedDictionary() }
.reduce([:]) { $1.merged(onto: $0) } .reduce([:]) { $1.merged(onto: $0) })
)
} }
func resolvingPaths(relativeTo basePath: Path = Path()) -> SpecFile { func resolvingPaths(relativeTo basePath: Path = Path()) -> SpecFile {
@ -105,7 +104,7 @@ public struct SpecFile {
return SpecFile( return SpecFile(
jsonDictionary: jsonDictionary, jsonDictionary: jsonDictionary,
relativePath: self.relativePath, relativePath: self.relativePath,
subSpecs: self.subSpecs.map { $0.resolvingPaths(relativeTo: relativePath) } subSpecs: subSpecs.map { $0.resolvingPaths(relativeTo: relativePath) }
) )
} }
} }
@ -117,7 +116,7 @@ extension Dictionary where Key == String, Value: Any {
for (key, value) in self { for (key, value) in self {
if key.hasSuffix(":REPLACE") { if key.hasSuffix(":REPLACE") {
let newKey = key[key.startIndex ..< key.index(key.endIndex, offsetBy: -8)] let newKey = key[key.startIndex..<key.index(key.endIndex, offsetBy: -8)]
merged[Key(newKey)] = value merged[Key(newKey)] = value
} else if let dictionary = value as? Dictionary<Key, Value>, let base = merged[key] as? Dictionary<Key, Value> { } else if let dictionary = value as? Dictionary<Key, Value>, let base = merged[key] as? Dictionary<Key, Value> {
merged[key] = dictionary.merged(onto: base) as? Value merged[key] = dictionary.merged(onto: base) as? Value

View File

@ -48,18 +48,18 @@ func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
let bytes = valuePointer.withMemoryRebound(to: UInt8.self, capacity: totalBytes) { (bytesPointer) -> [UInt8] in let bytes = valuePointer.withMemoryRebound(to: UInt8.self, capacity: totalBytes) { (bytesPointer) -> [UInt8] in
var bytes = [UInt8](repeating: 0, count: totalBytes) var bytes = [UInt8](repeating: 0, count: totalBytes)
for j in 0 ..< min(MemoryLayout<T>.size, totalBytes) { for j in 0..<min(MemoryLayout<T>.size, totalBytes) {
bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
} }
return bytes return bytes
} }
#if swift(>=4.1) #if swift(>=4.1)
valuePointer.deinitialize(count: 1) valuePointer.deinitialize(count: 1)
valuePointer.deallocate() valuePointer.deallocate()
#else #else
valuePointer.deinitialize() valuePointer.deinitialize()
valuePointer.deallocate(capacity: 1) valuePointer.deallocate(capacity: 1)
#endif #endif
return bytes return bytes
@ -136,7 +136,7 @@ struct BytesIterator: IteratorProtocol {
mutating func next() -> ArraySlice<UInt8>? { mutating func next() -> ArraySlice<UInt8>? {
let end = min(chunkSize, data.count - offset) let end = min(chunkSize, data.count - offset)
let result = data[offset ..< offset + end] let result = data[offset..<offset + end]
offset += result.count offset += result.count
return result.count > 0 ? result : nil return result.count > 0 ? result : nil
} }
@ -222,24 +222,24 @@ class MD5: HashProtocol {
var dTemp: UInt32 = 0 var dTemp: UInt32 = 0
// Main loop // Main loop
for j in 0 ..< sines.count { for j in 0..<sines.count {
var g = 0 var g = 0
var F: UInt32 = 0 var F: UInt32 = 0
switch j { switch j {
case 0 ... 15: case 0...15:
F = (B & C) | ((~B) & D) F = (B & C) | ((~B) & D)
g = j g = j
break break
case 16 ... 31: case 16...31:
F = (D & B) | (~D & C) F = (D & B) | (~D & C)
g = (5 * j + 1) % 16 g = (5 * j + 1) % 16
break break
case 32 ... 47: case 32...47:
F = B ^ C ^ D F = B ^ C ^ D
g = (3 * j + 5) % 16 g = (3 * j + 5) % 16
break break
case 48 ... 63: case 48...63:
F = C ^ (B | (~D)) F = C ^ (B | (~D))
g = (7 * j) % 16 g = (7 * j) % 16
break break

View File

@ -319,11 +319,11 @@ class SourceGenerator {
.filter { .filter {
if $0.isDirectory { if $0.isDirectory {
let children = try $0.children() let children = try $0.children()
if children.isEmpty { if children.isEmpty {
return project.options.generateEmptyDirectories return project.options.generateEmptyDirectories
} }
return !children.filter(isIncludedPath).isEmpty return !children.filter(isIncludedPath).isEmpty
} else if $0.isFile { } else if $0.isFile {
return isIncludedPath($0) return isIncludedPath($0)

View File

@ -2,6 +2,5 @@ import Foundation
public struct FrameworkStruct { public struct FrameworkStruct {
public init() { public init() {}
}
} }

View File

@ -140,19 +140,19 @@ extension Project {
try path.mkpath() try path.mkpath()
paths.append(path) paths.append(path)
for swiftFile in 1 ... swiftFilesPerDirectory { for swiftFile in 1...swiftFilesPerDirectory {
let file = path + "file_\(swiftFile).swift" let file = path + "file_\(swiftFile).swift"
try file.write("") try file.write("")
paths.append(file) paths.append(file)
} }
for resourceFile in 1 ... resourcesPerDirectory { for resourceFile in 1...resourcesPerDirectory {
let file = path + "file_\(resourceFile).png" let file = path + "file_\(resourceFile).png"
try file.write("") try file.write("")
paths.append(file) paths.append(file)
} }
for objFile in 1 ... objFilesPerDirectory { for objFile in 1...objFilesPerDirectory {
let header = path + "file_\(objFile).h" let header = path + "file_\(objFile).h"
try header.write("") try header.write("")
paths.append(header) paths.append(header)
@ -163,7 +163,7 @@ extension Project {
} }
if depth < levels - 1 { if depth < levels - 1 {
for directory in 1 ... directoriesPerLevel { for directory in 1...directoriesPerLevel {
try createDirectory(path + "directory_\(directory)", depth: depth + 1) try createDirectory(path + "directory_\(directory)", depth: depth + 1)
} }
} }

View File

@ -184,8 +184,7 @@ class ProjectGeneratorTests: XCTestCase {
"staging": ["SETTING1": "VALUE1"], "staging": ["SETTING1": "VALUE1"],
"debug": ["SETTING2": "VALUE2"], "debug": ["SETTING2": "VALUE2"],
"Release": ["SETTING3": "VALUE3"], "Release": ["SETTING3": "VALUE3"],
] ])
)
) )
var buildSettings = project.getProjectBuildSettings(config: project.configs[1]) var buildSettings = project.getProjectBuildSettings(config: project.configs[1])
@ -563,12 +562,12 @@ class ProjectGeneratorTests: XCTestCase {
type: .stickerPack, type: .stickerPack,
platform: .iOS, platform: .iOS,
dependencies: [ dependencies: [
Dependency(type: .sdk, reference: "NotificationCenter.framework") Dependency(type: .sdk, reference: "NotificationCenter.framework"),
] ]
) )
expectedResourceFiles[stickerPack.name] = nil expectedResourceFiles[stickerPack.name] = nil
expectedLinkedFiles[stickerPack.name] = Set([ expectedLinkedFiles[stickerPack.name] = Set([
"NotificationCenter.framework" "NotificationCenter.framework",
]) ])
let targets = [app, iosFrameworkZ, staticLibrary, resourceBundle, iosFrameworkA, iosFrameworkB, appTest, appTestWithoutTransitive, stickerPack] let targets = [app, iosFrameworkZ, staticLibrary, resourceBundle, iosFrameworkA, iosFrameworkB, appTest, appTestWithoutTransitive, stickerPack]

View File

@ -277,7 +277,7 @@ class SourceGeneratorTests: XCTestCase {
] ]
let target = Target(name: "Test", type: .application, platform: .iOS, sources: [TargetSource(path: "Sources", excludes: excludes)]) let target = Target(name: "Test", type: .application, platform: .iOS, sources: [TargetSource(path: "Sources", excludes: excludes)])
func test(generateEmptyDirectories: Bool) throws { func test(generateEmptyDirectories: Bool) throws {
let options = SpecOptions(generateEmptyDirectories: generateEmptyDirectories) let options = SpecOptions(generateEmptyDirectories: generateEmptyDirectories)
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options) let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options)
@ -307,7 +307,7 @@ class SourceGeneratorTests: XCTestCase {
// try pbxProj.expectFileMissing(paths: ["Sources", "A", "a.ignored"]) // try pbxProj.expectFileMissing(paths: ["Sources", "A", "a.ignored"])
// try pbxProj.expectFileMissing(paths: ["Sources", "A", "B", "b.ignored"]) // try pbxProj.expectFileMissing(paths: ["Sources", "A", "B", "b.ignored"])
} }
try test(generateEmptyDirectories: false) try test(generateEmptyDirectories: false)
try test(generateEmptyDirectories: true) try test(generateEmptyDirectories: true)
} }
@ -379,7 +379,7 @@ class SourceGeneratorTests: XCTestCase {
"Sources/A/b.swift", "Sources/A/b.swift",
"Sources/F/G/h.swift", "Sources/F/G/h.swift",
"../OtherDirectory/C/D/e.swift", "../OtherDirectory/C/D/e.swift",
TargetSource(path: "Sources/B", createIntermediateGroups: false) TargetSource(path: "Sources/B", createIntermediateGroups: false),
]) ])
let options = SpecOptions(createIntermediateGroups: true) let options = SpecOptions(createIntermediateGroups: true)
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options) let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options)

View File

@ -347,7 +347,7 @@ class SpecLoadingTests: XCTestCase {
"type": "framework", "type": "framework",
"platform": "tvOS", "platform": "tvOS",
"deploymentTarget": "1.1.0", "deploymentTarget": "1.1.0",
"configFiles": ["debug": "Configs/$target_name/debug.xcconfig"] "configFiles": ["debug": "Configs/$target_name/debug.xcconfig"],
], ],
], ],
]) ])
@ -559,7 +559,7 @@ class SpecLoadingTests: XCTestCase {
["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file", "file2"], "outputFiles": ["file", "file2"], "shell": "bin/customshell", "runOnlyWhenInstalling": true], ["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file", "file2"], "outputFiles": ["file", "file2"], "shell": "bin/customshell", "runOnlyWhenInstalling": true],
["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file", "file2"], "outputFiles": ["file", "file2"], "shell": "bin/customshell", "showEnvVars": false], ["script": "shell script\ndo thing", "name": "myscript", "inputFiles": ["file", "file2"], "outputFiles": ["file", "file2"], "shell": "bin/customshell", "showEnvVars": false],
["script": "shell script\nwith file lists", "name": "myscript", "inputFileLists": ["inputList.xcfilelist"], "outputFileLists": ["outputList.xcfilelist"], "shell": "bin/customshell", "runOnlyWhenInstalling": true], ["script": "shell script\nwith file lists", "name": "myscript", "inputFileLists": ["inputList.xcfilelist"], "outputFileLists": ["outputList.xcfilelist"], "shell": "bin/customshell", "runOnlyWhenInstalling": true],
["script": "shell script\nwith file lists", "name": "myscript", "inputFileLists": ["inputList.xcfilelist"], "outputFileLists": ["outputList.xcfilelist"], "shell": "bin/customshell", "showEnvVars": false] ["script": "shell script\nwith file lists", "name": "myscript", "inputFileLists": ["inputList.xcfilelist"], "outputFileLists": ["outputList.xcfilelist"], "shell": "bin/customshell", "showEnvVars": false],
] ]
target["preBuildScripts"] = scripts target["preBuildScripts"] = scripts
target["postCompileScripts"] = scripts target["postCompileScripts"] = scripts

View File

@ -14,7 +14,7 @@ public func firstDifferenceBetweenStrings(_ s1: String, _ s2: String) -> FirstDi
let lenMin = min(len1, len2) let lenMin = min(len1, len2)
for i in 0 ..< lenMin { for i in 0..<lenMin {
if (s1 as NSString).character(at: i) != (s2 as NSString).character(at: i) { if (s1 as NSString).character(at: i) != (s2 as NSString).character(at: i) {
return .DifferenceAtIndex(i) return .DifferenceAtIndex(i)
} }