-
-
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.
ProjectsUseXCConfigRule, TargetsUseXCConfigRule
- Loading branch information
1 parent
7a5e565
commit 0222a54
Showing
12 changed files
with
862 additions
and
0 deletions.
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,25 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Matthew Massicotte on 2024-01-22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Detect projects that do not use XCConfigs. | ||
struct ProjectsUseXCConfigRule { | ||
func run(_ environment: XCLinter.Environment) throws -> [Violation] { | ||
var violations = [Violation]() | ||
|
||
for project in environment.project.pbxproj.projects { | ||
for config in project.buildConfigurationList?.buildConfigurations ?? [] { | ||
if config.baseConfiguration?.path == nil { | ||
violations.append(.init("No xcconfig set for \(project.name), \(config.name)")) | ||
} | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
|
||
import XcodeProj | ||
import XCConfig | ||
|
||
/// Detect targets that do not use XCConfigs. | ||
struct TargetsUseXCConfigRule { | ||
func run(_ environment: XCLinter.Environment) throws -> [Violation] { | ||
var violations = [Violation]() | ||
|
||
// check targets | ||
environment.project.pbxproj.enumerateBuildConfigurations { name, configList in | ||
for config in configList.buildConfigurations { | ||
if config.baseConfiguration?.path == nil { | ||
violations.append(.init("No xcconfig set for \(name), \(config.name)")) | ||
} | ||
} | ||
} | ||
|
||
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 ProjectsUseXCConfigRuleTests: XCTestCase { | ||
func testProjectsWithoutXCConfigs() 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 ProjectsUseXCConfigRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
|
||
func testProjectsWithOnlyXCConfigs() throws { | ||
let url = try Bundle.module.testDataURL(named: "ProjectsUseXCConfigFiles.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try ProjectsUseXCConfigRule().run(env) | ||
|
||
XCTAssertTrue(violations.isEmpty) | ||
} | ||
} | ||
|
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,38 @@ | ||
import XCTest | ||
|
||
@testable import XCLinting | ||
import XcodeProj | ||
|
||
final class TargetsUseXCConfigRuleTests: XCTestCase { | ||
func testTargetsWithoutXCConfigs() 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 TargetsUseXCConfigRule().run(env) | ||
|
||
XCTAssertFalse(violations.isEmpty) | ||
} | ||
|
||
func testTargetsWithOnlyXCConfigs() throws { | ||
let url = try Bundle.module.testDataURL(named: "TargetsUseXCConfigFiles.xcodeproj") | ||
|
||
let project = try XcodeProj(pathString: url.path) | ||
|
||
let env = XCLinter.Environment( | ||
project: project, | ||
projectRootURL: url, | ||
configuration: Configuration() | ||
) | ||
|
||
let violations = try TargetsUseXCConfigRule().run(env) | ||
|
||
XCTAssertTrue(violations.isEmpty) | ||
} | ||
} |
Oops, something went wrong.