Skip to content

Commit fe7541a

Browse files
committed
Update linter rules, add editorconfig
1 parent 02d7b50 commit fe7541a

Some content is hidden

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

41 files changed

+286
-693
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
xcode_trim_whitespace_on_empty_lines = true

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v4
2020
- name: Lint Swift files
21-
run: swift format lint Sources/ Tests/ Example/ --recursive
21+
run: swift format lint Sources/ Tests/ Example/ --recursive --strict
2222
- name: Build sourcekit-bazel-bsp (debug)
2323
run: swift build
2424
- name: Test sourcekit-bazel-bsp

.swift-format

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
{
2-
"fileScopedDeclarationPrivacy" : {
3-
"accessLevel" : "private"
4-
},
5-
"indentConditionalCompilationBlocks" : true,
6-
"indentSwitchCaseLabels" : false,
72
"indentation" : {
83
"spaces" : 4
94
},
10-
"lineBreakAroundMultilineExpressionChainComponents" : false,
11-
"lineBreakBeforeControlFlowKeywords" : false,
12-
"lineBreakBeforeEachArgument" : false,
13-
"lineBreakBeforeEachGenericRequirement" : false,
14-
"lineBreakBetweenDeclarationAttributes" : false,
15-
"lineLength" : 100,
16-
"maximumBlankLines" : 1,
17-
"multiElementCollectionTrailingCommas" : true,
18-
"noAssignmentInExpressions" : {
19-
"allowedFunctions" : [
20-
"XCTAssertNoThrow"
21-
]
22-
},
23-
"prioritizeKeepingFunctionOutputTogether" : false,
24-
"reflowMultilineStringLiterals" : {
25-
"never" : {
26-
27-
}
28-
},
5+
"lineLength": 120,
6+
"prioritizeKeepingFunctionOutputTogether" : true,
297
"respectsExistingLineBreaks" : true,
8+
"lineBreakBeforeEachArgument": true,
9+
"lineBreakBeforeEachGenericRequirement": true,
10+
"lineBreakBetweenDeclarationAttributes": true,
11+
"indentConditionalCompilationBlocks": false,
3012
"rules" : {
3113
"AllPublicDeclarationsHaveDocumentation" : false,
3214
"AlwaysUseLiteralForEmptyCollectionInit" : false,
@@ -40,9 +22,9 @@
4022
"FullyIndirectEnum" : true,
4123
"GroupNumericLiterals" : true,
4224
"IdentifiersMustBeASCII" : true,
43-
"NeverForceUnwrap" : false,
44-
"NeverUseForceTry" : false,
45-
"NeverUseImplicitlyUnwrappedOptionals" : false,
25+
"NeverForceUnwrap" : true,
26+
"NeverUseForceTry" : true,
27+
"NeverUseImplicitlyUnwrappedOptionals" : true,
4628
"NoAccessLevelOnExtensionDeclaration" : true,
4729
"NoAssignmentInExpressions" : true,
4830
"NoBlockComments" : true,
@@ -62,7 +44,7 @@
6244
"ReplaceForEachWithForLoop" : true,
6345
"ReturnVoidInsteadOfEmptyTuple" : true,
6446
"TypeNamesShouldBeCapitalized" : true,
65-
"UseEarlyExits" : false,
47+
"UseEarlyExits" : true,
6648
"UseExplicitNilCheckInConditions" : true,
6749
"UseLetInEveryBoundCaseVariable" : true,
6850
"UseShorthandTypeNames" : true,
@@ -72,8 +54,4 @@
7254
"UseWhereClausesInForLoops" : false,
7355
"ValidateDocumentationComments" : false
7456
},
75-
"spacesAroundRangeFormationOperators" : false,
76-
"spacesBeforeEndOfLineComments" : 2,
77-
"tabWidth" : 8,
78-
"version" : 1
79-
}
57+
}

Example/HelloWorld/HelloWorldLib/Sources/AddTodoView.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ import TodoModels
2222

