Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,12 @@
or other error.
[Martin Redington](https://github.com/mildm8nnered)
[#6052](https://github.com/realm/SwiftLint/issues/6052)


* Fall back to default configuration when a nested `.swiftlint.yml` cannot be parsed
instead of aborting (e.g. duplicate YAML keys in a subdirectory).
[leno23](https://github.com/leno23)
[#6052](https://github.com/realm/SwiftLint/issues/6052)

* Keep the default severity levels when neither `warning` nor `error` values are configured.
Ensure especially that the `error` level is not set to `nil` when the `warning` level
isn't set either.
Expand Down
2 changes: 2 additions & 0 deletions Source/SwiftLintCore/Models/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public enum Issue: LocalizedError, Equatable {
return "error: \(message)"
case .genericWarning:
return "warning: \(message)"
case .yamlParsing:
return "warning: \(message)"
default:
return Self.genericWarning(message).errorDescription
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ extension Configuration {
// Ignore parent_config / child_config specifications of nested configs
var childConfiguration = Configuration(
configurationFiles: [configurationSearchPath],
ignoreParentAndChildConfigs: true
ignoreParentAndChildConfigs: true,
useDefaultConfigOnFailure: true
)
childConfiguration.fileGraph = FileGraph(rootDirectory: directory)
config = merged(withChild: childConfiguration, rootDirectory: rootDirectory)
Expand Down
4 changes: 4 additions & 0 deletions Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal extension ConfigurationTests {
static var remoteConfigLocalRef: String { level0.stringByAppendingPathComponent("RemoteConfig/LocalRef") }
static var remoteConfigCycle: String { level0.stringByAppendingPathComponent("RemoteConfig/Cycle") }
static var emptyFolder: String { level0.stringByAppendingPathComponent("EmptyFolder") }
static var duplicateYamlKeys: String { level0.stringByAppendingPathComponent("DuplicateYamlKeys") }

static var exclusionTests: String { testResourcesPath.stringByAppendingPathComponent("ExclusionTests") }
static var directory: String { exclusionTests.stringByAppendingPathComponent("directory") }
Expand Down Expand Up @@ -65,6 +66,9 @@ internal extension ConfigurationTests {
static var _2: String { Dir.level2.stringByAppendingPathComponent("Level2.swift") }
static var _3: String { Dir.level3.stringByAppendingPathComponent("Level3.swift") }
static var nestedSub: String { Dir.nestedSub.stringByAppendingPathComponent("Sub.swift") }
static var duplicateYamlKeysSub: String {
Dir.duplicateYamlKeys.stringByAppendingPathComponent("subdir/a.swift")
}
}

// MARK: Configurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ extension ConfigurationTests {
)
}

func testNestedConfigurationWithInvalidYamlFallsBackToDefault() async throws {
XCTAssert(FileManager.default.changeCurrentDirectoryPath(Mock.Dir.duplicateYamlKeys))

let console = try await Issue.captureConsole {
let config = Configuration(configurationFiles: [])
_ = config.configuration(for: SwiftLintFile(path: Mock.Swift.duplicateYamlKeysSub)!)
}

XCTAssertTrue(console.contains("Cannot parse YAML file"))
XCTAssertTrue(console.contains("Falling back to default configuration"))
}

func testNestedConfigurationForOnePathPassedIn() {
// If a path to one or more configuration files is specified, nested configurations should be ignored
let config = Configuration(configurationFiles: [Mock.Yml._0])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opt_in_rules:
- closure_body_length

opt_in_rules:
- closure_body_length
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Test file for nested configuration with invalid YAML.