Lint Plugins directory (#4591)
This commit is contained in:
parent
12c8bb369e
commit
5a7d3ade02
|
@ -1,4 +1,5 @@
|
|||
included:
|
||||
- Plugins
|
||||
- Source
|
||||
- Tests
|
||||
excluded:
|
||||
|
|
|
@ -3,16 +3,14 @@ import PackagePlugin
|
|||
|
||||
extension Path {
|
||||
/// Scans the receiver, then all of its parents looking for a configuration file with the name ".swiftlint.yml".
|
||||
/// - Returns: Path to the configuration file, or nil if one cannot be found.
|
||||
///
|
||||
/// - returns: Path to the configuration file, or nil if one cannot be found.
|
||||
func firstConfigurationFileInParentDirectories() -> Path? {
|
||||
// TODO: Consider linking to the framework to get the default configuration file name
|
||||
let defaultConfigurationFileName = ".swiftlint.yml"
|
||||
let proposedDirectory = sequence(first: self, next: { $0.removingLastComponent() })
|
||||
.first { path in
|
||||
let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName)
|
||||
return FileManager.default.isReadableFile(atPath: potentialConfigurationFile.string)
|
||||
}
|
||||
|
||||
let proposedDirectory = sequence(first: self, next: { $0.removingLastComponent() }).first { path in
|
||||
let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName)
|
||||
return FileManager.default.isReadableFile(atPath: potentialConfigurationFile.string)
|
||||
}
|
||||
return proposedDirectory?.appending(subpath: defaultConfigurationFileName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ struct SwiftLintPlugin: BuildToolPlugin {
|
|||
"--cache-path", "\(context.pluginWorkDirectory)"
|
||||
]
|
||||
|
||||
// Manually look for configuration files, to avoid issues when the plugin does not execute our tool from the package source directory.
|
||||
// Manually look for configuration files, to avoid issues when the plugin does not execute our tool from the
|
||||
// package source directory.
|
||||
if let configuration = context.package.directory.firstConfigurationFileInParentDirectories() {
|
||||
arguments.append(contentsOf: [
|
||||
"--config", "\(configuration.string)"
|
||||
|
@ -69,7 +70,8 @@ extension SwiftLintPlugin: XcodeBuildToolPlugin {
|
|||
"--cache-path", "\(context.pluginWorkDirectory)"
|
||||
]
|
||||
|
||||
// Xcode build tool plugins don't seem to run from the project source directory, so our auto-discovery of configuration files doesn't work. We approximate it here.
|
||||
// Xcode build tool plugins don't seem to run from the project source directory, so our auto-discovery of
|
||||
// configuration files doesn't work. We approximate it here.
|
||||
if let configuration = context.xcodeProject.directory.firstConfigurationFileInParentDirectories() {
|
||||
arguments.append(contentsOf: [
|
||||
"--config", "\(configuration.string)"
|
||||
|
|
Loading…
Reference in New Issue