forked from Quick/Quick
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Quick#1280 from Quick/quicklint
Add QuickLint, a CLI tool to detect focused specs, and optionally remove the focus.
- Loading branch information
Showing
27 changed files
with
1,483 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
struct DefocusCommandPlugin: CommandPlugin { | ||
func performCommand( | ||
context: PluginContext, | ||
arguments: [String] | ||
) throws { | ||
try run( | ||
tool: try context.tool(named: "QuickLint"), | ||
workingDirectory: URL(fileURLWithPath: context.package.directory.string), | ||
arguments: arguments | ||
) | ||
} | ||
|
||
private func run( | ||
tool: PluginContext.Tool, | ||
workingDirectory: URL, | ||
arguments: [String] | ||
) throws { | ||
let process: Process = .init() | ||
process.currentDirectoryURL = workingDirectory | ||
process.executableURL = URL(fileURLWithPath: tool.path.string) | ||
process.arguments = ["defocus"] + arguments | ||
try process.run() | ||
process.waitUntilExit() | ||
switch process.terminationReason { | ||
case .exit: | ||
break | ||
case .uncaughtSignal: | ||
Diagnostics.error("Uncaught Signal") | ||
@unknown default: | ||
Diagnostics.error("Unexpected Termination Reason") | ||
} | ||
guard process.terminationStatus == EXIT_SUCCESS else { | ||
Diagnostics.error("Command Failed") | ||
return | ||
} | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
|
||
import XcodeProjectPlugin | ||
|
||
extension DefocusCommandPlugin: XcodeCommandPlugin { | ||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
try run( | ||
tool: try context.tool(named: "QuickLint"), | ||
workingDirectory: URL(fileURLWithPath: context.pluginWorkDirectory.string), | ||
arguments: arguments | ||
) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
struct LintCommandPlugin: CommandPlugin { | ||
func performCommand( | ||
context: PluginContext, | ||
arguments: [String] | ||
) throws { | ||
try run( | ||
tool: try context.tool(named: "QuickLint"), | ||
workingDirectory: URL(fileURLWithPath: context.package.directory.string), | ||
arguments: arguments | ||
) | ||
} | ||
|
||
private func run( | ||
tool: PluginContext.Tool, | ||
workingDirectory: URL, | ||
arguments: [String] | ||
) throws { | ||
let process: Process = .init() | ||
process.currentDirectoryURL = workingDirectory | ||
process.executableURL = URL(fileURLWithPath: tool.path.string) | ||
process.arguments = ["lint"] + arguments | ||
try process.run() | ||
process.waitUntilExit() | ||
switch process.terminationReason { | ||
case .exit: | ||
break | ||
case .uncaughtSignal: | ||
Diagnostics.error("Uncaught Signal") | ||
@unknown default: | ||
Diagnostics.error("Unexpected Termination Reason") | ||
} | ||
guard process.terminationStatus == EXIT_SUCCESS else { | ||
Diagnostics.error("Command Failed") | ||
return | ||
} | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
|
||
import XcodeProjectPlugin | ||
|
||
extension LintCommandPlugin: XcodeCommandPlugin { | ||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
try run( | ||
tool: try context.tool(named: "QuickLint"), | ||
workingDirectory: URL(fileURLWithPath: context.pluginWorkDirectory.string), | ||
arguments: arguments | ||
) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main | ||
struct LintError: BuildToolPlugin { | ||
func createBuildCommands(context: PluginContext, target: any Target) async throws -> [Command] { | ||
try makeCommand( | ||
executable: context.tool(named: "QuickLint"), | ||
files: (target as? SourceModuleTarget).flatMap(lintableFiles(target:)) ?? [], | ||
pluginWorkDirectory: context.pluginWorkDirectory | ||
) | ||
} | ||
|
||
private func lintableFiles(target: SourceModuleTarget) -> [Path] { | ||
target | ||
.sourceFiles | ||
.filter(isLintable(file:)) | ||
.map { $0.path } | ||
} | ||
|
||
private func isLintable(file: PackagePlugin.File) -> Bool { | ||
return ["swift", "m", "mm"].contains(file.path.extension ?? "") | ||
} | ||
|
||
private func makeCommand( | ||
executable: PluginContext.Tool, | ||
files: [Path], | ||
pluginWorkDirectory path: Path) throws -> [Command] { | ||
guard files.isEmpty == false else { return [] } | ||
|
||
return [Command.buildCommand( | ||
displayName: "quicklint", | ||
executable: executable.path, | ||
arguments: ["lint", "--error"] + files.map { $0.string }, | ||
inputFiles: files, | ||
outputFiles: files | ||
)] | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
|
||
import XcodeProjectPlugin | ||
|
||
extension LintError: XcodeBuildToolPlugin { | ||
func createBuildCommands( | ||
context: XcodePluginContext, | ||
target: XcodeTarget | ||
) throws -> [Command] { | ||
try makeCommand( | ||
executable: context.tool(named: "QuickLint"), | ||
files: lintableFiles(target: target), | ||
pluginWorkDirectory: context.pluginWorkDirectory | ||
) | ||
} | ||
|
||
private func lintableFiles(target: XcodeTarget) -> [Path] { | ||
target.inputFiles | ||
.filter(isLintable(file:)) | ||
.map { $0.path } | ||
} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.