Skip to content

Commit aea4ba6

Browse files
committed
Formatting: omit explicit returns where possible
This commit sets up `.swift-format` rule to omit returns.
1 parent a381b0d commit aea4ba6

File tree

130 files changed

+525
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+525
-524
lines changed

.swift-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"AlwaysUseLowerCamelCase": false,
1111
"AmbiguousTrailingClosureOverload": false,
1212
"NoBlockComments": false,
13+
"OmitExplicitReturns": true,
1314
"OrderedImports": true,
1415
"UseLetInEveryBoundCaseVariable": false,
1516
"UseSynthesizedInitializer": false

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class Child {
108108

109109
/// A name of this child that's suitable to be used for variable or enum case names.
110110
public var varOrCaseName: TokenSyntax {
111-
return .identifier(lowercaseFirstWord(name: name))
111+
.identifier(lowercaseFirstWord(name: name))
112112
}
113113

114114
/// If this child has node choices, the type that the nested `SyntaxChildChoices` type should get.
@@ -137,7 +137,7 @@ public class Child {
137137

138138
/// Determines if this child has a deprecated name
139139
public var hasDeprecatedName: Bool {
140-
return deprecatedName != nil
140+
deprecatedName != nil
141141
}
142142

143143
/// If the child ends with "token" in the kind, it's considered a token node.

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class Node {
6060
/// A name for this node that is suitable to be used as a variables or enum
6161
/// case's name.
6262
public var varOrCaseName: TokenSyntax {
63-
return kind.varOrCaseName
63+
kind.varOrCaseName
6464
}
6565

6666
/// If this is a layout node, return a view of the node that provides access
@@ -264,7 +264,7 @@ public struct LayoutNode {
264264

265265
/// Allow transparent accesss to the properties of the underlying `Node`.
266266
public subscript<T>(dynamicMember keyPath: KeyPath<Node, T>) -> T {
267-
return node[keyPath: keyPath]
267+
node[keyPath: keyPath]
268268
}
269269

270270
/// The children of the layout node.
@@ -281,7 +281,7 @@ public struct LayoutNode {
281281

282282
/// All children in the node that are not unexpected.
283283
public var nonUnexpectedChildren: [Child] {
284-
return children.filter { !$0.isUnexpectedNodes }
284+
children.filter { !$0.isUnexpectedNodes }
285285
}
286286

287287
/// Traits that the node conforms to.
@@ -328,7 +328,7 @@ public struct CollectionNode {
328328

329329
/// Allow transparent access to the properties of the underlying `Node`.
330330
public subscript<T>(dynamicMember keyPath: KeyPath<Node, T>) -> T {
331-
return node[keyPath: keyPath]
331+
node[keyPath: keyPath]
332332
}
333333

334334
/// The kinds the elements can have.

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
333333
/// A name for this node that is suitable to be used as a variables or enum
334334
/// case's name.
335335
public var varOrCaseName: TokenSyntax {
336-
return .identifier(rawValue)
336+
.identifier(rawValue)
337337
}
338338

339339
/// The type name of this node in the SwiftSyntax module.
@@ -351,12 +351,12 @@ public enum SyntaxNodeKind: String, CaseIterable {
351351
/// For base nodes, the name of the corresponding protocol to which all the
352352
/// concrete nodes that have this base kind, conform.
353353
public var protocolType: TypeSyntax {
354-
return "\(syntaxType)Protocol"
354+
"\(syntaxType)Protocol"
355355
}
356356

357357
/// The name of this node at the `RawSyntax` level.
358358
public var rawType: TypeSyntax {
359-
return "Raw\(syntaxType)"
359+
"Raw\(syntaxType)"
360360
}
361361

362362
/// For base nodes, the name of the corresponding raw protocol to which all the

CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public struct TokenSpec {
7575
/// - name: A name of the token.
7676
/// - text: An actual text of the punctuation token.
7777
static func punctuator(name: String, text: String) -> TokenSpec {
78-
return TokenSpec(
78+
TokenSpec(
7979
name: name,
8080
nameForDiagnostics: text,
8181
text: text,
@@ -89,7 +89,7 @@ public struct TokenSpec {
8989
/// - name: A name of the token.
9090
/// - text: An actual text of the pound keyword token.
9191
static func poundKeyword(name: String, text: String) -> TokenSpec {
92-
return TokenSpec(
92+
TokenSpec(
9393
name: name,
9494
nameForDiagnostics: text,
9595
text: text,
@@ -104,7 +104,7 @@ public struct TokenSpec {
104104
/// - nameForDiagnostics: A name of the token that can be shown in diagnostics.
105105
/// - text: An actual text of the token, if available.
106106
static func other(name: String, nameForDiagnostics: String, text: String? = nil) -> TokenSpec {
107-
return TokenSpec(
107+
TokenSpec(
108108
name: name,
109109
nameForDiagnostics: nameForDiagnostics,
110110
text: text,

CodeGeneration/Sources/Utils/CodeGenerationFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class CodeGenerationFormat: BasicFormat {
9999
private func shouldBeSeparatedByTwoNewlines(node: CodeBlockItemSyntax) -> Bool {
100100
// First item in the ``CodeBlockItemListSyntax`` don't need a newline or indentation if the parent is a ``SourceFileSyntax``.
101101
// We want to group imports so newline between them should be omitted
102-
return node.parent?.as(CodeBlockItemListSyntax.self)?.first == node || node.item.is(ImportDeclSyntax.self)
102+
node.parent?.as(CodeBlockItemListSyntax.self)?.first == node || node.item.is(ImportDeclSyntax.self)
103103
}
104104

105105
private func ensuringTwoLeadingNewlines<NodeType: SyntaxProtocol>(node: NodeType) -> NodeType {

CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public extension Child {
5454
}
5555

5656
var parameterType: TypeSyntax {
57-
return self.buildableType.optionalWrapped(type: parameterBaseType)
57+
self.buildableType.optionalWrapped(type: parameterBaseType)
5858
}
5959

6060
var defaultValue: ExprSyntax? {

CodeGeneration/Sources/Utils/SyntaxBuildableType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public struct SyntaxBuildableType: Hashable {
133133
/// which will eventually get built from `SwiftSyntaxBuilder`. If the type
134134
/// is optional, this terminates with a `?`.
135135
public var syntax: TypeSyntax {
136-
return optionalWrapped(type: syntaxBaseName)
136+
optionalWrapped(type: syntaxBaseName)
137137
}
138138

139139
/// The type that is used for parameters in SwiftSyntaxBuilder that take this
@@ -147,7 +147,7 @@ public struct SyntaxBuildableType: Hashable {
147147
}
148148

149149
public var parameterType: TypeSyntax {
150-
return optionalWrapped(type: parameterBaseType)
150+
optionalWrapped(type: parameterBaseType)
151151
}
152152

153153
/// Assuming that this is a collection type, the non-optional type of the result builder

CodeGeneration/Sources/Utils/Utils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ extension String {
2121

2222
/// Removes all empty lines from a multi-line string.
2323
public var removingEmptyLines: String {
24-
return
25-
self
24+
25+
self
2626
.split(whereSeparator: \.isNewline)
2727
.filter { !$0.allSatisfy(\.isWhitespace) }
2828
.joined(separator: "\n")

CodeGeneration/Sources/generate-swift-syntax/GenerateSwiftSyntax.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct GeneratedFileSpec {
3939
let pathComponents: [String]
4040
private let contentsGenerator: () -> String
4141
var contents: String {
42-
return self.contentsGenerator()
42+
self.contentsGenerator()
4343
}
4444

4545
init(_ pathComponents: [String], _ contents: @escaping @autoclosure () -> String) {
@@ -55,7 +55,7 @@ struct GeneratedFileSpec {
5555
struct TemplateSpec {
5656
let sourceFileGenerator: () -> SourceFileSyntax
5757
var sourceFile: SourceFileSyntax {
58-
return self.sourceFileGenerator()
58+
self.sourceFileGenerator()
5959
}
6060
let module: String
6161
let filename: String

0 commit comments

Comments
 (0)