Add SwiftCLI dependency to TokamakCLI (#89)
* Add public lintFile * Add SwiftCLI package * Add CLI to TokamakCLI * Apply swiftformat * Fix TokamakCLI version * Fix typo * Update TokamakCLI error catch * Update TokamakCLI path * Update Linter.md * Remove SRCROOT * Update Linter.md * Update XcodeReporter * Update project.pbxproj * Remove commented print
This commit is contained in:
parent
c3e7f5237e
commit
ee1f2d93c8
|
@ -9,6 +9,15 @@
|
|||
"revision": "43aa4a19b8105a803d8149ad2a86aa53a77efef3",
|
||||
"version": "0.50000.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "SwiftCLI",
|
||||
"repositoryURL": "https://github.com/jakeheis/SwiftCLI",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
|
||||
"version": "5.2.2"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -39,6 +39,7 @@ let package = Package(
|
|||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-syntax.git", .exact("0.50000.0")),
|
||||
.package(url: "https://github.com/jakeheis/SwiftCLI", from: "5.0.0"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define
|
||||
|
@ -67,7 +68,7 @@ let package = Package(
|
|||
),
|
||||
.target(
|
||||
name: "TokamakCLI",
|
||||
dependencies: ["TokamakLint"]
|
||||
dependencies: ["TokamakLint", "SwiftCLI"]
|
||||
),
|
||||
.target(
|
||||
name: "TokamakLint",
|
||||
|
|
|
@ -6,12 +6,34 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftCLI
|
||||
import TokamakLint
|
||||
|
||||
do {
|
||||
let srcRoot = ProcessInfo.processInfo.environment["SRCROOT"]!
|
||||
try lintFolder("\(srcRoot)/Sources/Tokamak/Components/Host")
|
||||
} catch {
|
||||
print("Can't lint folder")
|
||||
print(error)
|
||||
class LintCommand: Command {
|
||||
let name = "lint"
|
||||
let shortDescription = "Lint folder or file"
|
||||
let path = Parameter()
|
||||
|
||||
func execute() throws {
|
||||
if path.value.contains(".swift") {
|
||||
do {
|
||||
try lintFile("\(path.value)")
|
||||
} catch {
|
||||
print("Can't lint file")
|
||||
print(error)
|
||||
}
|
||||
} else {
|
||||
do {
|
||||
try lintFolder("\(path.value)")
|
||||
} catch {
|
||||
print("Can't lint folder")
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let TokamakCLI = CLI(name: "TokamakCLI", version: "0.1.2", description: "Tokamak CLI tools")
|
||||
|
||||
TokamakCLI.commands = [LintCommand()]
|
||||
TokamakCLI.go()
|
||||
|
|
|
@ -28,15 +28,23 @@ public func lintFolder(_ path: String) throws {
|
|||
for (i, fileURL) in enumerated {
|
||||
print("Linting ",
|
||||
"\(fileURL.lastPathComponent) ",
|
||||
"(\(i)/\(count))")
|
||||
let errors = try lintFile(fileURL.path)
|
||||
"(\(i + 1)/\(count))")
|
||||
let errors = try checkFile(fileURL.path)
|
||||
if errors.count > 0 {
|
||||
print(XcodeReporter.generateReport(errors))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func lintFile(_ path: String) throws -> [StyleViolation] {
|
||||
public func lintFile(_ path: String) throws {
|
||||
print("Linting \(path)")
|
||||
let errors = try checkFile(path)
|
||||
if errors.count > 0 {
|
||||
print(XcodeReporter.generateReport(errors))
|
||||
}
|
||||
}
|
||||
|
||||
func checkFile(_ path: String) throws -> [StyleViolation] {
|
||||
let visitor = try walkParsedTree(path)
|
||||
visitor.path = path
|
||||
guard !hasTokamakImport(from: visitor) else {
|
||||
|
|
|
@ -20,7 +20,7 @@ struct XcodeReporter: Reporter {
|
|||
static func generateForSingleViolation(_ violation: StyleViolation) -> String {
|
||||
// {full_path_to_file}{:line}{:character}: {error,warning}: {content}
|
||||
return [
|
||||
"\(violation.location): ",
|
||||
"\(violation.location): warning: ",
|
||||
"\(violation.ruleDescription.name) Violation: ",
|
||||
violation.reason,
|
||||
" (\(violation.ruleDescription.identifier))",
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,175 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "9999"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakDemo"
|
||||
BuildableName = "TokamakDemo.framework"
|
||||
BlueprintName = "TokamakDemo"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakLint"
|
||||
BuildableName = "TokamakLint.framework"
|
||||
BlueprintName = "TokamakLint"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakAppKit"
|
||||
BuildableName = "TokamakAppKit.framework"
|
||||
BlueprintName = "TokamakAppKit"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakCLI"
|
||||
BuildableName = "TokamakCLI"
|
||||
BlueprintName = "TokamakCLI"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakUIKit"
|
||||
BuildableName = "TokamakUIKit.framework"
|
||||
BlueprintName = "TokamakUIKit"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakTestRenderer"
|
||||
BuildableName = "TokamakTestRenderer.framework"
|
||||
BlueprintName = "TokamakTestRenderer"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::Tokamak"
|
||||
BuildableName = "Tokamak.framework"
|
||||
BlueprintName = "Tokamak"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakTests"
|
||||
BuildableName = "TokamakTests.xctest"
|
||||
BlueprintName = "TokamakTests"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakCLITests"
|
||||
BuildableName = "TokamakCLITests.xctest"
|
||||
BlueprintName = "TokamakCLITests"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Tokamak::TokamakDemo"
|
||||
BuildableName = "TokamakDemo.framework"
|
||||
BlueprintName = "TokamakDemo"
|
||||
ReferencedContainer = "container:Tokamak.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -11,7 +11,7 @@ and show them in Xcode or in terminal.
|
|||
- add path to TokamakCLI to build phase
|
||||
|
||||
```bash
|
||||
{path to TokamakCLI}/TokamakCLI
|
||||
{path to TokamakCLI}/TokamakCLI lint {path to folder or file}
|
||||
```
|
||||
|
||||
or
|
||||
|
@ -19,7 +19,7 @@ or
|
|||
### Run in terminal
|
||||
|
||||
- run `swift build --product TokamakCLI` in Tokamak directory
|
||||
- run `swift run TokamakCLI "{path to lint folder}"` in Tokamak directory
|
||||
- run `swift run TokamakCLI lint "{path to lint folder or file}"` in Tokamak directory
|
||||
|
||||
## Supported Rules
|
||||
|
||||
|
|
Loading…
Reference in New Issue