Skip to content

Commit

Permalink
Revert "Fix finding the nested config when a single file path is pass…
Browse files Browse the repository at this point in the history
…ed (realm#3342)" (realm#3362)

This reverts commit ea06b79.
  • Loading branch information
jpsim authored Sep 22, 2020
1 parent 774267c commit a67b0f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
[hank121314](https://github.com/hank121314)
[#2367](https://github.com/realm/SwiftLint/issues/3267)

* Fix finding a nested config when a single file path is passed.
[Seth Friedman](https://github.com/sethfri)

## 0.40.2: Demo Unit

#### Breaking
Expand Down
21 changes: 18 additions & 3 deletions Source/SwiftLintFramework/Extensions/Configuration+Merging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ extension Configuration {
}

private func configuration(forPath path: String) -> Configuration {
let rootConfigurationDirectory = configurationPath?.bridge().deletingLastPathComponent
// We're linting a file in the same directory as the root configuration we've already loaded
if path == rootConfigurationDirectory {
if path == rootDirectory {
return self
}

Expand Down Expand Up @@ -51,6 +49,23 @@ extension Configuration {
return self
}

private var rootDirectory: String? {
guard let rootPath = rootPath else {
return nil
}

var isDirectoryObjC: ObjCBool = false
guard FileManager.default.fileExists(atPath: rootPath, isDirectory: &isDirectoryObjC) else {
return nil
}

if isDirectoryObjC.boolValue {
return rootPath
} else {
return rootPath.bridge().deletingLastPathComponent
}
}

private struct HashableRule: Hashable {
fileprivate let rule: Rule

Expand Down
3 changes: 1 addition & 2 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 1.0.0 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 0.18.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

@testable import SwiftLintFrameworkTests
Expand Down Expand Up @@ -208,7 +208,6 @@ extension ConfigurationTests {
("testLevel2", testLevel2),
("testLevel3", testLevel3),
("testNestedConfigurationWithCustomRootPath", testNestedConfigurationWithCustomRootPath),
("testNestedConfigurationForOnePathPassedIn", testNestedConfigurationForOnePathPassedIn),
("testMergedWarningThreshold", testMergedWarningThreshold),
("testNestedWhitelistedRules", testNestedWhitelistedRules),
("testNestedConfigurationsWithCustomRulesMerge", testNestedConfigurationsWithCustomRulesMerge),
Expand Down
8 changes: 0 additions & 8 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ extension ConfigurationTests {
XCTAssertEqual(projectMockConfig0.merge(with: projectMockConfig3).rootPath, projectMockConfig3.rootPath)
}

func testNestedConfigurationForOnePathPassedIn() {
let config = Configuration(path: projectMockYAML0, rootPath: projectMockSwift3)
XCTAssertEqual(
config.configuration(for: SwiftLintFile(path: projectMockSwift3)!),
config.merge(with: projectMockConfig3)
)
}

func testMergedWarningThreshold() {
func configuration(forWarningThreshold warningThreshold: Int?) -> Configuration {
return Configuration(warningThreshold: warningThreshold,
Expand Down

0 comments on commit a67b0f2

Please sign in to comment.