2323
struct AddTodoView: View {
2424

25-
@ObservedObject var todoManager: TodoListManager
26-
@Binding var isPresented: Bool
27-
@State private var todoTitle = ""
28-
@FocusState private var isTextFieldFocused: Bool
25+
@ObservedObject
26+
var todoManager: TodoListManager
27+
@Binding
28+
var isPresented: Bool
29+
@State
30+
private var todoTitle = ""
31+
@FocusState
32+
private var isTextFieldFocused: Bool
2933

3034
var body: some View {
3135
NavigationView {

Example/HelloWorld/HelloWorldLib/Sources/TodoListView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import SwiftUI
2121
import TodoModels
2222

2323
struct TodoListView: View {
24-
@StateObject private var todoManager = TodoListManager()
25-
@State private var showingAddTodo = false
24+
@StateObject
25+
private var todoManager = TodoListManager()
26+
@State
27+
private var showingAddTodo = false
2628

2729
var body: some View {
2830
NavigationView {

Example/HelloWorld/TodoModels/Sources/TodoListManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import Foundation
2121
import SwiftUI
2222

2323
public final class TodoListManager: ObservableObject {
24-
@Published public var todoItems: [TodoItem] = []
24+
@Published
25+
public var todoItems: [TodoItem] = []
2526

2627
private let userDefaults: UserDefaults
2728
private let todoItemsKey = "todo-items"

Sources/BazelProtobufBindings/BazelProtobufBindings.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,19 @@
2020
import Foundation
2121

2222
public struct BazelProtobufBindings {
23-
23+
2424
let actionGraph: Analysis_ActionGraphContainer
25-
26-
init(actionGraph: Analysis_ActionGraphContainer) {
27-
self.actionGraph = actionGraph
28-
}
2925

3026
public static func new(data: Data) throws -> Self {
3127
let actionGraph = try Analysis_ActionGraphContainer(serializedBytes: data)
3228
return BazelProtobufBindings(actionGraph: actionGraph)
3329
}
34-
30+
3531
public func findActionsBy(mnemonic: String) -> [Analysis_Action] {
3632
return actionGraph.actions.filter { $0.mnemonic == mnemonic }
3733
}
38-
34+
3935
public func getTargetBy(label: String) -> Analysis_Target? {
40-
return actionGraph.targets.first { $0.label == label }
36+
return actionGraph.targets.first { $0.label == label }
4137
}
4238
}

Sources/SourceKitBazelBSP/RequestHandlers/BuildTargets/BazelQueryParser.swift

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ enum BazelQueryParser {
3838

3939
var targets: [(BuildTarget, [URI])] = []
4040
for child in (xml.children ?? []) {
41-
if child.name != "rule" {
42-
continue
43-
}
44-
guard let childElement = child as? XMLElement else {
45-
continue
46-
}
41+
if child.name != "rule" { continue }
42+
guard let childElement = child as? XMLElement else { continue }
4743
let className = childElement.attribute(forName: "class")?.stringValue ?? ""
48-
guard supportedRuleTypes.contains(className) else {
49-
continue
50-
}
44+
guard supportedRuleTypes.contains(className) else { continue }
5145
if let data = try getTargetForLibrary(childElement, className, rootUri, toolchainPath) {
5246
targets.append(data)
5347
}
@@ -56,10 +50,11 @@ enum BazelQueryParser {
5650
}
5751

5852
static private func getTargetForLibrary(
59-
_ childElement: XMLElement, _ className: String, _ rootUri: String, _ toolchainPath: String
60-
)
61-
throws -> (BuildTarget, [URI])?
62-
{
53+
_ childElement: XMLElement,
54+
_ className: String,
55+
_ rootUri: String,
56+
_ toolchainPath: String
57+
) throws -> (BuildTarget, [URI])? {
6358
let bazelTarget = childElement.attribute(forName: "name")?.stringValue ?? ""
6459
guard bazelTarget.starts(with: "//") else {
6560
// FIXME
@@ -73,28 +68,16 @@ enum BazelQueryParser {
7368
let uri: URI = try URI(string: uriRaw)
7469

7570
for child in (childElement.children ?? []) {
76-
if child.name != "list" {
77-
continue
78-
}
79-
guard let childElement = child as? XMLElement else {
80-
continue
81-
}
71+
if child.name != "list" { continue }
72+
guard let childElement = child as? XMLElement else { continue }
8273
let name = childElement.attribute(forName: "name")?.stringValue ?? ""
83-
guard name == "srcs" else {
84-
continue
85-
}
74+
guard name == "srcs" else { continue }
8675
for srcsEntry in (childElement.children ?? []) {
87-
if srcsEntry.name != "label" {
88-
continue
89-
}
90-
guard let srcsEntryElement = srcsEntry as? XMLElement else {
91-
continue
92-
}
76+
if srcsEntry.name != "label" { continue }
77+
guard let srcsEntryElement = srcsEntry as? XMLElement else { continue }
9378
let srcValue = srcsEntryElement.attribute(forName: "value")?.stringValue ?? ""
9479
// FIXME
95-
if !srcValue.starts(with: "//") {
96-
continue
97-
}
80+
if !srcValue.starts(with: "//") { continue }
9881
let src = srcValue.replacingOccurrences(of: ":", with: "/")
9982
let srcUri = try URI(string: "file://" + rootUri + "/" + src.dropFirst(2))
10083
targetSrcs.append(srcUri)
@@ -103,41 +86,24 @@ enum BazelQueryParser {
10386

10487
var targetDeps: [BuildTargetIdentifier] = []
10588
for child in (childElement.children ?? []) {
106-
if child.name != "list" {
107-
continue
108-
}
109-
guard let childElement = child as? XMLElement else {
110-
continue
111-
}
89+
if child.name != "list" { continue }
90+
guard let childElement = child as? XMLElement else { continue }
11291
let name = childElement.attribute(forName: "name")?.stringValue ?? ""
113-
guard name == "deps" else {
114-
continue
115-
}
92+
guard name == "deps" else { continue }
11693
for depsEntry in (childElement.children ?? []) {
117-
if depsEntry.name != "label" {
118-
continue
119-
}
120-
guard let depsEntryElement = depsEntry as? XMLElement else {
121-
continue
122-
}
94+
if depsEntry.name != "label" { continue }
95+
guard let depsEntryElement = depsEntry as? XMLElement else { continue }
12396
let depValue = depsEntryElement.attribute(forName: "value")?.stringValue ?? ""
12497
// FIXME
125-
if !depValue.starts(with: "//") {
126-
continue
127-
}
98+
if !depValue.starts(with: "//") { continue }
12899
let depFullPath = rootUri + "/" + depValue.dropFirst(2)
129100
let depUri = bazelTargetToURI(depFullPath)
130101
targetDeps.append(BuildTargetIdentifier(uri: try URI(string: depUri)))
131102
}
132103
}
133104

134105
var tags: [BuildTargetTag] = [.library]
135-
var capabilities = BuildTargetCapabilities(
136-
canCompile: true,
137-
canTest: false,
138-
canRun: false,
139-
canDebug: false
140-
)
106+
var capabilities = BuildTargetCapabilities(canCompile: true, canTest: false, canRun: false, canDebug: false)
141107
// FIXME: Not the way to do this
142108
if bazelTarget.hasSuffix("TestsLib") {
143109
capabilities.canTest = true
@@ -153,9 +119,7 @@ enum BazelQueryParser {
153119
languageIds: isSwift ? [.swift] : [.objective_c],
154120
dependencies: targetDeps,
155121
dataKind: .sourceKit,
156-
data: SourceKitBuildTarget(
157-
toolchain: try URI(string: "file://" + toolchainPath)
158-
).encodeToLSPAny()
122+
data: SourceKitBuildTarget(toolchain: try URI(string: "file://" + toolchainPath)).encodeToLSPAny()
159123
), targetSrcs
160124
)
161125
}

Sources/SourceKitBazelBSP/RequestHandlers/BuildTargets/BazelTargetQuerier.swift

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ enum BazelTargetQuerierError: Error, LocalizedError {
2828

2929
var errorDescription: String? {
3030
switch self {
31-
case .noKinds:
32-
return "A list of kinds is necessary to query targets"
33-
case .noTargets:
34-
return "A list of targets is necessary to query targets"
35-
case .invalidQueryOutput:
36-
return "Query output is not valid XML"
31+
case .noKinds: return "A list of kinds is necessary to query targets"
32+
case .noTargets: return "A list of targets is necessary to query targets"
33+
case .invalidQueryOutput: return "Query output is not valid XML"
3734
}
3835
}
3936
}
@@ -62,13 +59,7 @@ final class BazelTargetQuerier {
6259
self.commandRunner = commandRunner
6360
}
6461

65-
func queryTargets(
66-
forConfig config: BaseServerConfig,
67-
rootUri: String,
68-
kinds: Set<String>
69-
) throws
70-
-> XMLElement
71-
{
62+
func queryTargets(forConfig config: BaseServerConfig, rootUri: String, kinds: Set<String>) throws -> XMLElement {
7263
guard !kinds.isEmpty else {
7364
throw BazelTargetQuerierError.noKinds
7465
}
@@ -90,11 +81,7 @@ final class BazelTargetQuerier {
9081

9182
// We run this one on the main output base since it's not related to the actual indexing bits
9283
let cmd = "query \"kind('\(kindsFilter)', \(depsQuery))\" --output xml"
93-
let output = try commandRunner.bazel(
94-
baseConfig: config,
95-
rootUri: rootUri,
96-
cmd: cmd
97-
)
84+
let output = try commandRunner.bazel(baseConfig: config, rootUri: rootUri, cmd: cmd)
9885

9986
logger.debug("Finished querying, building result XML")
10087

Sources/SourceKitBazelBSP/RequestHandlers/BuildTargets/BazelTargetStore.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ enum BazelTargetStoreError: Error, LocalizedError {
2626

2727
var errorDescription: String? {
2828
switch self {
29-
case .unknownBSPURI(let uri):
30-
return "Requested data about a URI, but couldn't find it in the store: \(uri)"
29+
case .unknownBSPURI(let uri): return "Requested data about a URI, but couldn't find it in the store: \(uri)"
3130
}
3231
}
3332
}
@@ -37,10 +36,7 @@ enum BazelTargetStoreError: Error, LocalizedError {
3736
final class BazelTargetStore {
3837

3938
// The list of rules we currently care about and can process
40-
static let supportedRuleTypes: Set<String> = [
41-
"swift_library",
42-
"objc_library",
43-
]
39+
static let supportedRuleTypes: Set<String> = ["swift_library", "objc_library"]
4440

4541
private let initializedConfig: InitializedServerConfig
4642
private let bazelTargetQuerier: BazelTargetQuerier
@@ -49,10 +45,7 @@ final class BazelTargetStore {
4945
private var bspURIsToSrcsMap: [URI: [URI]] = [:]
5046
private var srcToBspURIsMap: [URI: [URI]] = [:]
5147

52-
init(
53-
initializedConfig: InitializedServerConfig,
54-
bazelTargetQuerier: BazelTargetQuerier = BazelTargetQuerier()
55-
) {
48+
init(initializedConfig: InitializedServerConfig, bazelTargetQuerier: BazelTargetQuerier = BazelTargetQuerier()) {
5649
self.initializedConfig = initializedConfig
5750
self.bazelTargetQuerier = bazelTargetQuerier
5851
}

0 commit comments

Comments
 (0)