diff --git a/CHANGELOG.md b/CHANGELOG.md index 24b266362..4aa3d646f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,11 @@ * Fix finding a nested config when a single file path is passed. [Seth Friedman](https://github.com/sethfri) +* Fix incorrect calculation of the root path when a directory in the + tree is passed in as a path argument. + [Seth Friedman](https://github.com/sethfri) + [#3383](https://github.com/realm/SwiftLint/issues/3383) + ## 0.40.3: Greased Up Drum Bearings #### Breaking diff --git a/Source/swiftlint/Extensions/Configuration+CommandLine.swift b/Source/swiftlint/Extensions/Configuration+CommandLine.swift index 19162db99..fa974eff8 100644 --- a/Source/swiftlint/Extensions/Configuration+CommandLine.swift +++ b/Source/swiftlint/Extensions/Configuration+CommandLine.swift @@ -227,16 +227,12 @@ extension Configuration { }) } - private static func rootPath(from paths: [String]) -> String? { - // We don't know the root when more than one path is passed (i.e. not useful if the root of 2 paths is ~) - return paths.count == 1 ? paths.first?.absolutePathStandardized() : nil - } - // MARK: LintOrAnalyze Command init(options: LintOrAnalyzeOptions) { let cachePath = options.cachePath.isEmpty ? nil : options.cachePath - self.init(path: options.configurationFile, rootPath: Self.rootPath(from: options.paths), + self.init(path: options.configurationFile, + rootPath: FileManager.default.currentDirectoryPath.bridge().absolutePathStandardized(), optional: isConfigOptional(), quiet: options.quiet, enableAllRules: options.enableAllRules, cachePath: cachePath) } @@ -256,7 +252,8 @@ extension Configuration { init(options: AutoCorrectOptions) { let cachePath = options.cachePath.isEmpty ? nil : options.cachePath - self.init(path: options.configurationFile, rootPath: Self.rootPath(from: options.paths), + self.init(path: options.configurationFile, + rootPath: FileManager.default.currentDirectoryPath.bridge().absolutePathStandardized(), optional: isConfigOptional(), quiet: options.quiet, cachePath: cachePath) }