diff --git a/.github/scripts/format.swift b/.github/scripts/format.swift new file mode 100755 index 0000000..5df8916 --- /dev/null +++ b/.github/scripts/format.swift @@ -0,0 +1,14 @@ +#!/usr/bin/env swift + +// Workflow commands for GitHub Actions +// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions + +let regex = #/(?.+\.swift):(?\d+):(?\d+): (?.+): \[(?.+)\] (?<message>.+)/# +while let line = readLine() { + if let match = try? regex.firstMatch(in: line) { + let (_, file, line, column, severity, title, message) = match.output + print("::\(severity) file=\(file),line=\(line),col=\(column),title=\(title)::\(message)") + } else { + print(line) + } +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 366832b..a809c41 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: runs-on: macOS-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 - name: Build and test shell: bash env: @@ -29,5 +29,13 @@ jobs: container: image: swift:6.3.3 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v7 - run: swift test + Lint: + runs-on: macOS-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + - name: swift-format lint + run: make lint 2>&1 | .github/scripts/format.swift + shell: bash diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..897490b --- /dev/null +++ b/.swift-format @@ -0,0 +1,79 @@ +{ + "fileScopedDeclarationPrivacy" : { + "accessLevel" : "private" + }, + "indentBlankLines" : false, + "indentConditionalCompilationBlocks" : false, + "indentSwitchCaseLabels" : false, + "indentation" : { + "spaces" : 4 + }, + "lineBreakAroundMultilineExpressionChainComponents" : false, + "lineBreakBeforeControlFlowKeywords" : false, + "lineBreakBeforeEachArgument" : false, + "lineBreakBeforeEachGenericRequirement" : false, + "lineBreakBetweenDeclarationAttributes" : false, + "lineLength" : 120, + "maximumBlankLines" : 1, + "multiElementCollectionTrailingCommas" : true, + "noAssignmentInExpressions" : { + "allowedFunctions" : [ + "XCTAssertNoThrow" + ] + }, + "orderedImports" : { + "includeConditionalImports" : false + }, + "prioritizeKeepingFunctionOutputTogether" : false, + "reflowMultilineStringLiterals" : "never", + "respectsExistingLineBreaks" : true, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLiteralForEmptyCollectionInit" : false, + "AlwaysUseLowerCamelCase" : true, + "AmbiguousTrailingClosureOverload" : true, + "AvoidRetroactiveConformances" : true, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : true, + "DontRepeatTypeInStaticProperties" : true, + "FileScopedDeclarationPrivacy" : true, + "FullyIndirectEnum" : true, + "GroupNumericLiterals" : true, + "IdentifiersMustBeASCII" : true, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : true, + "NoAssignmentInExpressions" : true, + "NoBlockComments" : true, + "NoCasesWithOnlyFallthrough" : true, + "NoEmptyLinesOpeningClosingBraces" : false, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : true, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoPlaygroundLiterals" : true, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : false, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : true, + "OnlyOneTrailingClosureArgument" : true, + "OrderedImports" : true, + "ReplaceForEachWithForLoop" : true, + "ReturnVoidInsteadOfEmptyTuple" : true, + "TypeNamesShouldBeCapitalized" : true, + "UseEarlyExits" : false, + "UseExplicitNilCheckInConditions" : true, + "UseLetInEveryBoundCaseVariable" : true, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : true, + "UseSynthesizedInitializer" : true, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + }, + "spacesAroundRangeFormationOperators" : false, + "spacesBeforeEndOfLineComments" : 1, + "tabWidth" : 8, + "version" : 1 +} diff --git a/Makefile b/Makefile index c89051f..df35fe7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,16 @@ +.PHONY: clean test lint format + test: swift test --enable-code-coverage ./.github/scripts/codecov.sh $(shell swift test --show-codecov-path) clean: swift package clean + +# MARK: - format + +lint: + xcrun swift-format lint --recursive --strict ./ + +format: + xcrun swift-format --recursive --in-place ./ diff --git a/Package.swift b/Package.swift index ece785e..2a1b0b2 100644 --- a/Package.swift +++ b/Package.swift @@ -6,15 +6,14 @@ import PackageDescription let package = Package( name: "XSTooling", platforms: [ - .macOS(.v10_15), + .macOS(.v10_15) ], products: [ .library( name: "XSTooling", - targets: ["XSTooling"]), - ], - dependencies: [ + targets: ["XSTooling"]) ], + dependencies: [], targets: [ .target( name: "XSTooling", diff --git a/Sources/XSTooling/ProcessCommand.swift b/Sources/XSTooling/ProcessCommand.swift index be3d79f..93916f5 100644 --- a/Sources/XSTooling/ProcessCommand.swift +++ b/Sources/XSTooling/ProcessCommand.swift @@ -14,7 +14,7 @@ public struct ProcessCommand: Hashable, Sendable { /// The receiver’s executable. public var executableURL: URL - + /// The command arguments that the system uses to launch the executable. public var arguments: [String] diff --git a/Tests/XSToolingTests/GHTest/GHTestCase.swift b/Tests/XSToolingTests/GHTest/GHTestCase.swift index ff06125..e22d247 100644 --- a/Tests/XSToolingTests/GHTest/GHTestCase.swift +++ b/Tests/XSToolingTests/GHTest/GHTestCase.swift @@ -1,6 +1,6 @@ // // GHTestCase.swift -// +// // // Created by Alexander Ignatiev on 12.12.2022. // @@ -11,23 +11,25 @@ class GHTestCase: XCTestCase { var github: GHActions { .shared } var isLinux: Bool { -#if os(Linux) + #if os(Linux) return true -#else + #else return false -#endif + #endif } -#if os(Linux) + #if os(Linux) - override func recordFailure(withDescription description: String, inFile filePath: String, atLine lineNumber: Int, expected: Bool) { + override func recordFailure( + withDescription description: String, inFile filePath: String, atLine lineNumber: Int, expected: Bool + ) { if github.isEnabled { github.error(file: filePath, line: lineNumber, message: description) } super.recordFailure(withDescription: description, inFile: filePath, atLine: lineNumber, expected: expected) } -#else // os(Darwin) + #else // os(Darwin) override func record(_ issue: XCTIssue) { if github.isEnabled { @@ -41,5 +43,5 @@ class GHTestCase: XCTestCase { super.record(issue) } -#endif + #endif } diff --git a/Tests/XSToolingTests/ShellTests.swift b/Tests/XSToolingTests/ShellTests.swift index fec2a4c..9fec58d 100644 --- a/Tests/XSToolingTests/ShellTests.swift +++ b/Tests/XSToolingTests/ShellTests.swift @@ -29,7 +29,7 @@ final class ShellTests: GHTestCase { func testZsh() async throws { try XCTSkipIf(isLinux) - + shell = Shell.zsh XCTAssertEqual(shell.path, "/bin/zsh")