Skip to content

Commit

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

This reverts commit a67b0f2.
  • Loading branch information
sethfri committed Oct 26, 2020
1 parent 5d6e25a commit dedbde3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
[Jumhyn](https://github.com/jumhyn)
[#3295](https://github.com/realm/SwiftLint/issues/3295)

* 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: 3 additions & 18 deletions Source/SwiftLintFramework/Extensions/Configuration+Merging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ extension Configuration {
}

private func configuration(forPath path: String) -> Configuration {
if path == rootDirectory {
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 {
return self
}

Expand Down Expand Up @@ -49,23 +51,6 @@ 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: 2 additions & 1 deletion Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated using Sourcery 0.18.0 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 1.0.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

@testable import SwiftLintFrameworkTests
Expand Down Expand Up @@ -208,6 +208,7 @@ extension ConfigurationTests {
("testLevel2", testLevel2),
("testLevel3", testLevel3),
("testNestedConfigurationWithCustomRootPath", testNestedConfigurationWithCustomRootPath),
("testNestedConfigurationForOnePathPassedIn", testNestedConfigurationForOnePathPassedIn),
("testMergedWarningThreshold", testMergedWarningThreshold),
("testNestedWhitelistedRules", testNestedWhitelistedRules),
("testNestedConfigurationsWithCustomRulesMerge", testNestedConfigurationsWithCustomRulesMerge),
Expand Down
8 changes: 8 additions & 0 deletions Tests/SwiftLintFrameworkTests/ConfigurationTests+Nested.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ 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 dedbde3

Please sign in to comment.