Skip to content

Commit

Permalink
Merge pull request #8 from magicbell/issue-5-formatting
Browse files Browse the repository at this point in the history
Dev improvements: formatting, linting, git hooks
  • Loading branch information
stigi authored Oct 21, 2024
2 parents a14940f + a559dbe commit e074540
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/spm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
${{ runner.os }}-spm-
- name: Build
run: swift build --build-tests
- name: Lint
run: swift format lint --parallel --recursive --strict Package.swift Sources Tests
- name: Test
run: swift test --parallel --skip-build --xunit-output ./reports/xcunit.xml
- name: Publish Test Report
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
35 changes: 35 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Continue, even when tests fail
# We'll capture and forward the exit code, but we also want to finish echoing out logs
set +e

info () {
printf " [ \033[00;33mINFO\033[0m ] $1\n"
}

user () {
printf "\r [ \033[0;33m?\033[0m ] $1\n"
}

success () {
printf "\r\033[2K [ \033[00;32mOK\033[0m ] $1\n"
}

fail () {
printf "\r\033[2K [\033[0;31mFAIL\033[0m] $1\n"
}

info 'Running tests before pushing'

xcrun swift test
result=$?

if [[ $result == 0 ]]; then
success 'All tests passed. Proceeding with push.'
else
fail 'Test failed. Aborting push'
user 'Want to proceed to push without tests: git push --no-verify'
fi

exit $result
6 changes: 6 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"*.swift": [
"xcrun swift-format format -i --parallel",
"xcrun swift-format lint --parallel --strict"
]
}
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentConditionalCompilationBlocks" : true,
"indentSwitchCaseLabels" : false,
"indentation" : {
"spaces" : 4
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 100,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : 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,
"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,
"tabWidth" : 8,
"version" : 1
}
37 changes: 0 additions & 37 deletions .swiftformat.yml

This file was deleted.

86 changes: 0 additions & 86 deletions .swiftlint.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ Contributions are always welcome, no matter how large or small!

We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md).

## Setup

We automate some common tasks, like code formatting, linting, and release notes, using tools from the Javascript ecosystem.
We use a tool called [Husky](https://typicode.github.io/husky/) to manage our git hooks.

To enable Husky, run the following commands in the root repo directory:

```shell
yarn install
```

## Development workflow

1. Do your changes
Expand Down
2 changes: 1 addition & 1 deletion EmbeddedProvision.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
59799E302746587000BFB375 /* EmbeddedProvision.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedProvision.swift; sourceTree = "<group>"; };
59EF99B127446D6900FB2378 /* EmbeddedProvision.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EmbeddedProvision.framework; sourceTree = BUILT_PRODUCTS_DIR; };
59EF99BB27446D6900FB2378 /* EmbeddedProvisionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EmbeddedProvisionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
59EF99C027446D6900FB2378 /* EmbeddedProvisionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedProvisionTests.swift; sourceTree = "<group>"; };
59EF99C027446D6900FB2378 /* EmbeddedProvisionTests.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = EmbeddedProvisionTests.swift; sourceTree = "<group>"; tabWidth = 4; };
9400259E2CC12857000C9264 /* Entitlements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Entitlements.swift; sourceTree = "<group>"; };
94691DA12CBFDE900046785A /* APSEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APSEnvironment.swift; sourceTree = "<group>"; };
94691DA42CBFE83D0046785A /* embedded.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = embedded.mobileprovision; sourceTree = "<group>"; };
Expand Down
12 changes: 6 additions & 6 deletions Tests/Bundle+Testing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ extension Bundle {
static func fixturesBaseURL() -> URL {
// Swift Package Manager provides `Bundle.module` which is not available in Foundation by default
// Also See https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
#if NOT_SPM
return Bundle(for: BundleFinder.self).bundleURL
#else
let resourceBundle = Bundle(url: Bundle.module.resourceURL!)!
return resourceBundle.resourceURL!
#endif
#if NOT_SPM
return Bundle(for: BundleFinder.self).bundleURL
#else
let resourceBundle = Bundle(url: Bundle.module.resourceURL!)!
return resourceBundle.resourceURL!
#endif
}

}
16 changes: 11 additions & 5 deletions Tests/EmbeddedProvisionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let existingProvisionURL: URL = {
return fixturesBaseURL.appendingPathComponent("embedded.mobileprovision")
}()

let missingProvisionURL: URL = URL(fileURLWithPath: "/tmp/non-existent.provisionprofile")
let missingProvisionURL: URL = URL(
fileURLWithPath: "/tmp/non-existent.provisionprofile")

@Suite("Loading")
struct EmbeddedProvisionLoading {
Expand All @@ -27,7 +28,7 @@ struct EmbeddedProvisionLoading {
}

@Test("is nil for missing provision in test bundle")
func embeddedProvisionPlist_onTestBundleProvision_isNil() throws {
func defaultProvision() throws {
let provision = try! EmbeddedProvision.load()

#expect(provision == nil)
Expand All @@ -41,7 +42,8 @@ struct EmbeddedProvisionProperties {
// public let entitlements: Entitlements
@Test("parses name")
func name() throws {
#expect(provision.name == "iOS Team Provisioning Profile: pushinfo.example")
#expect(
provision.name == "iOS Team Provisioning Profile: pushinfo.example")
}

@Test("parses app ID")
Expand Down Expand Up @@ -72,11 +74,15 @@ struct EmbeddedProvisionProperties {

@Suite("Entitlement parsing")
struct EmbeddedProvisionEntitlements {
let entitlements = try! EmbeddedProvision.load(from: existingProvisionURL).entitlements
let entitlements = try! EmbeddedProvision.load(from: existingProvisionURL)
.entitlements

@Test("parses keychainAccessGroups")
func keychainAccessGroups() throws {
#expect(entitlements.keychainAccessGroups == ["7847W99F5L.*", "com.apple.token"])
#expect(
entitlements.keychainAccessGroups == [
"7847W99F5L.*", "com.apple.token",
])
}

@Test("parses getTaskAllow")
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"replace-in-file": "^8.2.0",
"tsx": "^4.19.1"
},
"scripts": {
"changeset": "./scripts/changeset-wrapper.sh"
"changeset": "./scripts/changeset-wrapper.sh",
"prepare": "husky"
}
}
Loading

0 comments on commit e074540

Please sign in to comment.