Skip to content

Commit d46815a

Browse files
committed
Fix all linter warnings
- Replace for-loop with where clause in ComplexProtoTests.swift - Add blank lines after first sentences in documentation comments - Add missing period in parseExtendDeclaration documentation - Maintain 100% test success rate (1086/1086 tests) - Preserve excellent code coverage (94.73% lines, 93.00% functions)
1 parent b82d49b commit d46815a

35 files changed

+5286
-4495
lines changed

Sources/SwiftProtoParser/DescriptorBuilder/DescriptorBuilder.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,57 @@ import SwiftProtobuf
33

44
/// Main descriptor builder that converts ProtoAST to swift-protobuf FileDescriptorProto.
55
public struct DescriptorBuilder {
6-
6+
77
/// Convert ProtoAST to FileDescriptorProto.
8-
public static func buildFileDescriptor(from ast: ProtoAST, fileName: String) throws -> Google_Protobuf_FileDescriptorProto {
8+
public static func buildFileDescriptor(from ast: ProtoAST, fileName: String) throws
9+
-> Google_Protobuf_FileDescriptorProto
10+
{
911
var fileProto = Google_Protobuf_FileDescriptorProto()
10-
12+
1113
// Set file name
1214
fileProto.name = fileName
13-
15+
1416
// Set syntax
1517
fileProto.syntax = ast.syntax.rawValue
16-
18+
1719
// Set package
1820
if let package = ast.package {
1921
fileProto.package = package
2022
}
21-
23+
2224
// Set imports
2325
fileProto.dependency.append(contentsOf: ast.imports)
24-
26+
2527
// Convert messages
2628
for messageNode in ast.messages {
2729
let messageProto = try MessageDescriptorBuilder.build(from: messageNode, packageName: ast.package)
2830
fileProto.messageType.append(messageProto)
2931
}
30-
32+
3133
// Convert enums
3234
for enumNode in ast.enums {
3335
let enumProto = try EnumDescriptorBuilder.build(from: enumNode)
3436
fileProto.enumType.append(enumProto)
3537
}
36-
38+
3739
// Convert services
3840
for serviceNode in ast.services {
3941
let serviceProto = try ServiceDescriptorBuilder.build(from: serviceNode, packageName: ast.package)
4042
fileProto.service.append(serviceProto)
4143
}
42-
44+
4345
// Convert file options
4446
if !ast.options.isEmpty {
4547
fileProto.options = try buildFileOptions(from: ast.options)
4648
}
47-
49+
4850
return fileProto
4951
}
50-
52+
5153
/// Build FileOptions from AST options.
5254
private static func buildFileOptions(from options: [OptionNode]) throws -> Google_Protobuf_FileOptions {
5355
var fileOptions = Google_Protobuf_FileOptions()
54-
56+
5557
for option in options {
5658
switch option.name {
5759
case "java_package":
@@ -147,7 +149,7 @@ public struct DescriptorBuilder {
147149
namePart.namePart = option.name
148150
namePart.isExtension = option.isCustom
149151
uninterpretedOption.name = [namePart]
150-
152+
151153
// Set value based on option value type
152154
switch option.value {
153155
case .string(let value):
@@ -159,11 +161,11 @@ public struct DescriptorBuilder {
159161
case .identifier(let value):
160162
uninterpretedOption.identifierValue = value
161163
}
162-
164+
163165
fileOptions.uninterpretedOption.append(uninterpretedOption)
164166
}
165167
}
166-
168+
167169
return fileOptions
168170
}
169171
}

Sources/SwiftProtoParser/DescriptorBuilder/DescriptorError.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import Foundation
44
public enum DescriptorError: LocalizedError, Equatable {
55
/// Unable to convert AST node to descriptor.
66
case conversionFailed(reason: String)
7-
7+
88
/// Missing required field in AST node.
99
case missingRequiredField(field: String, in: String)
10-
10+
1111
/// Invalid field type for descriptor conversion.
1212
case invalidFieldType(type: String, context: String)
13-
13+
1414
/// Duplicate element found during conversion.
1515
case duplicateElement(name: String, type: String)
16-
16+
1717
/// Unsupported feature for descriptor conversion.
1818
case unsupportedFeature(feature: String, context: String)
19-
19+
2020
/// Internal error during descriptor building.
2121
case internalError(message: String)
22-
22+
2323
public var errorDescription: String? {
2424
switch self {
2525
case .conversionFailed(let reason):
@@ -45,27 +45,27 @@ extension DescriptorError {
4545
public static func conversionFailed(_ reason: String) -> DescriptorError {
4646
return .conversionFailed(reason: reason)
4747
}
48-
48+
4949
/// Create a missing required field error.
5050
public static func missingField(_ field: String, in context: String) -> DescriptorError {
5151
return .missingRequiredField(field: field, in: context)
5252
}
53-
53+
5454
/// Create an invalid field type error.
5555
public static func invalidType(_ type: String, in context: String) -> DescriptorError {
5656
return .invalidFieldType(type: type, context: context)
5757
}
58-
58+
5959
/// Create a duplicate element error.
6060
public static func duplicate(_ name: String, type: String) -> DescriptorError {
6161
return .duplicateElement(name: name, type: type)
6262
}
63-
63+
6464
/// Create an unsupported feature error.
6565
public static func unsupported(_ feature: String, in context: String) -> DescriptorError {
6666
return .unsupportedFeature(feature: feature, context: context)
6767
}
68-
68+
6969
/// Create an internal error.
7070
public static func internalError(_ message: String) -> DescriptorError {
7171
return .internalError(message: message)

Sources/SwiftProtoParser/DescriptorBuilder/EnumDescriptorBuilder.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@ import SwiftProtobuf
33

44
/// Builds SwiftProtobuf EnumDescriptorProto from AST EnumNode.
55
struct EnumDescriptorBuilder {
6-
6+
77
/// Convert EnumNode to EnumDescriptorProto.
88
static func build(from enumNode: EnumNode) throws -> Google_Protobuf_EnumDescriptorProto {
99
var enumProto = Google_Protobuf_EnumDescriptorProto()
10-
10+
1111
// Set enum name
1212
enumProto.name = enumNode.name
13-
13+
1414
// Convert enum values
1515
for valueNode in enumNode.values {
1616
let valueProto = try buildEnumValue(from: valueNode)
1717
enumProto.value.append(valueProto)
1818
}
19-
19+
2020
// Validate that enum has a zero value (required in proto3)
2121
if !enumNode.hasZeroValue {
2222
throw DescriptorError.conversionFailed("Enum '\(enumNode.name)' must have a zero value in proto3")
2323
}
24-
24+
2525
// Convert enum options
2626
if !enumNode.options.isEmpty {
2727
enumProto.options = try buildEnumOptions(from: enumNode.options)
2828
}
29-
29+
3030
return enumProto
3131
}
32-
32+
3333
/// Build EnumValueDescriptorProto from EnumValueNode.
3434
private static func buildEnumValue(from valueNode: EnumValueNode) throws -> Google_Protobuf_EnumValueDescriptorProto {
3535
var valueProto = Google_Protobuf_EnumValueDescriptorProto()
36-
36+
3737
valueProto.name = valueNode.name
3838
valueProto.number = valueNode.number
39-
39+
4040
// Convert value options
4141
if !valueNode.options.isEmpty {
4242
valueProto.options = try buildEnumValueOptions(from: valueNode.options)
4343
}
44-
44+
4545
return valueProto
4646
}
47-
47+
4848
/// Build EnumOptions from AST options.
4949
private static func buildEnumOptions(from options: [OptionNode]) throws -> Google_Protobuf_EnumOptions {
5050
var enumOptions = Google_Protobuf_EnumOptions()
51-
51+
5252
for option in options {
5353
switch option.name {
5454
case "allow_alias":
@@ -65,14 +65,14 @@ struct EnumDescriptorBuilder {
6565
break
6666
}
6767
}
68-
68+
6969
return enumOptions
7070
}
71-
71+
7272
/// Build EnumValueOptions from AST options.
7373
private static func buildEnumValueOptions(from options: [OptionNode]) throws -> Google_Protobuf_EnumValueOptions {
7474
var valueOptions = Google_Protobuf_EnumValueOptions()
75-
75+
7676
for option in options {
7777
switch option.name {
7878
case "deprecated":
@@ -85,7 +85,7 @@ struct EnumDescriptorBuilder {
8585
break
8686
}
8787
}
88-
88+
8989
return valueOptions
9090
}
9191
}

Sources/SwiftProtoParser/DescriptorBuilder/FieldDescriptorBuilder.swift

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import SwiftProtobuf
33

44
/// Builds SwiftProtobuf FieldDescriptorProto from AST FieldNode.
55
struct FieldDescriptorBuilder {
6-
6+
77
/// Convert FieldNode to FieldDescriptorProto.
8-
static func build(from fieldNode: FieldNode, index: Int32, packageName: String? = nil) throws -> Google_Protobuf_FieldDescriptorProto {
8+
static func build(from fieldNode: FieldNode, index: Int32, packageName: String? = nil) throws
9+
-> Google_Protobuf_FieldDescriptorProto
10+
{
911
var fieldProto = Google_Protobuf_FieldDescriptorProto()
10-
12+
1113
// Set basic field properties
1214
fieldProto.name = fieldNode.name
1315
fieldProto.number = fieldNode.number
14-
16+
1517
// Convert field label
1618
switch fieldNode.label {
1719
case .optional:
@@ -21,20 +23,24 @@ struct FieldDescriptorBuilder {
2123
case .repeated:
2224
fieldProto.label = .repeated
2325
}
24-
26+
2527
// Convert field type
2628
try setFieldType(fieldProto: &fieldProto, fieldType: fieldNode.type, packageName: packageName)
27-
29+
2830
// Convert field options
2931
if !fieldNode.options.isEmpty {
3032
fieldProto.options = try buildFieldOptions(from: fieldNode.options)
3133
}
32-
34+
3335
return fieldProto
3436
}
35-
37+
3638
/// Set field type in FieldDescriptorProto with proper type enum mapping.
37-
private static func setFieldType(fieldProto: inout Google_Protobuf_FieldDescriptorProto, fieldType: FieldType, packageName: String?) throws {
39+
private static func setFieldType(
40+
fieldProto: inout Google_Protobuf_FieldDescriptorProto,
41+
fieldType: FieldType,
42+
packageName: String?
43+
) throws {
3844
switch fieldType {
3945
// Scalar types
4046
case .double:
@@ -67,22 +73,22 @@ struct FieldDescriptorBuilder {
6773
fieldProto.type = .string
6874
case .bytes:
6975
fieldProto.type = .bytes
70-
76+
7177
// Complex types
7278
case .message(let typeName):
7379
fieldProto.type = .message
7480
fieldProto.typeName = buildFullyQualifiedTypeName(typeName, packageName: packageName)
75-
81+
7682
case .enumType(let typeName):
7783
fieldProto.type = .enum
7884
fieldProto.typeName = buildFullyQualifiedTypeName(typeName, packageName: packageName)
79-
85+
8086
case .qualifiedType(let qualifiedName):
8187
// For qualified types like google.protobuf.Timestamp, assume it's a message type
8288
fieldProto.type = .message
8389
// Qualified names are already fully qualified, just add leading dot if missing
8490
fieldProto.typeName = qualifiedName.hasPrefix(".") ? qualifiedName : ".\(qualifiedName)"
85-
91+
8692
case .map(_, _):
8793
// Maps are represented as repeated message with special structure
8894
fieldProto.type = .message
@@ -91,26 +97,27 @@ struct FieldDescriptorBuilder {
9197
fieldProto.label = .repeated
9298
}
9399
}
94-
100+
95101
/// Build fully qualified type name with package prefix.
96102
private static func buildFullyQualifiedTypeName(_ typeName: String, packageName: String?) -> String {
97103
// If already starts with dot, it's already fully qualified
98104
if typeName.hasPrefix(".") {
99105
return typeName
100106
}
101-
107+
102108
// Build fully qualified name
103109
if let package = packageName, !package.isEmpty {
104110
return ".\(package).\(typeName)"
105-
} else {
111+
}
112+
else {
106113
return ".\(typeName)"
107114
}
108115
}
109-
116+
110117
/// Build FieldOptions from AST options.
111118
private static func buildFieldOptions(from options: [OptionNode]) throws -> Google_Protobuf_FieldOptions {
112119
var fieldOptions = Google_Protobuf_FieldOptions()
113-
120+
114121
for option in options {
115122
switch option.name {
116123
case "deprecated":
@@ -162,7 +169,7 @@ struct FieldDescriptorBuilder {
162169
namePart.namePart = option.name
163170
namePart.isExtension = option.isCustom
164171
uninterpretedOption.name = [namePart]
165-
172+
166173
// Set value based on option value type
167174
switch option.value {
168175
case .string(let value):
@@ -174,11 +181,11 @@ struct FieldDescriptorBuilder {
174181
case .identifier(let value):
175182
uninterpretedOption.identifierValue = value
176183
}
177-
184+
178185
fieldOptions.uninterpretedOption.append(uninterpretedOption)
179186
}
180187
}
181-
188+
182189
return fieldOptions
183190
}
184191
}

0 commit comments

Comments
 (0)