Skip to content

Commit ea0d803

Browse files
committed
Let Xcode fix indentation
1 parent 70f9630 commit ea0d803

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

Scripts/BuildPhases/LintAppLocalizedStringsUsage.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import Foundation
66
class Xcodeproj {
77
let projectURL: URL // points to the "<projectDirectory>/<projectName>.xcodeproj/project.pbxproj" file
88
private let pbxproj: PBXProjFile
9-
9+
1010
/// Semantic type for strings that correspond to an object' UUID in the `pbxproj` file
1111
typealias ObjectUUID = String
12-
12+
1313
/// Builds an `Xcodeproj` instance by parsing the `.xcodeproj` or `.pbxproj` file at the provided URL.
1414
init(url: URL) throws {
1515
projectURL = url.pathExtension == "xcodeproj" ? URL(fileURLWithPath: "project.pbxproj", relativeTo: url) : url
1616
let data = try Data(contentsOf: projectURL)
1717
let decoder = PropertyListDecoder()
1818
pbxproj = try decoder.decode(PBXProjFile.self, from: data)
1919
}
20-
20+
2121
/// An internal mapping listing the parent ObjectUUID for each ObjectUUID.
2222
/// - Built by recursing top-to-bottom in the various `PBXGroup` objects of the project to visit all the children objects,
2323
/// and storing which parent object they belong to.
@@ -43,14 +43,14 @@ extension Xcodeproj {
4343
convenience init(path: String) throws {
4444
try self.init(url: URL(fileURLWithPath: path))
4545
}
46-
47-
/// The directory where the `.xcodeproj` resides.
46+
47+
/// The directory where the `.xcodeproj` resides.
4848
var projectDirectory: URL { projectURL.deletingLastPathComponent().deletingLastPathComponent() }
4949
/// The list of `PBXNativeTarget` targets in the project. Convenience getter for `PBXProjFile.nativeTargets`
5050
var nativeTargets: [PBXNativeTarget] { pbxproj.nativeTargets }
5151
/// The list of `PBXBuildFile` files a given `PBXNativeTarget` will build. Convenience getter for `PBXProjFile.buildFiles(for:)`
5252
func buildFiles(for target: PBXNativeTarget) -> [PBXBuildFile] { pbxproj.buildFiles(for: target) }
53-
53+
5454
/// Finds the full path / URL of a `PBXBuildFile` based on the groups it belongs to and their `sourceTree` attribute
5555
func resolveURL(to buildFile: PBXBuildFile) throws -> URL? {
5656
if let fileRefID = buildFile.fileRef, let fileRefObject = try? self.pbxproj.object(id: fileRefID) as PBXFileReference {
@@ -62,11 +62,11 @@ extension Xcodeproj {
6262
return nil // just skip those (but don't throw — those are valid use cases in any pbxproj, just ones we don't care about)
6363
}
6464
}
65-
65+
6666
/// Finds the full path / URL of a PBXReference (`PBXFileReference` of `PBXGroup`) based on the groups it belongs to and their `sourceTree` attribute
6767
private func resolveURL<T: PBXReference>(objectUUID: ObjectUUID, object: T) throws -> URL? {
6868
if objectUUID == self.pbxproj.rootProject.mainGroup { return URL(fileURLWithPath: ".", relativeTo: projectDirectory) }
69-
69+
7070
switch object.sourceTree {
7171
case .absolute:
7272
guard let path = object.path else { throw ProjectInconsistencyError.incorrectAbsolutePath(id: objectUUID) }
@@ -89,7 +89,7 @@ extension Xcodeproj {
8989

9090
/// "Parent" type for all the PBX... types of objects encountered in a pbxproj
9191
protocol PBXObject: Decodable {
92-
static var isa: String { get}
92+
static var isa: String { get }
9393
}
9494
extension PBXObject {
9595
static var isa: String { String(describing: self) }
@@ -110,7 +110,7 @@ extension Xcodeproj {
110110
case unexpectedObjectType(id: ObjectUUID, expectedType: Any.Type, found: PBXObject)
111111
case incorrectAbsolutePath(id: ObjectUUID)
112112
case orphanObject(id: ObjectUUID, object: PBXObject)
113-
113+
114114
var description: String {
115115
switch self {
116116
case .objectNotFound(id: let id):
@@ -129,9 +129,9 @@ extension Xcodeproj {
129129
struct PBXProjFile: Decodable {
130130
let rootObject: ObjectUUID
131131
let objects: [String: PBXObjectWrapper]
132-
132+
133133
// Convenience methods
134-
134+
135135
/// Returns the `PBXObject` instance with the given `ObjectUUID`, by looking it up in the list of `objects` registered in the project.
136136
func object<T: PBXObject>(id: ObjectUUID) throws -> T {
137137
guard let wrapped = objects[id] else { throw ProjectInconsistencyError.objectNotFound(id: id) }
@@ -140,35 +140,35 @@ extension Xcodeproj {
140140
}
141141
return obj
142142
}
143-
143+
144144
/// Returns the `PBXObject` instance with the given `ObjectUUID`, by looking it up in the list of `objects` registered in the project.
145145
func object<T: PBXObject>(id: ObjectUUID) -> T? {
146146
try? object(id: id) as T
147147
}
148-
148+
149149
/// The `PBXProject` corresponding to the `rootObject` of the project file.
150150
var rootProject: PBXProject { try! object(id: rootObject) }
151-
151+
152152
/// The `PBXGroup` corresponding to the main groop serving as root for the whole hierarchy of files and groups in the project.
153153
var mainGroup: PBXGroup { try! object(id: rootProject.mainGroup) }
154-
154+
155155
/// The list of `PBXNativeTarget` targets found in the project.
156156
var nativeTargets: [PBXNativeTarget] { rootProject.targets.compactMap(object(id:)) }
157-
157+
158158
/// The list of `PBXBuildFile` build file references included in a given target.
159159
func buildFiles(for target: PBXNativeTarget) -> [PBXBuildFile] {
160160
guard let sourceBuildPhase: PBXSourcesBuildPhase = target.buildPhases.lazy.compactMap(object(id:)).first else { return [] }
161161
return sourceBuildPhase.files.compactMap(object(id:)) as [PBXBuildFile]
162162
}
163163
}
164-
164+
165165
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
166166
/// Represents the root project object.
167167
struct PBXProject: PBXObject {
168168
let mainGroup: ObjectUUID
169169
let targets: [ObjectUUID]
170170
}
171-
171+
172172
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
173173
/// Represents a native target (i.e. a target building an app, app extension, bundle...).
174174
/// - note: Does not represent other types of targets like `PBXAggregateTarget`, only native ones.
@@ -186,20 +186,20 @@ extension Xcodeproj {
186186
case framework = "com.apple.product-type.framework"
187187
}
188188
}
189-
189+
190190
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
191191
/// Represents a "Compile Sources" build phase containing a list of files to compile.
192192
/// - note: Does not represent other types of Build Phases that could exist in the project, only "Compile Sources" one
193193
struct PBXSourcesBuildPhase: PBXObject {
194194
let files: [ObjectUUID]
195195
}
196-
196+
197197
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
198198
/// Represents a single build file in a `PBXSourcesBuildPhase` build phase.
199199
struct PBXBuildFile: PBXObject {
200200
let fileRef: ObjectUUID?
201201
}
202-
202+
203203
/// This type is used to indicate what a file reference in the project is actually relative to
204204
enum SourceTree: String, Decodable, CustomStringConvertible {
205205
case absolute = "<absolute>"
@@ -210,15 +210,15 @@ extension Xcodeproj {
210210
case sdkDir = "SDKROOT"
211211
var description: String { rawValue }
212212
}
213-
213+
214214
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
215215
/// Represents a reference to a file contained in the project tree.
216216
struct PBXFileReference: PBXReference {
217217
let name: String?
218218
let path: String?
219219
let sourceTree: SourceTree
220220
}
221-
221+
222222
/// One of the many `PBXObject` types encountered in the `.pbxproj` file format.
223223
/// Represents a group (aka "folder") contained in the project tree.
224224
struct PBXGroup: PBXReference {
@@ -227,17 +227,17 @@ extension Xcodeproj {
227227
let sourceTree: SourceTree
228228
let children: [ObjectUUID]
229229
}
230-
230+
231231
/// Fallback type for any unknown `PBXObject` type.
232232
struct UnknownPBXObject: PBXObject {
233233
let isa: String
234234
}
235-
235+
236236
/// Wrapper helper to decode any `PBXObject` based on the value of their `isa` field
237237
@propertyWrapper
238238
struct PBXObjectWrapper: Decodable, CustomDebugStringConvertible {
239239
let wrappedValue: PBXObject
240-
240+
241241
static let knownTypes: [PBXObject.Type] = [
242242
PBXProject.self,
243243
PBXGroup.self,
@@ -246,14 +246,14 @@ extension Xcodeproj {
246246
PBXSourcesBuildPhase.self,
247247
PBXBuildFile.self
248248
]
249-
249+
250250
init(from decoder: Decoder) throws {
251251
let untypedObject = try UnknownPBXObject(from: decoder)
252252
if let objectType = Self.knownTypes.first(where: { $0.isa == untypedObject.isa }) {
253253
self.wrappedValue = try objectType.init(from: decoder)
254-
} else {
254+
} else {
255255
self.wrappedValue = untypedObject
256-
}
256+
}
257257
}
258258
var debugDescription: String { String(describing: wrappedValue) }
259259
}
@@ -276,7 +276,7 @@ func lint(fileAt url: URL, targetName: String) throws -> LintResult {
276276
lineNo += 1
277277
guard line.range(of: "\\s*//", options: .regularExpression) == nil else { return } // Skip commented lines
278278
guard let range = line.range(of: "NSLocalizedString") else { return }
279-
279+
280280
let colNo = line.distance(from: line.startIndex, to: range.lowerBound)
281281
let message = "Use `AppLocalizedString` instead of `NSLocalizedString` in source files that are used in the `\(targetName)` extension target. See paNNhX-nP-p2 for more info."
282282
print("\(url.path):\(lineNo):\(colNo): error: \(message)")
@@ -294,7 +294,7 @@ let args = CommandLine.arguments.dropFirst()
294294
guard let projectPath = args.first, !projectPath.isEmpty else { print("You must provide the path to the xcodeproj as first argument."); exit(1) }
295295
do {
296296
let project = try Xcodeproj(path: projectPath)
297-
297+
298298
// 2nd arg (optional) = name of target to lint
299299
let targetsToLint: [Xcodeproj.PBXNativeTarget]
300300
if let targetName = args.dropFirst().first, !targetName.isEmpty {
@@ -304,7 +304,7 @@ do {
304304
print("Linting all app extension targets")
305305
targetsToLint = project.nativeTargets.filter { $0.knownProductType == .appExtension }
306306
}
307-
307+
308308
// Lint each requested target
309309
var violationsFound = 0
310310
for target in targetsToLint {

0 commit comments

Comments
 (0)