Skip to content
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

swift-format experiments #617

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

swift-format experiments #617

wants to merge 10 commits into from

Conversation

adam-fowler
Copy link
Member

Experimenting with moving to swift-format
So far I copied the .swift-format from swift-nio and ran swift format on the Tests and Sources folders

@adam-fowler adam-fowler marked this pull request as draft November 21, 2024 17:50
@adam-fowler
Copy link
Member Author

Running swift format lint brings up a few issues as well

Sources/HummingbirdCore/Utils/HBParser.swift:677:21: warning: [NoBlockComments] replace this block comment with line comments
/Users/adamfowler/Developer/server/hummingbird-project/hummingbird/Sources/HummingbirdCore/Utils/HBParser.swift:61:113: warning: [EndOfLineComment] move end-of-line comment that exceeds the line length
Sources/Hummingbird/Environment.swift:140:17: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression
Sources/Hummingbird/Codable/URLEncodedForm/URLEncodedFormNode.swift:31:19: warning: [ReplaceForEachWithForLoop] replace use of '.forEach { ... }' with for-in loop
Sources/Hummingbird/Codable/URLEncodedForm/URLEncodedFormNode.swift:179:36: warning: [OneCasePerLine] move 'map' to its own 'case' declaration
Sources/Hummingbird/Codable/URLEncodedForm/URLEncodedFormNode.swift:179:59: warning: [OneCasePerLine] move 'arrayWithIndices' to its own 'case' declaration
Sources/Hummingbird/Server/RequestID.swift:39:24: warning: [DontRepeatTypeInStaticProperties] remove the suffix 'RequestID' from the name of the variable 'globalRequestID'
Sources/Hummingbird/HTTP/MediaType.swift:400:16: warning: [DontRepeatTypeInStaticProperties] remove the suffix 'MediaType' from the name of the variable 'extensionMediaTypeMap'
Sources/Hummingbird/Router/Router.swift:60:23: warning: [ReplaceForEachWithForLoop] replace use of '.forEach { ... }' with for-in loop

Copy link

github-actions bot commented Nov 21, 2024

Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot, just one thing that's annoying IMO. But I can live with it if it's not fixable


extension JSONEncoder: ResponseEncoder {
/// Extend JSONEncoder to support encoding `Response`'s. Sets body and header values
/// - Parameters:
/// - value: Value to encode
/// - request: Request used to generate response
/// - context: Request context
public func encode(_ value: some Encodable, from request: Request, context: some RequestContext) throws -> Response {
public func encode(_ value: some Encodable, from request: Request, context: some RequestContext) throws -> Response
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of formatting is super annoying, is that configurable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I haven't worked out how to stop that. Not very keen on it

@@ -18,7 +18,8 @@ extension URLEncodedFormEncoder: ResponseEncoder {
/// - value: Value to encode
/// - request: Request used to generate response
/// - context: Request context
public func encode(_ value: some Encodable, from request: Request, context: some RequestContext) throws -> Response {
public func encode(_ value: some Encodable, from request: Request, context: some RequestContext) throws -> Response
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"

@@ -310,7 +334,8 @@ final class RouterTests: XCTestCase {
}
let app = Application(responder: router)
try await app.test(.router) { client in
try await client.execute(uri: "/test/group", method: .get, headers: [.middleware2: "Transforming"]) { response in
try await client.execute(uri: "/test/group", method: .get, headers: [.middleware2: "Transforming"]) {
response in
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Joannis this is pretty horrible as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants