Skip to content

Commit

Permalink
Merge pull request #180 from PureSwift/feature/swift-lint
Browse files Browse the repository at this point in the history
Add Swift Lint and Formatting
  • Loading branch information
colemancda authored Jan 13, 2025
2 parents 4a57214 + c121bb7 commit 3aeeb31
Show file tree
Hide file tree
Showing 483 changed files with 18,826 additions and 17,340 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Swift Lint
on: [pull_request]
jobs:
swift-format-lint:
name: swift-format lint
runs-on: ubuntu-latest
container: swift:6.0.3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Swift Version
run: swift --version
- name: Lint
run: swift format lint -r ./ --configuration .swift-format

swiftlint:
name: swiftlint
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Swift
uses: slashmo/[email protected]
with:
version: 6.0.3
- name: Swift Version
run: swift --version
- name: Install SwiftLint
run: brew install swiftlint
- name: Lint
run: swiftlint
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"indentation" : {
"spaces" : 4
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 1000,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : false,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : false,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : false,
"ReplaceForEachWithForLoop" : false,
"ReturnVoidInsteadOfEmptyTuple" : false,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : true,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : false,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 8,
"version" : 1
}
65 changes: 65 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
included:
- Plugins
- Source
- Tests
- Package.swift
analyzer_rules:
- unused_declaration
- unused_import
disabled_rules:
- comma
- void_return
- cyclomatic_complexity
- force_cast
- large_tuple
- comment_spacing
- private_over_fileprivate
- redundant_discardable_let
- statement_position
- file_length
- function_body_length
- identifier_name
- line_length
- number_separator
- sorted_imports
- trailing_whitespace
- vertical_whitespace
- vertical_whitespace_opening_braces
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- type_body_length
- anonymous_argument_in_multiline_closure
- async_without_await
- conditional_returns_on_newline
- contrasted_opening_brace
- convenience_type
- discouraged_optional_collection
- explicit_acl
- explicit_enum_raw_value
- explicit_top_level_acl
- explicit_type_interface
- file_types_order
- force_unwrapping
- function_default_parameter_at_end
- indentation_width
- missing_docs
- multiline_arguments
- multiline_arguments_brackets
- multiline_function_chains
- multiline_parameters_brackets
- no_extension_access_modifier
- no_grouping_extension
- no_magic_numbers
- one_declaration_per_file
- prefer_key_path # Re-enable once we are on Swift 6.
- prefer_nimble
- prefixed_toplevel_constant
- required_deinit
- sorted_enum_cases
- strict_fileprivate
- switch_case_on_newline
- todo
- trailing_closure
- type_contents_order
- vertical_whitespace_between_cases
- inclusive_language
28 changes: 14 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var package = Package(
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
.tvOS(.v13)
],
products: [
.library(
Expand Down Expand Up @@ -74,7 +74,7 @@ var package = Package(
.target(
name: "BluetoothGATT",
dependencies: [
"Bluetooth",
"Bluetooth"
]
),
.target(
Expand All @@ -93,15 +93,15 @@ var package = Package(
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
),
.target(
name: "BluetoothGAP",
name: "BluetoothGAP",
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
),
.target(
name: "BluetoothGATT",
name: "BluetoothGATT",
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
),
.target(
name: "BluetoothHCI",
name: "BluetoothHCI",
condition: .when(platforms: [.macOS, .linux, .macCatalyst, .windows])
)
]
Expand All @@ -127,7 +127,7 @@ if buildDocs {
}

if generateCode {
for (index, _) in package.targets.enumerated() {
for index in package.targets.indices {
package.targets[index].swiftSettings = [
.define("SWIFTPM_ENABLE_PLUGINS")
]
Expand Down Expand Up @@ -169,14 +169,14 @@ if enableMacros {
.macro(
name: "BluetoothMacros",
dependencies: [
.product(
name: "SwiftSyntaxMacros",
package: "swift-syntax"
),
.product(
name: "SwiftCompilerPlugin",
package: "swift-syntax"
)
.product(
name: "SwiftSyntaxMacros",
package: "swift-syntax"
),
.product(
name: "SwiftCompilerPlugin",
package: "swift-syntax"
)
]
)
]
Expand Down
5 changes: 3 additions & 2 deletions Plugins/GenerateBluetoothDefinitions/BluetoothUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import PackagePlugin

extension GenerateBluetoothDefinitionsPlugin {

func bluetoothUUIDBuildCommands(
type: String,
fileName: String,
Expand All @@ -25,7 +25,8 @@ extension GenerateBluetoothDefinitionsPlugin {
let outputURLs = [
outputDirectory.appending(component: fileName + ".swift")
]
let arguments = ["uuid", type]
let arguments =
["uuid", type]
+ outputURLs.map { $0.path() }
let command = Command.buildCommand(
displayName: "Generate Bluetooth \(type) UUID Definitions",
Expand Down
4 changes: 2 additions & 2 deletions Plugins/GenerateBluetoothDefinitions/CompanyIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import PackagePlugin

extension GenerateBluetoothDefinitionsPlugin {

func companyIdentifiersBuildCommands(
for context: PluginContext,
target: SwiftSourceModuleTarget,
Expand All @@ -34,7 +34,7 @@ extension GenerateBluetoothDefinitionsPlugin {
assert(arguments.count == 2)
commands.append(command)
}

func companyIdentifierTestsBuildCommands(
for context: PluginContext,
target: SwiftSourceModuleTarget,
Expand Down
8 changes: 4 additions & 4 deletions Plugins/GenerateBluetoothDefinitions/Plugin.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Plugin.swift
//
//
//
// Created by Alsey Coleman Miller on 6/12/22.
//
Expand All @@ -18,7 +18,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
}
var commands = [Command]()
commands.reserveCapacity(10)

// Generate Bluetooth Company Identifier Definitions
try companyIdentifiersBuildCommands(for: context, target: target, commands: &commands)
// Generate Bluetooth Company Identifier Unit Tests
Expand All @@ -33,7 +33,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
("Characteristic", "CharacteristicUUID"),
("Descriptor", "DescriptorUUID"),
("Member", "MemberUUID"),
("Declaration", "DeclarationUUID"),
("Declaration", "DeclarationUUID")
]
for (type, fileName) in uuidFiles {
try bluetoothUUIDBuildCommands(
Expand All @@ -44,7 +44,7 @@ struct GenerateBluetoothDefinitionsPlugin: BuildToolPlugin {
commands: &commands
)
}

return commands
}
}
4 changes: 2 additions & 2 deletions Plugins/GenerateBluetoothDefinitions/UnitIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import PackagePlugin

extension GenerateBluetoothDefinitionsPlugin {

func unitIdentifiersBuildCommands(
for context: PluginContext,
target: SwiftSourceModuleTarget,
Expand All @@ -31,7 +31,7 @@ extension GenerateBluetoothDefinitionsPlugin {
)
commands.append(command)
}

func unitIdentifierTestsBuildCommands(
for context: PluginContext,
target: SwiftSourceModuleTarget,
Expand Down
Loading

0 comments on commit 3aeeb31

Please sign in to comment.