From 45bb9afc7e0b6810bd17e1cda32a1b626cda3f99 Mon Sep 17 00:00:00 2001 From: Matt Gacy Date: Tue, 26 Dec 2023 16:47:12 -0700 Subject: [PATCH 1/4] Add SwiftLint --- .swiftlint.yml | 58 ++++++++++++++++++++++++++++++++++ Package.resolved | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ Package.swift | 13 +++++++- 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..6586b91 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,58 @@ +excluded: + - .build + +opt_in_rules: + - empty_count + - explicit_init + - closure_spacing + - overridden_super_call + - redundant_nil_coalescing + - private_outlet + - nimble_operator + - attributes + - operator_usage_whitespace + - closure_end_indentation + - first_where + - prohibited_super_call + - fatal_error_message + - vertical_parameter_alignment_on_call + - let_var_whitespace + - unneeded_parentheses_in_closure_argument + - extension_access_modifier + - pattern_matching_keywords + - array_init + - literal_expression_end_indentation + +disabled_rules: + - void_return + - multiple_closures_with_trailing_closure + - vertical_parameter_alignment_on_call + +identifier_name: + excluded: + - id + +type_name: + excluded: + - ID + +function_body_length: 50 + +line_length: 200 + +file_length: + warning: 500 + error: 1000 + +nesting: + type_level: + warning: 2 + function_level: + warning: 10 + +large_tuple: + warning: 6 + error: 10 + +cyclomatic_complexity: + ignores_case_statements: true diff --git a/Package.resolved b/Package.resolved index 8d89a2e..66cd51a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,41 @@ { "pins" : [ + { + "identity" : "collectionconcurrencykit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git", + "state" : { + "revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95", + "version" : "0.2.0" + } + }, + { + "identity" : "cryptoswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "state" : { + "revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e", + "version" : "1.8.0" + } + }, + { + "identity" : "sourcekitten", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/SourceKitten.git", + "state" : { + "revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56", + "version" : "0.34.1" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", + "version" : "1.2.3" + } + }, { "identity" : "swift-atomics", "kind" : "remoteSourceControl", @@ -53,6 +89,51 @@ "revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c", "version" : "2.62.0" } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036", + "version" : "509.0.2" + } + }, + { + "identity" : "swiftlint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/realm/SwiftLint.git", + "state" : { + "revision" : "f17a4f9dfb6a6afb0408426354e4180daaf49cee", + "version" : "0.54.0" + } + }, + { + "identity" : "swiftytexttable", + "kind" : "remoteSourceControl", + "location" : "https://github.com/scottrhoyt/SwiftyTextTable.git", + "state" : { + "revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", + "version" : "0.9.0" + } + }, + { + "identity" : "swxmlhash", + "kind" : "remoteSourceControl", + "location" : "https://github.com/drmohundro/SWXMLHash.git", + "state" : { + "revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", + "version" : "7.0.2" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3", + "version" : "5.0.6" + } } ], "version" : 2 diff --git a/Package.swift b/Package.swift index b23a2eb..fdcd169 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,9 @@ let package = Package( .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")), .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")), .package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", branch: "main"), - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"), + // Plugins + .package(url: "https://github.com/realm/SwiftLint.git", exact: "0.54.0") ], targets: [ .target( @@ -25,6 +27,9 @@ let package = Package( dependencies: [ .product(name: "Logging", package: "swift-log"), .product(name: "NIOCore", package: "swift-nio") + ], + plugins: [ + .plugin(name: "SwiftLintPlugin", package: "SwiftLint") ] ), .target( @@ -33,12 +38,18 @@ let package = Package( "LambdaExtrasCore", .product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"), .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events") + ], + plugins: [ + .plugin(name: "SwiftLintPlugin", package: "SwiftLint") ] ), .target( name: "LambdaMocks", dependencies: [ "LambdaExtrasCore" + ], + plugins: [ + .plugin(name: "SwiftLintPlugin", package: "SwiftLint") ] ), .testTarget( From b5af52707f58936e7d7d0244aecee224fde14bd2 Mon Sep 17 00:00:00 2001 From: Matt Gacy Date: Tue, 26 Dec 2023 16:47:20 -0700 Subject: [PATCH 2/4] Fix warning --- Sources/LambdaExtrasCore/Protocols/InitializationContext.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/LambdaExtrasCore/Protocols/InitializationContext.swift b/Sources/LambdaExtrasCore/Protocols/InitializationContext.swift index 4e64c0f..ae099d5 100644 --- a/Sources/LambdaExtrasCore/Protocols/InitializationContext.swift +++ b/Sources/LambdaExtrasCore/Protocols/InitializationContext.swift @@ -23,8 +23,6 @@ public protocol InitializationContext: Sendable { /// `ByteBufferAllocator` to allocate `ByteBuffer`. var allocator: ByteBufferAllocator { get } - // TODO: Is there any point to allowing a name to be passed? - /// Register a closure to be performed on lambda shutdown. /// /// - Parameter handler: A closure to execute when the lambda shuts down. From 502edb564c9170131d4ed30ee45d9f1318174f64 Mon Sep 17 00:00:00 2001 From: Matt Gacy Date: Wed, 27 Dec 2023 09:46:35 -0700 Subject: [PATCH 3/4] Only use SwiftLint plugin on macOS --- Package.swift | 67 ++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/Package.swift b/Package.swift index fdcd169..316a820 100644 --- a/Package.swift +++ b/Package.swift @@ -17,41 +17,9 @@ let package = Package( .package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.4.2")), .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.43.1")), .package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", branch: "main"), - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"), - // Plugins - .package(url: "https://github.com/realm/SwiftLint.git", exact: "0.54.0") + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") ], targets: [ - .target( - name: "LambdaExtrasCore", - dependencies: [ - .product(name: "Logging", package: "swift-log"), - .product(name: "NIOCore", package: "swift-nio") - ], - plugins: [ - .plugin(name: "SwiftLintPlugin", package: "SwiftLint") - ] - ), - .target( - name: "LambdaExtras", - dependencies: [ - "LambdaExtrasCore", - .product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events") - ], - plugins: [ - .plugin(name: "SwiftLintPlugin", package: "SwiftLint") - ] - ), - .target( - name: "LambdaMocks", - dependencies: [ - "LambdaExtrasCore" - ], - plugins: [ - .plugin(name: "SwiftLintPlugin", package: "SwiftLint") - ] - ), .testTarget( name: "LambdaExtrasTests", dependencies: [ @@ -60,3 +28,36 @@ let package = Package( ) ] ) + +let genericTargets: [Target] = [ + .target( + name: "LambdaExtrasCore", + dependencies: [ + .product(name: "Logging", package: "swift-log"), + .product(name: "NIOCore", package: "swift-nio") + ] + ), + .target( + name: "LambdaExtras", + dependencies: [ + "LambdaExtrasCore", + .product(name: "AWSLambdaRuntime",package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events") + ] + ), + .target( + name: "LambdaMocks", + dependencies: [ + "LambdaExtrasCore" + ] + ) +] + +#if os(macOS) +package.dependencies.append(.package(url: "https://github.com/realm/SwiftLint.git", exact: "0.54.0")) +for target in genericTargets { + target.plugins = [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")] +} +#endif + +package.targets.append(contentsOf: genericTargets) From 4cd451b9c6a0db065a18d9ced1cc6f2dda9f985c Mon Sep 17 00:00:00 2001 From: Matt Gacy Date: Wed, 27 Dec 2023 10:29:12 -0700 Subject: [PATCH 4/4] Specify LambdaExtras as the default docs --- .spi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.spi.yml b/.spi.yml index b915600..50181ea 100644 --- a/.spi.yml +++ b/.spi.yml @@ -1,4 +1,4 @@ version: 1 builder: configs: - - documentation_targets: [LambdaExtrasCore, LambdaExtras, LambdaMocks] + - documentation_targets: [LambdaExtras, LambdaExtrasCore, LambdaMocks]