Skip to content

Commit d887490

Browse files
authored
Merge pull request #2231 from ahoppen/exhaustive-swift-format
Apply exhaustive swift-format configuration from swift-syntax
2 parents 16c30a6 + 6074529 commit d887490

File tree

99 files changed

+344
-249
lines changed

Some content is hidden

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

99 files changed

+344
-249
lines changed

.swift-format

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,76 @@
11
{
2-
"version": 1,
3-
"lineLength": 120,
2+
"fileScopedDeclarationPrivacy": {
3+
"accessLevel": "private"
4+
},
5+
"indentConditionalCompilationBlocks": false,
6+
"indentSwitchCaseLabels": false,
47
"indentation": {
58
"spaces": 2
69
},
10+
"lineBreakAroundMultilineExpressionChainComponents": false,
11+
"lineBreakBeforeControlFlowKeywords": false,
712
"lineBreakBeforeEachArgument": true,
8-
"indentConditionalCompilationBlocks": false,
13+
"lineBreakBeforeEachGenericRequirement": false,
14+
"lineBreakBetweenDeclarationAttributes": false,
15+
"lineLength": 120,
16+
"maximumBlankLines": 1,
17+
"multiElementCollectionTrailingCommas": true,
18+
"noAssignmentInExpressions": {
19+
"allowedFunctions": [
20+
"XCTAssertNoThrow"
21+
]
22+
},
923
"prioritizeKeepingFunctionOutputTogether": true,
24+
"reflowMultilineStringLiterals": {
25+
"never": {
26+
27+
}
28+
},
29+
"respectsExistingLineBreaks": true,
1030
"rules": {
31+
"AllPublicDeclarationsHaveDocumentation": false,
32+
"AlwaysUseLiteralForEmptyCollectionInit": false,
1133
"AlwaysUseLowerCamelCase": false,
1234
"AmbiguousTrailingClosureOverload": false,
35+
"BeginDocumentationCommentWithOneLineSummary": false,
36+
"DoNotUseSemicolons": false,
37+
"DontRepeatTypeInStaticProperties": false,
38+
"FileScopedDeclarationPrivacy": true,
39+
"FullyIndirectEnum": true,
40+
"GroupNumericLiterals": true,
41+
"IdentifiersMustBeASCII": true,
42+
"NeverForceUnwrap": false,
43+
"NeverUseForceTry": false,
44+
"NeverUseImplicitlyUnwrappedOptionals": false,
45+
"NoAccessLevelOnExtensionDeclaration": false,
46+
"NoAssignmentInExpressions": true,
1347
"NoBlockComments": false,
48+
"NoCasesWithOnlyFallthrough": true,
49+
"NoEmptyTrailingClosureParentheses": true,
50+
"NoLabelsInCasePatterns": true,
51+
"NoLeadingUnderscores": false,
52+
"NoParensAroundConditions": true,
53+
"NoPlaygroundLiterals": true,
54+
"NoVoidReturnOnFunctionSignature": true,
55+
"OmitExplicitReturns": false,
56+
"OneCasePerLine": true,
57+
"OneVariableDeclarationPerLine": true,
58+
"OnlyOneTrailingClosureArgument": true,
1459
"OrderedImports": true,
60+
"ReplaceForEachWithForLoop": true,
61+
"ReturnVoidInsteadOfEmptyTuple": true,
62+
"TypeNamesShouldBeCapitalized": true,
63+
"UseEarlyExits": false,
64+
"UseExplicitNilCheckInConditions": true,
1565
"UseLetInEveryBoundCaseVariable": false,
66+
"UseShorthandTypeNames": true,
67+
"UseSingleLinePropertyGetter": true,
1668
"UseSynthesizedInitializer": false,
17-
"ReturnVoidInsteadOfEmptyTuple": true,
18-
"NoVoidReturnOnFunctionSignature": true,
19-
}
69+
"UseTripleSlashForDocumentationComments": true,
70+
"UseWhereClausesInForLoops": false,
71+
"ValidateDocumentationComments": false
72+
},
73+
"spacesAroundRangeFormationOperators": false,
74+
"spacesBeforeEndOfLineComments": 2,
75+
"version": 1,
2076
}

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/JSONSchema.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ struct JSONSchemaBuilder {
101101
case .integer: schema.type = "integer"
102102
case .number: schema.type = "number"
103103
case .string: schema.type = "string"
104-
case .array(value: let value):
104+
case .array(let value):
105105
schema.type = "array"
106106
schema.items = try buildJSONSchema(from: value)
107-
case .dictionary(value: let value):
107+
case .dictionary(let value):
108108
schema.type = "object"
109109
schema.additionalProperties = try buildJSONSchema(from: value)
110110
case .struct(let structInfo):

Sources/BuildServerIntegration/BuildServerManager.swift

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package import ToolchainRegistry
2424

2525
import struct TSCBasic.RelativePath
2626

27-
fileprivate typealias RequestCache<Request: RequestType & Hashable> = Cache<Request, Request.Response>
27+
private typealias RequestCache<Request: RequestType & Hashable> = Cache<Request, Request.Response>
2828

2929
/// An output path returned from the build server in the `SourceItem.data.outputPath` field.
3030
package enum OutputPath: Hashable, Comparable, CustomLogStringConvertible {
@@ -462,36 +462,38 @@ package actor BuildServerManager: QueueBasedMessageHandler {
462462
// The debounce duration of 500ms was chosen arbitrarily without any measurements.
463463
self.filesDependenciesUpdatedDebouncer = Debouncer(
464464
debounceDuration: .milliseconds(500),
465-
combineResults: { $0.union($1) }
466-
) {
467-
[weak self] (filesWithUpdatedDependencies) in
468-
guard let self, let delegate = await self.delegate else {
469-
logger.fault("Not calling filesDependenciesUpdated because no delegate exists in SwiftPMBuildServer")
470-
return
471-
}
472-
let changedWatchedFiles = await self.watchedFilesReferencing(mainFiles: filesWithUpdatedDependencies)
473-
if !changedWatchedFiles.isEmpty {
474-
await delegate.filesDependenciesUpdated(changedWatchedFiles)
465+
combineResults: { $0.union($1) },
466+
makeCall: {
467+
[weak self] (filesWithUpdatedDependencies) in
468+
guard let self, let delegate = await self.delegate else {
469+
logger.fault("Not calling filesDependenciesUpdated because no delegate exists in SwiftPMBuildServer")
470+
return
471+
}
472+
let changedWatchedFiles = await self.watchedFilesReferencing(mainFiles: filesWithUpdatedDependencies)
473+
if !changedWatchedFiles.isEmpty {
474+
await delegate.filesDependenciesUpdated(changedWatchedFiles)
475+
}
475476
}
476-
}
477+
)
477478

478479
// We don't need a large debounce duration here. It just needs to be big enough to accumulate
479480
// `resultReceivedAfterTimeout` calls for the same document (see comment on `filesBuildSettingsChangedDebouncer`).
480481
// Since they should all come in at the same time, a couple of milliseconds should be sufficient here, an 20ms be
481482
// plenty while still not causing a noticeable delay to the user.
482483
self.filesBuildSettingsChangedDebouncer = Debouncer(
483484
debounceDuration: .milliseconds(20),
484-
combineResults: { $0.union($1) }
485-
) {
486-
[weak self] (filesWithChangedBuildSettings) in
487-
guard let self, let delegate = await self.delegate else {
488-
logger.fault("Not calling fileBuildSettingsChanged because no delegate exists in SwiftPMBuildServer")
489-
return
490-
}
491-
if !filesWithChangedBuildSettings.isEmpty {
492-
await delegate.fileBuildSettingsChanged(filesWithChangedBuildSettings)
485+
combineResults: { $0.union($1) },
486+
makeCall: {
487+
[weak self] (filesWithChangedBuildSettings) in
488+
guard let self, let delegate = await self.delegate else {
489+
logger.fault("Not calling fileBuildSettingsChanged because no delegate exists in SwiftPMBuildServer")
490+
return
491+
}
492+
if !filesWithChangedBuildSettings.isEmpty {
493+
await delegate.fileBuildSettingsChanged(filesWithChangedBuildSettings)
494+
}
493495
}
494-
}
496+
)
495497

496498
// TODO: Forward file watch patterns from this initialize request to the client
497499
// (https://github.com/swiftlang/sourcekit-lsp/issues/1671)
@@ -1629,7 +1631,7 @@ fileprivate extension TextDocumentSourceKitOptionsResponse {
16291631
}
16301632
}
16311633

1632-
fileprivate let supplementalClangIndexingArgs: [String] = [
1634+
private let supplementalClangIndexingArgs: [String] = [
16331635
// Retain extra information for indexing
16341636
"-fretain-comments-from-system-headers",
16351637
// Pick up macro definitions during indexing

Sources/BuildServerIntegration/CompilationDatabase.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ package struct JSONCompilationDatabase: Equatable, Codable {
140140

141141
package func encode(to encoder: Encoder) throws {
142142
var container = encoder.unkeyedContainer()
143-
try commands.forEach { try container.encode($0) }
143+
for command in commands {
144+
try container.encode(command)
145+
}
144146
}
145147

146148
package subscript(_ uri: DocumentURI) -> [CompilationDatabaseCompileCommand] {

Sources/BuildServerIntegration/CompilerCommandLineOption.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ package struct CompilerCommandLineOption {
151151
}
152152
}
153153

154-
extension Array<CompilerCommandLineOption> {
154+
extension [CompilerCommandLineOption] {
155155
func firstMatch(for argument: String) -> CompilerCommandLineOption.Match? {
156156
for optionToRemove in self {
157157
if let match = optionToRemove.matches(argument: argument) {

Sources/BuildServerIntegration/SplitShellCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// MARK: - Unix
1414

15-
fileprivate struct UnixCommandParser {
15+
private struct UnixCommandParser {
1616
var content: Substring
1717
var i: Substring.UTF8View.Index
1818
var result: [String] = []
@@ -162,7 +162,7 @@ fileprivate extension Character {
162162
}
163163
}
164164

165-
fileprivate struct WindowsCommandParser {
165+
private struct WindowsCommandParser {
166166
/// The content of the entire command that shall be parsed.
167167
private let content: String
168168

Sources/BuildServerIntegration/SwiftPMBuildServer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import struct TSCBasic.AbsolutePath
3636
import class TSCBasic.Process
3737
package import class ToolchainRegistry.Toolchain
3838

39-
fileprivate typealias AbsolutePath = Basics.AbsolutePath
39+
private typealias AbsolutePath = Basics.AbsolutePath
4040

4141
/// A build target in SwiftPM
4242
package typealias SwiftBuildTarget = SourceKitLSPAPI.BuildTarget
@@ -78,7 +78,7 @@ fileprivate extension TSCBasic.AbsolutePath {
7878
}
7979
}
8080

81-
fileprivate let preparationTaskID: AtomicUInt32 = AtomicUInt32(initialValue: 0)
81+
private let preparationTaskID: AtomicUInt32 = AtomicUInt32(initialValue: 0)
8282

8383
/// Swift Package Manager build server and workspace support.
8484
///
@@ -779,7 +779,7 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
779779
switch exitStatus {
780780
case .terminated(code: 0):
781781
break
782-
case .terminated(code: let code):
782+
case .terminated(let code):
783783
// This most likely happens if there are compilation errors in the source file. This is nothing to worry about.
784784
let stdout = (try? String(bytes: result.output.get(), encoding: .utf8)) ?? "<no stderr>"
785785
let stderr = (try? String(bytes: result.stderrOutput.get(), encoding: .utf8)) ?? "<no stderr>"
@@ -792,14 +792,14 @@ package actor SwiftPMBuildServer: BuiltInBuildServer {
792792
\(stdout)
793793
"""
794794
)
795-
case .signalled(signal: let signal):
795+
case .signalled(let signal):
796796
if !Task.isCancelled {
797797
// The indexing job finished with a signal. Could be because the compiler crashed.
798798
// Ignore signal exit codes if this task has been cancelled because the compiler exits with SIGINT if it gets
799799
// interrupted.
800800
logger.error("Preparation of target \(target.forLogging) signaled \(signal)")
801801
}
802-
case .abnormal(exception: let exception):
802+
case .abnormal(let exception):
803803
if !Task.isCancelled {
804804
logger.error("Preparation of target \(target.forLogging) exited abnormally \(exception)")
805805
}

Sources/BuildServerProtocol/Messages.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public import LanguageServerProtocol
1414

15-
fileprivate let requestTypes: [_RequestType.Type] = [
15+
private let requestTypes: [_RequestType.Type] = [
1616
BuildShutdownRequest.self,
1717
BuildTargetPrepareRequest.self,
1818
BuildTargetSourcesRequest.self,
@@ -24,7 +24,7 @@ fileprivate let requestTypes: [_RequestType.Type] = [
2424
WorkspaceWaitForBuildSystemUpdatesRequest.self,
2525
]
2626

27-
fileprivate let notificationTypes: [NotificationType.Type] = [
27+
private let notificationTypes: [NotificationType.Type] = [
2828
CancelRequestNotification.self,
2929
FileOptionsChangedNotification.self,
3030
OnBuildExitNotification.self,

Sources/BuildServerProtocol/Messages/TaskStartNotification.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public struct TaskStartNotification: NotificationType {
4646
/// Message describing the task.
4747
public var message: String?
4848

49-
/** Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified. */
49+
/// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
5050
public var dataKind: TaskStartDataKind?
5151

5252
/// Optional metadata about the task.

Sources/CompletionScoring/Semantics/Components/PopularityTable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ package struct PopularityTable {
138138
}
139139
}
140140

141-
extension Dictionary<String, Popularity> {
141+
extension [String: Popularity] {
142142
fileprivate mutating func record(scoreComponent: Double, for key: String) {
143143
let leastPopular = Popularity(scoreComponent: -Double.infinity)
144144
if self[key, default: leastPopular].scoreComponent < scoreComponent {

0 commit comments

Comments
 (0)