diff --git a/.swift-format-nolint b/.swift-format-nolint new file mode 100644 index 00000000..8f600e50 --- /dev/null +++ b/.swift-format-nolint @@ -0,0 +1,68 @@ +{ + "fileScopedDeclarationPrivacy" : { + "accessLevel" : "private" + }, + "indentation" : { + "spaces" : 4 + }, + "indentConditionalCompilationBlocks" : false, + "indentSwitchCaseLabels" : false, + "lineBreakAroundMultilineExpressionChainComponents" : false, + "lineBreakBeforeControlFlowKeywords" : false, + "lineBreakBeforeEachArgument" : false, + "lineBreakBeforeEachGenericRequirement" : false, + "lineLength" : 180, + "maximumBlankLines" : 1, + "multiElementCollectionTrailingCommas" : true, + "noAssignmentInExpressions" : { + "allowedFunctions" : [ + "XCTAssertNoThrow" + ] + }, + "prioritizeKeepingFunctionOutputTogether" : false, + "respectsExistingLineBreaks" : true, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLowerCamelCase" : false, + "AmbiguousTrailingClosureOverload" : false, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : true, + "DontRepeatTypeInStaticProperties" : false, + "FileScopedDeclarationPrivacy" : false, + "FullyIndirectEnum" : false, + "GroupNumericLiterals" : false, + "IdentifiersMustBeASCII" : false, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : false, + "NoAssignmentInExpressions" : false, + "NoBlockComments" : false, + "NoCasesWithOnlyFallthrough" : false, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : false, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoPlaygroundLiterals" : false, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : false, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : true, + "OnlyOneTrailingClosureArgument" : false, + "OrderedImports" : true, + "ReplaceForEachWithForLoop" : false, + "ReturnVoidInsteadOfEmptyTuple" : false, + "TypeNamesShouldBeCapitalized" : false, + "UseEarlyExits" : false, + "UseLetInEveryBoundCaseVariable" : false, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : true, + "UseSynthesizedInitializer" : false, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + }, + "spacesAroundRangeFormationOperators" : false, + "tabWidth" : 2, + "version" : 1 +} diff --git a/Makefile b/Makefile index 6d065827..92efbf8a 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,9 @@ ifeq (,$(wildcard bin/vmlinux)) @cp .local/vmlinux bin/vmlinux endif +.PHONY: check +check: swift-fmt-check check-licenses + .PHONY: fmt fmt: swift-fmt update-licenses @@ -135,6 +138,10 @@ swift-fmt: @echo Applying the standard code formatting... @$(SWIFT) format --recursive --configuration .swift-format -i $(SWIFT_SRC) +swift-fmt-check: + @echo Applying the standard code formatting... + @$(SWIFT) format lint --recursive --strict --configuration .swift-format-nolint $(SWIFT_SRC) + .PHONY: update-licenses update-licenses: @echo Updating license headers... @@ -147,6 +154,15 @@ check-licenses: @./scripts/ensure-hawkeye-exists.sh @.local/bin/hawkeye check --fail-if-unknown +.PHONY: pre-commit +pre-commit: + cp Scripts/pre-commit.fmt .git/hooks + touch .git/hooks/pre-commit + cat .git/hooks/pre-commit | grep -v 'hooks/pre-commit\.fmt' > /tmp/pre-commit.new || true + echo 'PRECOMMIT_NOFMT=$${PRECOMMIT_NOFMT} $$(git rev-parse --show-toplevel)/.git/hooks/pre-commit.fmt' >> /tmp/pre-commit.new + mv /tmp/pre-commit.new .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + .PHONY: serve-docs serve-docs: @echo 'to browse: open http://127.0.0.1:8000/containerization/documentation/' diff --git a/README.md b/README.md index ad780a59..bfb40ddb 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,10 @@ make protos If you'd like to build your own kernel please see the instructions in the [kernel directory](./kernel/README.md). +## Pre-commit hook + +Run `make pre-commit` to install a pre-commit hook that ensures that your changes have correct formatting and license headers when you run `git commit`. + ## Documentation Generate the API documentation for local viewing with: diff --git a/Sources/ContainerizationOCI/Platform.swift b/Sources/ContainerizationOCI/Platform.swift index 5828decf..a9c17482 100644 --- a/Sources/ContainerizationOCI/Platform.swift +++ b/Sources/ContainerizationOCI/Platform.swift @@ -194,20 +194,18 @@ public struct Platform: Sendable, Equatable { } extension Platform: Hashable { - /** - `~=` compares two platforms to check if **lhs** platform images are compatible with **rhs** platform - This operator can be used to check if an image of **lhs** platform can run on **rhs**: - - `true`: when **rhs**=`arm/v8`, **lhs** is any of `arm/v8`, `arm/v7`, `arm/v6` and `arm/v5` - - `true`: when **rhs**=`arm/v7`, **lhs** is any of `arm/v7`, `arm/v6` and `arm/v5` - - `true`: when **rhs**=`arm/v6`, **lhs** is any of `arm/v6` and `arm/v5` - - `true`: when **rhs**=`amd64`, **lhs** is any of `amd64` and `386` - - `true`: when **rhs**=**lhs** - - `false`: otherwise - - Parameters: - - lhs: platform whose compatibility is being checked - - rhs: platform against which compatibility is being checked - - Returns: `true | false` - */ + /// `~=` compares two platforms to check if **lhs** platform images are compatible with **rhs** platform + /// This operator can be used to check if an image of **lhs** platform can run on **rhs**: + /// - `true`: when **rhs**=`arm/v8`, **lhs** is any of `arm/v8`, `arm/v7`, `arm/v6` and `arm/v5` + /// - `true`: when **rhs**=`arm/v7`, **lhs** is any of `arm/v7`, `arm/v6` and `arm/v5` + /// - `true`: when **rhs**=`arm/v6`, **lhs** is any of `arm/v6` and `arm/v5` + /// - `true`: when **rhs**=`amd64`, **lhs** is any of `amd64` and `386` + /// - `true`: when **rhs**=**lhs** + /// - `false`: otherwise + /// - Parameters: + /// - lhs: platform whose compatibility is being checked + /// - rhs: platform against which compatibility is being checked + /// - Returns: `true | false` public static func ~= (lhs: Platform, rhs: Platform) -> Bool { if lhs.os == rhs.os { if lhs._rawArch == rhs._rawArch { diff --git a/scripts/pre-commit.fmt b/scripts/pre-commit.fmt new file mode 100755 index 00000000..58c96269 --- /dev/null +++ b/scripts/pre-commit.fmt @@ -0,0 +1,16 @@ +#! /bin/bash -e + +setup_error() { + echo failed to run: $1 1>&2 + echo run '"make pre-commit"' and try again 1>&2 + exit 1 +} + +if [ ! -z "${PRECOMMIT_NOFMT}" ] ; then + exit 0 +fi + +echo checking formatting and licenses 1>&2 +project_pathname=$(git rev-parse --show-toplevel) +cd "${project_pathname}" +make check