Skip to content

Commit

Permalink
Fix warning for unused return value in Linux build (#5819)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Oct 7, 2024
1 parent d22a719 commit 3b6ba6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 5 additions & 1 deletion Source/swiftlint/Commands/SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import SwiftLintFramework
struct SwiftLint: AsyncParsableCommand {
static let configuration: CommandConfiguration = {
if let directory = ProcessInfo.processInfo.environment["BUILD_WORKSPACE_DIRECTORY"] {
FileManager.default.changeCurrentDirectoryPath(directory)
if !FileManager.default.changeCurrentDirectoryPath(directory) {
queuedFatalError("""
Could not change current directory to \(directory) specified by BUILD_WORKSPACE_DIRECTORY.
""")
}
}

RuleRegistry.registerAllRulesOnce()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ extension ConfigurationTests {
}

for path in [Mock.Dir.childConfigTest1, Mock.Dir.childConfigTest2] {
FileManager.default.changeCurrentDirectoryPath(path)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(path))

assertEqualExceptForFileGraph(
Configuration(configurationFiles: ["main.yml"]),
Expand All @@ -248,7 +248,7 @@ extension ConfigurationTests {

func testValidParentConfig() {
for path in [Mock.Dir.parentConfigTest1, Mock.Dir.parentConfigTest2] {
FileManager.default.changeCurrentDirectoryPath(path)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(path))

assertEqualExceptForFileGraph(
Configuration(configurationFiles: ["main.yml"]),
Expand All @@ -263,7 +263,7 @@ extension ConfigurationTests {
}

for path in [Mock.Dir.childConfigTest1, Mock.Dir.childConfigTest2] {
FileManager.default.changeCurrentDirectoryPath(path)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(path))

assertEqualExceptForFileGraph(
Configuration(
Expand All @@ -283,7 +283,7 @@ extension ConfigurationTests {
Mock.Dir.parentConfigCycle2,
Mock.Dir.parentConfigCycle3,
] {
FileManager.default.changeCurrentDirectoryPath(path)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(path))

// If the cycle is properly detected, the config should equal the default config.
XCTAssertEqual(
Expand All @@ -294,7 +294,7 @@ extension ConfigurationTests {
}

func testCommandLineConfigsCycleDetection() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.childConfigCycle4)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.childConfigCycle4))

// If the cycle is properly detected, the config should equal the default config.
assertEqualExceptForFileGraph(
Expand Down Expand Up @@ -525,7 +525,7 @@ extension ConfigurationTests {

// MARK: - Remote Configs
func testValidRemoteChildConfig() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigChild)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigChild))

assertEqualExceptForFileGraph(
Configuration(
Expand All @@ -544,7 +544,7 @@ extension ConfigurationTests {
}

func testValidRemoteParentConfig() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigParent)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigParent))

assertEqualExceptForFileGraph(
Configuration(
Expand All @@ -569,7 +569,7 @@ extension ConfigurationTests {
}

func testsRemoteConfigNotAllowedToReferenceLocalConfig() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigLocalRef)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigLocalRef))

// If the remote file is not allowed to reference a local file, the config should equal the default config.
XCTAssertEqual(
Expand All @@ -589,7 +589,7 @@ extension ConfigurationTests {
}

func testRemoteConfigCycleDetection() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigCycle)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.remoteConfigCycle))

// If the cycle is properly detected, the config should equal the default config.
XCTAssertEqual(
Expand Down
24 changes: 12 additions & 12 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ final class ConfigurationTests: SwiftLintTestCase {
super.setUp()
Configuration.resetCache()
previousWorkingDir = FileManager.default.currentDirectoryPath
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
}

override func tearDown() {
super.tearDown()
FileManager.default.changeCurrentDirectoryPath(previousWorkingDir)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(previousWorkingDir))
}

// MARK: Tests
Expand All @@ -37,7 +37,7 @@ final class ConfigurationTests: SwiftLintTestCase {

func testNoConfiguration() {
// Change to a folder where there is no `.swiftlint.yml`
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.emptyFolder)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.emptyFolder))

// Test whether the default configuration is used if there is no `.swiftlint.yml` or other config file
XCTAssertEqual(Configuration(configurationFiles: []), Configuration.default)
Expand Down Expand Up @@ -210,7 +210,7 @@ final class ConfigurationTests: SwiftLintTestCase {
return
}

FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level1)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level1))

// The included path "File.swift" should be put relative to the configuration file
// (~> Resources/ProjectMock/File.swift) and not relative to the path where
Expand All @@ -230,7 +230,7 @@ final class ConfigurationTests: SwiftLintTestCase {
func testIncludedExcludedRelativeLocationLevel0() {
// Same as testIncludedPathRelatedToConfigurationFileLocationLevel1(),
// but run from the directory the config file resides in
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(configurationFiles: ["custom_included_excluded.yml"])
let actualIncludedPath = configuration.includedPaths.first!.bridge()
.absolutePathRepresentation(rootDirectory: configuration.rootDirectory)
Expand Down Expand Up @@ -345,7 +345,7 @@ final class ConfigurationTests: SwiftLintTestCase {
}

func testGlobIncludePaths() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(includedPaths: ["**/Level2"])
let paths = configuration.lintablePaths(inPath: Mock.Dir.level0,
forceExclude: true,
Expand Down Expand Up @@ -468,7 +468,7 @@ final class ConfigurationTests: SwiftLintTestCase {
// MARK: - ExcludeByPrefix option tests
extension ConfigurationTests {
func testExcludeByPrefixExcludedPaths() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(
includedPaths: ["Level1"],
excludedPaths: ["Level1/Level1.swift", "Level1/Level2/Level3"]
Expand All @@ -481,7 +481,7 @@ extension ConfigurationTests {
}

func testExcludeByPrefixForceExcludesFile() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(excludedPaths: ["Level1/Level2/Level3/Level3.swift"])
let paths = configuration.lintablePaths(inPath: "Level1/Level2/Level3/Level3.swift",
forceExclude: true,
Expand All @@ -490,7 +490,7 @@ extension ConfigurationTests {
}

func testExcludeByPrefixForceExcludesFileNotPresentInExcluded() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(includedPaths: ["Level1"],
excludedPaths: ["Level1/Level1.swift"])
let paths = configuration.lintablePaths(inPath: "Level1",
Expand All @@ -501,7 +501,7 @@ extension ConfigurationTests {
}

func testExcludeByPrefixForceExcludesDirectory() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(
excludedPaths: [
"Level1/Level2", "Directory.swift", "ChildConfig", "ParentConfig", "NestedConfig"
Expand All @@ -515,7 +515,7 @@ extension ConfigurationTests {
}

func testExcludeByPrefixForceExcludesDirectoryThatIsNotInExcludedButHasChildrenThatAre() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(
excludedPaths: [
"Level1", "Directory.swift/DirectoryLevel1.swift", "ChildConfig", "ParentConfig", "NestedConfig"
Expand All @@ -529,7 +529,7 @@ extension ConfigurationTests {
}

func testExcludeByPrefixGlobExcludePaths() {
FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0)
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.level0))
let configuration = Configuration(
includedPaths: ["Level1"],
excludedPaths: ["Level1/*/*.swift", "Level1/*/*/*.swift"])
Expand Down

0 comments on commit 3b6ba6d

Please sign in to comment.