Skip to content

Commit

Permalink
[Generator] Consistent style for initializing local variables (#159)
Browse files Browse the repository at this point in the history
[Generator] Consistent style for initializing local variables

### Motivation

Move to a consistent style when initializing local variables, always use `let foo = Foo(...)` vs `let foo: Foo = .init(...)`.

### Modifications

Updated all occurrences of the latter to use the former.

Also updated for the generated code.

### Result

Consistent local variable initialization.

### Test Plan

All tests passed.


Reviewed by: gjcairo, simonjbeaumont

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#159
  • Loading branch information
czechboy0 authored Aug 1, 2023
1 parent 8d5b397 commit 16420df
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ extension ClientFileTranslator {
.identifier(Constants.Operations.namespace)
.dot(description.methodName)

let operationArg: FunctionArgumentDescription = .init(
let operationArg = FunctionArgumentDescription(
label: "forOperation",
expression: operationTypeExpr.dot("id")
)
let inputArg: FunctionArgumentDescription = .init(
let inputArg = FunctionArgumentDescription(
label: "input",
expression: .identifier(Constants.Operation.Input.variableName)
)
let serializerArg: FunctionArgumentDescription = .init(
let serializerArg = FunctionArgumentDescription(
label: "serializer",
expression: try translateClientSerializer(description)
)
let deserializerArg: FunctionArgumentDescription = .init(
let deserializerArg = FunctionArgumentDescription(
label: "deserializer",
expression: try translateClientDeserializer(description)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension FileTranslator {
let knownKeys =
properties
.map(\.originalName)
let knownKeysFunctionArg: FunctionArgumentDescription = .init(
let knownKeysFunctionArg = FunctionArgumentDescription(
label: "knownKeys",
expression: .literal(
.array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extension FileTranslator {
typeUsage = valueTypeUsage.asDictionaryValue
}

let extraProperty: PropertyBlueprint = .init(
let extraProperty = PropertyBlueprint(
comment: .doc("A container of undocumented properties."),
originalName: "additionalProperties",
typeUsage: typeUsage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension FileTranslator {
]
)
}
let unknownCase: SwitchCaseDescription = .init(
let unknownCase = SwitchCaseDescription(
kind: .default,
body: [
.expression(
Expand Down Expand Up @@ -126,7 +126,7 @@ extension FileTranslator {
]
)
}
let unknownCase: SwitchCaseDescription = .init(
let unknownCase = SwitchCaseDescription(
kind: .case(
.valueBinding(
kind: .let,
Expand All @@ -147,7 +147,7 @@ extension FileTranslator {
]
)

let variableDescription: VariableDescription = .init(
let variableDescription = VariableDescription(
accessModifier: config.access,
kind: .var,
left: "rawValue",
Expand Down Expand Up @@ -186,7 +186,7 @@ extension FileTranslator {
)
}

let enumDescription: EnumDescription = .init(
let enumDescription = EnumDescription(
isFrozen: true,
accessModifier: config.access,
name: typeName.shortSwiftName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension FileTranslator {
userDescription: String?,
to existingTypeUsage: TypeUsage
) throws -> Declaration {
let typealiasDescription: TypealiasDescription = .init(
let typealiasDescription = TypealiasDescription(
accessModifier: config.access,
name: typeName.shortSwiftName,
existingType: existingTypeUsage.fullyQualifiedNonOptionalSwiftName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extension ClientFileTranslator {
])
)
)
let caseDesc: SwitchCaseDescription = .init(
let caseDesc = SwitchCaseDescription(
kind: .case(.dot(contentTypeIdentifier), ["value"]),
body: [
.expression(bodyAssignExpr)
Expand All @@ -213,7 +213,7 @@ extension ClientFileTranslator {
return caseDesc
}
if !requestBody.request.required {
let noneCase: SwitchCaseDescription = .init(
let noneCase = SwitchCaseDescription(
kind: .case(.dot("none")),
body: [
.expression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ extension ServerFileTranslator {
let responseVarDecl: Declaration = .variable(
kind: .var,
left: "response",
type: "Response",
right: .dot("init")
right: .identifier("Response")
.call([
.init(label: "statusCode", expression: statusCodeExpr)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ extension ServerFileTranslator {
.identifier(Constants.Operations.namespace)
.dot(description.methodName)

let operationArg: FunctionArgumentDescription = .init(
let operationArg = FunctionArgumentDescription(
label: "forOperation",
expression: operationTypeExpr.dot("id")
)
let requestArg: FunctionArgumentDescription = .init(
let requestArg = FunctionArgumentDescription(
label: "request",
expression: .identifier("request")
)
let metadataArg: FunctionArgumentDescription = .init(
let metadataArg = FunctionArgumentDescription(
label: "with",
expression: .identifier("metadata")
)
let methodArg: FunctionArgumentDescription = .init(
let methodArg = FunctionArgumentDescription(
label: "using",
expression: .closureInvocation(
body: [
Expand All @@ -218,11 +218,11 @@ extension ServerFileTranslator {
]
)
)
let deserializerArg: FunctionArgumentDescription = .init(
let deserializerArg = FunctionArgumentDescription(
label: "deserializer",
expression: try translateServerDeserializer(description)
)
let serializerArg: FunctionArgumentDescription = .init(
let serializerArg = FunctionArgumentDescription(
label: "serializer",
expression: try translateServerSerializer(description)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension TypesFileTranslator {
operations
.map(translateAPIProtocolDeclaration(operation:))

let protocolDescription: ProtocolDescription = .init(
let protocolDescription = ProtocolDescription(
accessModifier: config.access,
name: Constants.APIProtocol.typeName,
conformances: Constants.APIProtocol.conformances,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import XCTest

final class Test_TextBasedRenderer: XCTestCase {

var renderer: TextBasedRenderer = .init()
var renderer = TextBasedRenderer()

func testComment() throws {
try _test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
switch output {
case let .ok(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 200)
var response = Response(statusCode: 200)
suppressMutabilityWarning(&response)
try converter.setHeaderFieldAsText(
in: &response.headerFields,
Expand All @@ -141,7 +141,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
return response
case let .`default`(statusCode, value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: statusCode)
var response = Response(statusCode: statusCode)
suppressMutabilityWarning(&response)
switch value.body {
case let .json(value):
Expand Down Expand Up @@ -203,7 +203,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
switch output {
case let .created(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 201)
var response = Response(statusCode: 201)
suppressMutabilityWarning(&response)
try converter.setHeaderFieldAsJSON(
in: &response.headerFields,
Expand All @@ -225,7 +225,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
return response
case let .badRequest(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 400)
var response = Response(statusCode: 400)
suppressMutabilityWarning(&response)
try converter.setHeaderFieldAsText(
in: &response.headerFields,
Expand Down Expand Up @@ -277,7 +277,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
switch output {
case let .noContent(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 204)
var response = Response(statusCode: 204)
suppressMutabilityWarning(&response)
return response
case let .undocumented(statusCode, _): return .init(statusCode: statusCode)
Expand Down Expand Up @@ -328,12 +328,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
switch output {
case let .noContent(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 204)
var response = Response(statusCode: 204)
suppressMutabilityWarning(&response)
return response
case let .badRequest(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 400)
var response = Response(statusCode: 400)
suppressMutabilityWarning(&response)
switch value.body {
case let .json(value):
Expand Down Expand Up @@ -398,7 +398,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
switch output {
case let .ok(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 200)
var response = Response(statusCode: 200)
suppressMutabilityWarning(&response)
switch value.body {
case let .binary(value):
Expand All @@ -415,7 +415,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
return response
case let .preconditionFailed(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 412)
var response = Response(statusCode: 412)
suppressMutabilityWarning(&response)
switch value.body {
case let .json(value):
Expand All @@ -432,7 +432,7 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
return response
case let .internalServerError(value):
suppressUnusedWarning(value)
var response: Response = .init(statusCode: 500)
var response = Response(statusCode: 500)
suppressMutabilityWarning(&response)
switch value.body {
case let .text(value):
Expand Down

0 comments on commit 16420df

Please sign in to comment.