-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90e461c
commit a35a195
Showing
8 changed files
with
524 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
import XcodeProj | ||
|
||
/// Make sure all file references use relative paths. | ||
struct RelativePathsRule { | ||
func run(_ environment: XCLinter.Environment) throws -> [Violation] { | ||
var violations = [Violation]() | ||
|
||
// check top-level | ||
for project in environment.project.pbxproj.projects { | ||
guard let group = project.mainGroup else { continue } | ||
|
||
violations.append(contentsOf: checkGroup(group)) | ||
} | ||
|
||
return violations | ||
} | ||
|
||
private func checkGroup(_ group: PBXGroup) -> [Violation] { | ||
var violations = [Violation]() | ||
|
||
let groupName = group.name ?? group.path ?? "???" | ||
|
||
for element in group.children { | ||
let elementName = element.name ?? element.path ?? "???" | ||
|
||
if element.path?.starts(with: "/") == true { | ||
violations.append(.init("\(groupName):\(elementName) has an absolute file path")) | ||
} | ||
|
||
if let subgroup = element as? PBXGroup { | ||
violations.append(contentsOf: checkGroup(subgroup)) | ||
} | ||
} | ||
|
||
return violations | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import XCTest | ||
|
||
@testable import XCLinting | ||
import XcodeProj | ||
|
||
final class RelativePathsRuleTests: XCTestCase { | ||
func testProjectWithOnlyRelativePaths() throws { | ||
let url = try Bundle.module.testDataURL(named: "StockMacOSApp.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try RelativePathsRule().run(env) | ||
|
||
XCTAssertTrue(violations.isEmpty) | ||
} | ||
|
||
func testProjectWithOneAbosluteFilePath() throws { | ||
let url = try Bundle.module.testDataURL(named: "AbsolueFileReference.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try RelativePathsRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
} | ||
|
Oops, something went wrong.