Skip to content

Commit 3aeeb31

Browse files
authored
Merge pull request #180 from PureSwift/feature/swift-lint
Add Swift Lint and Formatting
2 parents 4a57214 + c121bb7 commit 3aeeb31

File tree

483 files changed

+18826
-17340
lines changed

Some content is hidden

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

483 files changed

+18826
-17340
lines changed

.github/workflows/swiftlint.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Swift Lint
2+
on: [pull_request]
3+
jobs:
4+
swift-format-lint:
5+
name: swift-format lint
6+
runs-on: ubuntu-latest
7+
container: swift:6.0.3
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: Swift Version
12+
run: swift --version
13+
- name: Lint
14+
run: swift format lint -r ./ --configuration .swift-format
15+
16+
swiftlint:
17+
name: swiftlint
18+
runs-on: macos-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Install Swift
23+
uses: slashmo/[email protected]
24+
with:
25+
version: 6.0.3
26+
- name: Swift Version
27+
run: swift --version
28+
- name: Install SwiftLint
29+
run: brew install swiftlint
30+
- name: Lint
31+
run: swiftlint

.swift-format

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : false,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineLength" : 1000,
15+
"maximumBlankLines" : 1,
16+
"multiElementCollectionTrailingCommas" : false,
17+
"noAssignmentInExpressions" : {
18+
"allowedFunctions" : [
19+
"XCTAssertNoThrow"
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether" : false,
23+
"respectsExistingLineBreaks" : true,
24+
"rules" : {
25+
"AllPublicDeclarationsHaveDocumentation" : false,
26+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
27+
"AlwaysUseLowerCamelCase" : false,
28+
"AmbiguousTrailingClosureOverload" : true,
29+
"BeginDocumentationCommentWithOneLineSummary" : false,
30+
"DoNotUseSemicolons" : true,
31+
"DontRepeatTypeInStaticProperties" : true,
32+
"FileScopedDeclarationPrivacy" : true,
33+
"FullyIndirectEnum" : true,
34+
"GroupNumericLiterals" : true,
35+
"IdentifiersMustBeASCII" : true,
36+
"NeverForceUnwrap" : false,
37+
"NeverUseForceTry" : false,
38+
"NeverUseImplicitlyUnwrappedOptionals" : false,
39+
"NoAccessLevelOnExtensionDeclaration" : false,
40+
"NoAssignmentInExpressions" : true,
41+
"NoBlockComments" : false,
42+
"NoCasesWithOnlyFallthrough" : true,
43+
"NoEmptyTrailingClosureParentheses" : true,
44+
"NoLabelsInCasePatterns" : true,
45+
"NoLeadingUnderscores" : false,
46+
"NoParensAroundConditions" : true,
47+
"NoPlaygroundLiterals" : true,
48+
"NoVoidReturnOnFunctionSignature" : true,
49+
"OmitExplicitReturns" : false,
50+
"OneCasePerLine" : true,
51+
"OneVariableDeclarationPerLine" : true,
52+
"OnlyOneTrailingClosureArgument" : true,
53+
"OrderedImports" : false,
54+
"ReplaceForEachWithForLoop" : false,
55+
"ReturnVoidInsteadOfEmptyTuple" : false,
56+
"TypeNamesShouldBeCapitalized" : true,
57+
"UseEarlyExits" : false,
58+
"UseExplicitNilCheckInConditions" : true,
59+
"UseLetInEveryBoundCaseVariable" : false,
60+
"UseShorthandTypeNames" : true,
61+
"UseSingleLinePropertyGetter" : true,
62+
"UseSynthesizedInitializer" : false,
63+
"UseTripleSlashForDocumentationComments" : false,
64+
"UseWhereClausesInForLoops" : false,
65+
"ValidateDocumentationComments" : false
66+
},
67+
"spacesAroundRangeFormationOperators" : false,
68+
"tabWidth" : 8,
69+
"version" : 1
70+
}

.swiftlint.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
included:
2+
- Plugins
3+
- Source
4+
- Tests
5+
- Package.swift
6+
analyzer_rules:
7+
- unused_declaration
8+
- unused_import
9+
disabled_rules:
10+
- comma
11+
- void_return
12+
- cyclomatic_complexity
13+
- force_cast
14+
- large_tuple
15+
- comment_spacing
16+
- private_over_fileprivate
17+
- redundant_discardable_let
18+
- statement_position
19+
- file_length
20+
- function_body_length
21+
- identifier_name
22+
- line_length
23+
- number_separator
24+
- sorted_imports
25+
- trailing_whitespace
26+
- vertical_whitespace
27+
- vertical_whitespace_opening_braces
28+
- vertical_parameter_alignment_on_call
29+
- vertical_whitespace_closing_braces
30+
- type_body_length
31+
- anonymous_argument_in_multiline_closure
32+
- async_without_await
33+
- conditional_returns_on_newline
34+
- contrasted_opening_brace
35+
- convenience_type
36+
- discouraged_optional_collection
37+
- explicit_acl
38+
- explicit_enum_raw_value
39+
- explicit_top_level_acl
40+
- explicit_type_interface
41+
- file_types_order
42+
- force_unwrapping
43+
- function_default_parameter_at_end
44+
- indentation_width
45+
- missing_docs
46+
- multiline_arguments
47+
- multiline_arguments_brackets
48+
- multiline_function_chains
49+
- multiline_parameters_brackets
50+
- no_extension_access_modifier
51+
- no_grouping_extension
52+
- no_magic_numbers
53+
- one_declaration_per_file
54+
- prefer_key_path # Re-enable once we are on Swift 6.
55+
- prefer_nimble
56+
- prefixed_toplevel_constant
57+
- required_deinit
58+
- sorted_enum_cases
59+
- strict_fileprivate
60+
- switch_case_on_newline
61+
- todo
62+
- trailing_closure
63+
- type_contents_order
64+
- vertical_whitespace_between_cases
65+
- inclusive_language

Package.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var package = Package(
2020
.macOS(.v10_15),
2121
.iOS(.v13),
2222
.watchOS(.v6),
23-
.tvOS(.v13),
23+
.tvOS(.v13)
2424
],
2525
products: [
2626
.library(
@@ -74,7 +74,7 @@ var package = Package(
7474
.target(
7575
name: "BluetoothGATT",
7676
dependencies: [
77-
"Bluetooth",
77+
"Bluetooth"
7878
]
7979
),
8080
.target(
@@ -93,15 +93,15 @@ var package = Package(
9393
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
9494
),
9595
.target(
96-
name: "BluetoothGAP",
96+
name: "BluetoothGAP",
9797
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
9898
),
9999
.target(
100-
name: "BluetoothGATT",
100+
name: "BluetoothGATT",
101101
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
102102
),
103103
.target(
104-
name: "BluetoothHCI",
104+
name: "BluetoothHCI",
105105
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
106106
)
107107
]
@@ -127,7 +127,7 @@ if buildDocs {
127127
}
128128

129129
if generateCode {
130-
for (index, _) in package.targets.enumerated() {
130+
for index in package.targets.indices {
131131
package.targets[index].swiftSettings = [
132132
.define("SWIFTPM_ENABLE_PLUGINS")
133133
]
@@ -169,14 +169,14 @@ if enableMacros {
169169
.macro(
170170
name: "BluetoothMacros",
171171
dependencies: [
172-
.product(
173-
name: "SwiftSyntaxMacros",
174-
package: "swift-syntax"
175-
),
176-
.product(
177-
name: "SwiftCompilerPlugin",
178-
package: "swift-syntax"
179-
)
172+
.product(
173+
name: "SwiftSyntaxMacros",
174+
package: "swift-syntax"
175+
),
176+
.product(
177+
name: "SwiftCompilerPlugin",
178+
package: "swift-syntax"
179+
)
180180
]
181181
)
182182
]

Plugins/GenerateBluetoothDefinitions/BluetoothUUID.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import PackagePlugin
1010

1111
extension GenerateBluetoothDefinitionsPlugin {
12-
12+
1313
func bluetoothUUIDBuildCommands(
1414
type: String,
1515
fileName: String,
@@ -25,7 +25,8 @@ extension GenerateBluetoothDefinitionsPlugin {
2525
let outputURLs = [
2626
outputDirectory.appending(component: fileName + ".swift")
2727
]
28-
let arguments = ["uuid", type]
28+
let arguments =
29+
["uuid", type]
2930
+ outputURLs.map { $0.path() }
3031
let command = Command.buildCommand(
3132
displayName: "Generate Bluetooth \(type) UUID Definitions",

Plugins/GenerateBluetoothDefinitions/CompanyIdentifier.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import PackagePlugin
1010

1111
extension GenerateBluetoothDefinitionsPlugin {
12-
12+
1313
func companyIdentifiersBuildCommands(
1414
for context: PluginContext,
1515
target: SwiftSourceModuleTarget,
@@ -34,7 +34,7 @@ extension GenerateBluetoothDefinitionsPlugin {
3434
assert(arguments.count == 2)
3535
commands.append(command)
3636
}
37-
37+
3838
func companyIdentifierTestsBuildCommands(
3939
for context: PluginContext,
4040
target: SwiftSourceModuleTarget,

Plugins/GenerateBluetoothDefinitions/Plugin.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// Plugin.swift
3-
//
3+
//
44
//
55
// Created by Alsey Coleman Miller on 6/12/22.
66
//
@@ -18,7 +18,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
1818
}
1919
var commands = [Command]()
2020
commands.reserveCapacity(10)
21-
21+
2222
// Generate Bluetooth Company Identifier Definitions
2323
try companyIdentifiersBuildCommands(for: context, target: target, commands: &commands)
2424
// Generate Bluetooth Company Identifier Unit Tests
@@ -33,7 +33,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
3333
("Characteristic", "CharacteristicUUID"),
3434
("Descriptor", "DescriptorUUID"),
3535
("Member", "MemberUUID"),
36-
("Declaration", "DeclarationUUID"),
36+
("Declaration", "DeclarationUUID")
3737
]
3838
for (type, fileName) in uuidFiles {
3939
try bluetoothUUIDBuildCommands(
@@ -44,7 +44,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
4444
commands: &commands
4545
)
4646
}
47-
47+
4848
return commands
4949
}
5050
}

Plugins/GenerateBluetoothDefinitions/UnitIdentifier.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99
import PackagePlugin
1010

1111
extension GenerateBluetoothDefinitionsPlugin {
12-
12+
1313
func unitIdentifiersBuildCommands(
1414
for context: PluginContext,
1515
target: SwiftSourceModuleTarget,
@@ -31,7 +31,7 @@ extension GenerateBluetoothDefinitionsPlugin {
3131
)
3232
commands.append(command)
3333
}
34-
34+
3535
func unitIdentifierTestsBuildCommands(
3636
for context: PluginContext,
3737
target: SwiftSourceModuleTarget,

0 commit comments

Comments
 (0)