Skip to content

.swift-format: Specify an exhaustive configuration #3117

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
70 changes: 64 additions & 6 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,78 @@
{
"version": 1,
"lineLength": 120,
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"indentation": {
"spaces": 2
},
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": true,
"indentConditionalCompilationBlocks": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineBreakBetweenDeclarationAttributes": false,
"lineLength": 120,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": true,
"reflowMultilineStringLiterals": {
"never": {

}
},
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"AvoidRetroactiveConformances": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": false,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoAssignmentInExpressions": true,
"NoBlockComments": false,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyLinesOpeningClosingBraces": false,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": false,
"ReturnVoidInsteadOfEmptyTuple": true,
"NoVoidReturnOnFunctionSignature": true,
}
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"spacesBeforeEndOfLineComments": 2,
"version": 1,
}
6 changes: 3 additions & 3 deletions CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ public class Child: NodeChoiceConvertible {

public var syntaxNodeKind: SyntaxNodeKind {
switch kind {
case .node(kind: let kind):
case .node(let kind):
return kind
case .nodeChoices:
return .syntax
case .collection(kind: let kind, _, _, _, _):
case .collection(let kind, _, _, _, _):
return kind
case .token:
return .token
Expand Down Expand Up @@ -284,7 +284,7 @@ public class Child: NodeChoiceConvertible {
return choices.isEmpty
case .node(let kind):
return kind.isBase
case .collection(kind: let kind, _, _, _, _):
case .collection(let kind, _, _, _, _):
return kind.isBase
case .token:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct GrammarGenerator {
case .nodeChoices(let choices, _):
let choicesDescriptions = choices.map { grammar(for: $0) }
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
case .collection(kind: let kind, _, _, _, _):
case .collection(let kind, _, _, _, _):
return "\(kind.doccLink)\(optionality)"
case .token(let choices, _, _):
if choices.count == 1 {
Expand Down
12 changes: 6 additions & 6 deletions CodeGeneration/Sources/SyntaxSupport/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public struct LayoutNode {
/// This includes unexpected children
public var children: [Child] {
switch node.data {
case .layout(children: let children, childHistory: _, traits: _):
case .layout(let children, childHistory: _, traits: _):
return children
case .collection:
preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`")
Expand All @@ -299,7 +299,7 @@ public struct LayoutNode {
/// The history of the layout node's children.
public var childHistory: Child.History {
switch node.data {
case .layout(children: _, childHistory: let childHistory, traits: _):
case .layout(children: _, let childHistory, traits: _):
return childHistory
case .collection:
preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`")
Expand All @@ -309,7 +309,7 @@ public struct LayoutNode {
/// Traits that the node conforms to.
public var traits: [String] {
switch node.data {
case .layout(children: _, childHistory: _, traits: let traits):
case .layout(children: _, childHistory: _, let traits):
return traits
case .collection:
preconditionFailure("NodeLayoutView must wrap a Node with data `.layout`")
Expand Down Expand Up @@ -361,7 +361,7 @@ public struct CollectionNode {
switch node.data {
case .layout:
preconditionFailure("NodeLayoutView must wrap a Node with data `.collection`")
case .collection(choices: let choices):
case .collection(let choices):
return choices
}
}
Expand Down Expand Up @@ -391,15 +391,15 @@ fileprivate extension Child {
return [kind]
case .nodeChoices(let choices, _):
return choices.flatMap(\.kinds)
case .collection(kind: let kind, _, _, _, _):
case .collection(let kind, _, _, _, _):
return [kind]
case .token:
return [.token]
}
}
}

fileprivate func interleaveUnexpectedChildren(_ children: [Child]) -> [Child] {
private func interleaveUnexpectedChildren(_ children: [Child]) -> [Child] {
let liftedChildren = children.lazy.map(Optional.some)
let pairedChildren = zip([nil] + liftedChildren, liftedChildren + [nil])

Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/Utils/SyntaxBuildableChild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ extension Child {
public var buildableType: SyntaxBuildableType {
let buildableKind: SyntaxOrTokenNodeKind
switch kind {
case .node(kind: let kind):
case .node(let kind):
buildableKind = .node(kind: kind)
case .nodeChoices:
buildableKind = .node(kind: .syntax)
case .collection(kind: let kind, _, _, _, _):
case .collection(let kind, _, _, _, _):
buildableKind = .node(kind: kind)
case .token:
buildableKind = .token(self.tokenKind!)
Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/Utils/SyntaxBuildableType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public struct SyntaxBuildableType: Hashable {
/// without any question marks attached.
public var syntaxBaseName: TypeSyntax {
switch kind {
case .node(kind: let kind):
case .node(let kind):
return kind.syntaxType
case .token:
return "TokenSyntax"
Expand Down Expand Up @@ -150,7 +150,7 @@ public struct SyntaxBuildableType: Hashable {
/// that can be used to build the collection.
public var resultBuilderType: TypeSyntax {
switch kind {
case .node(kind: let kind):
case .node(let kind):
return TypeSyntax("\(raw: kind.uppercasedFirstWordRawValue)Builder")
case .token:
preconditionFailure("Tokens cannot be constructed using result builders")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {

}

fileprivate func generateFile(
private func generateFile(
contents: @autoclosure () -> String,
destination: URL,
verbose: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension InitSignature {
}
}

fileprivate func convertFromSyntaxProtocolToSyntaxType(
private func convertFromSyntaxProtocolToSyntaxType(
child: Child
) -> ExprSyntax {
let childName = child.identifier
Expand Down Expand Up @@ -350,7 +350,7 @@ extension InitParameterMapping {
func makeArgumentExpr() -> LabeledExprSyntax {
let argValue =
switch argument {
case .decl(olderChild: let olderChild):
case .decl(let olderChild):
ExprSyntax(DeclReferenceExprSyntax(baseName: olderChild.baseCallName))

case .nestedInit(let initArgs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead
}

ExprSyntax("assertAnyHasNoError(kind, \(raw: index), \(verifiedChoices))")
case .token(choices: let choices, requiresLeadingSpace: _, requiresTrailingSpace: _):
case .token(let choices, requiresLeadingSpace: _, requiresTrailingSpace: _):
let choices = ArrayExprSyntax {
for choice in choices {
switch choice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
try! generateIsHelpers(for: "RawTriviaPiece")
}

fileprivate func generateIsHelpers(for pieceName: TokenSyntax) throws -> ExtensionDeclSyntax {
private func generateIsHelpers(for pieceName: TokenSyntax) throws -> ExtensionDeclSyntax {
func generateHelper(_ header: SyntaxNodeString, trait: TriviaTraits) throws -> VariableDeclSyntax {
try VariableDeclSyntax(header) {
try SwitchExprSyntax("switch self") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import SyntaxSupport
import XCTest

fileprivate func assertNoFailures(
private func assertNoFailures(
_ failures: [ValidationFailure],
message: String,
file: StaticString = #filePath,
Expand All @@ -34,7 +34,7 @@ fileprivate func assertNoFailures(
XCTFail(message, file: file, line: line)
}

fileprivate func assertFailuresMatchXFails(
private func assertFailuresMatchXFails(
_ failures: [ValidationFailure],
expectedFailures: [ValidationFailure],
file: StaticString = #filePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension OptionSetMacro: MemberMacro {
// Find all of the case elements.
let caseElements: [EnumCaseElementSyntax] = optionsEnum.memberBlock.members.flatMap { member in
guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
return Array<EnumCaseElementSyntax>()
return [EnumCaseElementSyntax]()
}

return Array(caseDecl.elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum URLMacro: ExpressionMacro {
throw CustomError.message("#URL requires a static string literal")
}

guard let _ = URL(string: literalSegment.content.text) else {
guard URL(string: literalSegment.content.text) != nil else {
throw CustomError.message("malformed url: \(argument)")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension EnumDeclSyntax {
var caseElements: [EnumCaseElementSyntax] {
memberBlock.members.flatMap { member in
guard let caseDecl = member.decl.as(EnumCaseDeclSyntax.self) else {
return Array<EnumCaseElementSyntax>()
return [EnumCaseElementSyntax]()
}

return Array(caseDecl.elements)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftBasicFormat/InferIndentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private class IndentationInferrer: SyntaxVisitor {
}
}

fileprivate extension Array<Int> {
fileprivate extension [Int] {
var sum: Int {
return self.reduce(0) { return $0 + $1 }
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftIDEUtils/DeclNameLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ public struct DeclNameLocation: Equatable {
case .labeled(let firstName, let secondName):
let endPosition = secondName?.upperBound ?? firstName.upperBound
return firstName.lowerBound..<endPosition
case .labeledCall(label: let label, colon: let colon):
case .labeledCall(let label, let colon):
return label.lowerBound..<colon.upperBound
case .unlabeled(argumentPosition: let argumentPosition):
case .unlabeled(let argumentPosition):
return argumentPosition..<argumentPosition
}
}

/// Shift the ranges `utf8Offset` bytes to the right, ie. add `utf8Offset` to the upper and lower bound.
func advanced(by utf8Offset: Int) -> DeclNameLocation.Argument {
switch self {
case .labeled(firstName: let firstName, secondName: let secondName):
case .labeled(let firstName, let secondName):
return .labeled(firstName: firstName.advanced(by: utf8Offset), secondName: secondName?.advanced(by: utf8Offset))
case .labeledCall(label: let label, colon: let colon):
case .labeledCall(let label, let colon):
return .labeledCall(label: label.advanced(by: utf8Offset), colon: colon.advanced(by: utf8Offset))
case .unlabeled(argumentPosition: let argumentPosition):
case .unlabeled(let argumentPosition):
return .unlabeled(argumentPosition: argumentPosition.advanced(by: utf8Offset))
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public struct DeclNameLocation: Equatable {
switch self {
case .noArguments:
return .noArguments
case .call(let arguments, firstTrailingClosureIndex: let firstTrailingClosureIndex):
case .call(let arguments, let firstTrailingClosureIndex):
return .call(
arguments.map { $0.advanced(by: utf8Offset) },
firstTrailingClosureIndex: firstTrailingClosureIndex
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftIDEUtils/SyntaxClassifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension RawTriviaPiece {
}
}

fileprivate struct TokenKindAndText {
private struct TokenKindAndText {
let kind: RawTokenKind
let text: SyntaxText

Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftIfConfig/ActiveSyntaxRewriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ActiveSyntaxRewriter: SyntaxRewriter {

// Find #ifs within the list.
if let ifConfigDecl = elementAsIfConfig(element),
(!retainFeatureCheckIfConfigs || !ifConfigDecl.containsFeatureCheck)
!retainFeatureCheckIfConfigs || !ifConfigDecl.containsFeatureCheck
{
// Retrieve the active `#if` clause
let activeClause = activeClauses.activeClause(for: ifConfigDecl, diagnostics: &diagnostics)
Expand Down Expand Up @@ -392,7 +392,7 @@ class ActiveSyntaxRewriter: SyntaxRewriter {
}

/// Helper class to find a feature or compiler check.
fileprivate class FindFeatureCheckVisitor: SyntaxVisitor {
private class FindFeatureCheckVisitor: SyntaxVisitor {
var foundFeatureCheck = false

override func visit(_ node: DeclReferenceExprSyntax) -> SyntaxVisitorContinueKind {
Expand All @@ -411,7 +411,7 @@ fileprivate class FindFeatureCheckVisitor: SyntaxVisitor {
override func visit(_ node: FunctionCallExprSyntax) -> SyntaxVisitorContinueKind {
if let calleeDeclRef = node.calledExpression.as(DeclReferenceExprSyntax.self),
let calleeName = calleeDeclRef.simpleIdentifier?.name,
(calleeName == "compiler" || calleeName == "_compiler_version")
calleeName == "compiler" || calleeName == "_compiler_version"
{
foundFeatureCheck = true
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftIfConfig/ConfiguredRegions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension SyntaxProtocol {
}

/// Helper class that walks a syntax tree looking for configured regions.
fileprivate class ConfiguredRegionVisitor<Configuration: BuildConfiguration>: SyntaxVisitor {
private class ConfiguredRegionVisitor<Configuration: BuildConfiguration>: SyntaxVisitor {
let configuration: Configuration

/// The regions we've found so far.
Expand Down
Loading
Loading