Skip to content

Commit

Permalink
Update from Hummingbird Project Template (#619)
Browse files Browse the repository at this point in the history
* Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef

* Run swift-format

* Remove .swiftformat

---------

Co-authored-by: adam-fowler <[email protected]>
Co-authored-by: Adam Fowler <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2024
1 parent c0754a8 commit 08b9e86
Show file tree
Hide file tree
Showing 90 changed files with 1,004 additions and 672 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ concurrency:

jobs:
validate:
runs-on: macOS-latest
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
brew install mint
mint install NickLockwood/[email protected] --no-link
- name: run script
run: ./scripts/validate.sh
63 changes: 63 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 150,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"multiElementCollectionTrailingCommas" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"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,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
26 changes: 0 additions & 26 deletions .swiftformat

This file was deleted.

8 changes: 4 additions & 4 deletions Benchmarks/Benchmarks/Router/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import Hummingbird

let benchmarks = {
Benchmark.defaultConfiguration = .init(
metrics: ProcessInfo.processInfo.environment["CI"] != nil ?
[
metrics: ProcessInfo.processInfo.environment["CI"] != nil
? [
.instructions,
.mallocCountTotal,
] :
[
]
: [
.cpuTotal,
.instructions,
.mallocCountTotal,
Expand Down
16 changes: 10 additions & 6 deletions Benchmarks/Benchmarks/Router/RouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension Benchmark {

struct EmptyMiddleware<Context>: RouterMiddleware {
func handle(_ request: Request, context: Context, next: (Request, Context) async throws -> Response) async throws -> Response {
return try await next(request, context)
try await next(request, context)
}
}

Expand Down Expand Up @@ -170,12 +170,16 @@ func routerBenchmarks() {
} createRouter: {
let router = Router(context: BasicBenchmarkContext.self)
router.post { request, _ in
Response(status: .ok, headers: [:], body: .init { writer in
for try await buffer in request.body {
try await writer.write(buffer)
Response(
status: .ok,
headers: [:],
body: .init { writer in
for try await buffer in request.body {
try await writer.write(buffer)
}
try await writer.finish(nil)
}
try await writer.finish(nil)
})
)
}
return router
}
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let package = Package(
],
path: "Benchmarks/Router",
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
),
)
]
)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The main development branch of the repository is `main`.

### Formatting

We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.53.10.
We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted.
34 changes: 19 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,26 @@ let package = Package(
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
),
// test targets
.testTarget(name: "HummingbirdTests", dependencies: [
.byName(name: "Hummingbird"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
.byName(name: "HummingbirdRouter"),
]),
.testTarget(name: "HummingbirdRouterTests", dependencies: [
.byName(name: "HummingbirdRouter"),
.byName(name: "HummingbirdTesting"),
]),
.testTarget(
name: "HummingbirdTests",
dependencies: [
.byName(name: "Hummingbird"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
.byName(name: "HummingbirdRouter"),
]
),
.testTarget(
name: "HummingbirdRouterTests",
dependencies: [
.byName(name: "HummingbirdRouter"),
.byName(name: "HummingbirdTesting"),
]
),
.testTarget(
name: "HummingbirdCoreTests",
dependencies:
[
dependencies: [
.byName(name: "HummingbirdCore"),
.byName(name: "HummingbirdTLS"),
.byName(name: "HummingbirdTesting"),
Expand All @@ -147,8 +152,7 @@ let package = Package(
),
.testTarget(
name: "HummingbirdHTTP2Tests",
dependencies:
[
dependencies: [
.byName(name: "HummingbirdCore"),
.byName(name: "HummingbirdHTTP2"),
.byName(name: "HummingbirdTesting"),
Expand Down
5 changes: 3 additions & 2 deletions Sources/Hummingbird/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ extension ApplicationProtocol {
/// try await app.runService()
/// ```
/// Editing the application setup after calling `runService` will produce undefined behaviour.
public struct Application<Responder: HTTPResponder>: ApplicationProtocol where Responder.Context: InitializableFromSource<ApplicationRequestContextSource> {
public struct Application<Responder: HTTPResponder>: ApplicationProtocol
where Responder.Context: InitializableFromSource<ApplicationRequestContextSource> {
// MARK: Member variables

/// event loop group used by application
Expand Down Expand Up @@ -280,7 +281,7 @@ public struct Application<Responder: HTTPResponder>: ApplicationProtocol where R
}

public func buildResponder() async throws -> Responder {
return self.responder
self.responder
}

public func onServerRunning(_ channel: Channel) async {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Hummingbird/Codable/JSON/JSONCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
//
//===----------------------------------------------------------------------===//

import NIOFoundationCompat

import struct Foundation.Date
import class Foundation.JSONDecoder
import class Foundation.JSONEncoder
import NIOFoundationCompat

extension JSONEncoder: ResponseEncoder {
/// Extend JSONEncoder to support encoding `Response`'s. Sets body and header values
Expand Down
6 changes: 3 additions & 3 deletions Sources/Hummingbird/Codable/ResponseEncodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public protocol ResponseCodable: ResponseEncodable, Decodable {}
/// Extend ResponseEncodable to conform to ResponseGenerator
extension ResponseEncodable {
public func response(from request: Request, context: some RequestContext) throws -> Response {
return try context.responseEncoder.encode(self, from: request, context: context)
try context.responseEncoder.encode(self, from: request, context: context)
}
}

Expand All @@ -34,7 +34,7 @@ extension Array: ResponseGenerator where Element: Encodable {}
/// Extend Array to conform to ResponseEncodable
extension Array: ResponseEncodable where Element: Encodable {
public func response(from request: Request, context: some RequestContext) throws -> Response {
return try context.responseEncoder.encode(self, from: request, context: context)
try context.responseEncoder.encode(self, from: request, context: context)
}
}

Expand All @@ -44,6 +44,6 @@ extension Dictionary: ResponseGenerator where Key: Encodable, Value: Encodable {
/// Extend Array to conform to ResponseEncodable
extension Dictionary: ResponseEncodable where Key: Encodable, Value: Encodable {
public func response(from request: Request, context: some RequestContext) throws -> Response {
return try context.responseEncoder.encode(self, from: request, context: context)
try context.responseEncoder.encode(self, from: request, context: context)
}
}
Loading

0 comments on commit 08b9e86

Please sign in to comment.