Skip to content

swift-format experiments #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
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")
]
),
)
]
)
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