Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt swift-format #21

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ on:
push: { branches: [ main ] }

jobs:
lint:
runs-on: ubuntu-latest
container: swift:jammy
steps:
- name: Check out SendGridKit
uses: actions/checkout@v4
- name: Run format lint check
run: swift format lint --strict --recursive --parallel .

unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
secrets:
Expand Down
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"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": true,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineLength": 100,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"tabWidth": 8,
"version": 1
}
18 changes: 10 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ import PackageDescription
let package = Package(
name: "sendgrid-kit",
platforms: [
.macOS(.v14),
.macOS(.v14)
],
products: [
.library(name: "SendGridKit", targets: ["SendGridKit"]),
.library(name: "SendGridKit", targets: ["SendGridKit"])
],
dependencies: [
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0")
],
targets: [
.target(
name: "SendGridKit",
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "AsyncHTTPClient", package: "async-http-client")
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SendGridKitTests",
dependencies: [
.target(name: "SendGridKit"),
.target(name: "SendGridKit")
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
] }
var swiftSettings: [SwiftSetting] {
[
.enableUpcomingFeature("ExistentialAny")
]
}
10 changes: 5 additions & 5 deletions Sources/SendGridKit/Models/AdvancedSuppressionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import Foundation

public struct AdvancedSuppressionManager: Codable, Sendable {
/// The unsubscribe group to associate with this email.
///
///
/// See the Suppressions API to manage unsubscribe group IDs.
public var groupID: Int

/// An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page.
///
///
/// This page is displayed in the recipient's browser when they click the unsubscribe link in your message.
public var groupsToDisplay: [String]?

public init(
groupID: Int,
groupsToDisplay: [String]? = nil
) {
self.groupID = groupID
self.groupsToDisplay = groupsToDisplay
}

private enum CodingKeys: String, CodingKey {
case groupID = "group_id"
case groupsToDisplay = "groups_to_display"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SendGridKit/Models/EmailAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation
public struct EmailAddress: Codable, Sendable {
/// The email address of the person to whom you are sending an email.
public var email: String

/// The name of the person to whom you are sending an email.
public var name: String?

public init(
email: String,
name: String? = nil
Expand Down
18 changes: 9 additions & 9 deletions Sources/SendGridKit/Models/EmailAttachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import Foundation
public struct EmailAttachment: Codable, Sendable {
/// The Base64 encoded content of the attachment.
public var content: String

/// The MIME type of the content you are attaching.
///
///
/// For example, `image/jpeg`, `text/html` or `application/pdf`.
public var type: String?

/// The attachment's filename, including the file extension.
public var filename: String

/// The attachment's content-disposition specifies how you would like the attachment to be displayed.
///
///
/// For example, inline results in the attached file being displayed automatically within the message
/// while attachment results in the attached file requiring some action to be taken before it is displayed
/// such as opening or downloading the file.
Expand All @@ -23,13 +23,13 @@ public struct EmailAttachment: Codable, Sendable {
case inline
case attachment
}

/// The content ID for the attachment.
///
///
/// This is used when the disposition is set to “inline” and the attachment is an image,
/// allowing the file to be displayed within the body of your email.
public var contentID: String?

public init(
content: String,
type: String? = nil,
Expand All @@ -43,7 +43,7 @@ public struct EmailAttachment: Codable, Sendable {
self.disposition = disposition
self.contentID = contentID
}

private enum CodingKeys: String, CodingKey {
case content
case type
Expand Down
4 changes: 2 additions & 2 deletions Sources/SendGridKit/Models/EmailContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Foundation

public struct EmailContent: Codable, Sendable {
/// The MIME type of the content you are including in your email.
///
///
/// For example, `“text/plain”` or `“text/html”`.
public var type: String

/// The actual content of the specified MIME type that you are including in your email.
///
///
/// > Important: The minimum length is 1.
public var value: String

Expand Down
20 changes: 10 additions & 10 deletions Sources/SendGridKit/Models/MailSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ import Foundation

public struct MailSettings: Codable, Sendable {
/// Allows you to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient.
///
///
/// > Important: This should only be used in emergencies when it is absolutely necessary that every recipient receives your email.
public var bypassListManagement: Setting?

/// Allows you to bypass the spam report list to ensure that the email is delivered to recipients.
///
///
/// > Note: Bounce and unsubscribe lists will still be checked;
/// addresses on these other lists will not receive the message.
public var bypassSpamManagement: Setting?

/// Allows you to bypass the bounce list to ensure that the email is delivered to recipients.
///
///
/// > Note: Spam report and unsubscribe lists will still be checked;
/// addresses on these other lists will not receive the message.
public var bypassBounceManagement: Setting?

/// The default footer that you would like included on every email.
public var footer: Footer?

/// This allows you to send a test email to ensure that your request body is valid and formatted correctly.
public var sandboxMode: Setting?

public init(
bypassListManagement: Setting? = nil,
bypassSpamManagement: Setting? = nil,
Expand All @@ -37,7 +37,7 @@ public struct MailSettings: Codable, Sendable {
self.footer = footer
self.sandboxMode = sandboxMode
}

private enum CodingKeys: String, CodingKey {
case bypassListManagement = "bypass_list_management"
case bypassSpamManagement = "bypass_spam_management"
Expand All @@ -59,13 +59,13 @@ public struct Setting: Codable, Sendable {
public struct Footer: Codable, Sendable {
/// Indicates if this setting is enabled.
public var enable: Bool

/// The plain text content of your footer.
public var text: String?

/// The HTML content of your footer.
public var html: String?

public init(
enable: Bool,
text: String? = nil,
Expand Down
22 changes: 11 additions & 11 deletions Sources/SendGridKit/Models/Personalization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Foundation

public struct Personalization<DynamicTemplateData: Codable & Sendable>: Codable, Sendable {
/// An array of recipients.
///
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var to: [EmailAddress]?

/// An array of recipients who will receive a copy of your email.
///
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var cc: [EmailAddress]?

/// An array of recipients who will receive a blind carbon copy of your email.
///
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var bcc: [EmailAddress]?

Expand All @@ -24,18 +24,18 @@ public struct Personalization<DynamicTemplateData: Codable & Sendable>: Codable,

/// A collection of key/value pairs following the pattern `"substitution_tag":"value to substitute"`.
public var substitutions: [String: String]?

/// A collection of key/value pairs following the pattern `"key":"value"` to substitute handlebar template data.
public var dynamicTemplateData: DynamicTemplateData?

/// Values that are specific to this personalization that will be carried along with the email and its activity data.
public var customArgs: [String: String]?

/// A UNIX timestamp allowing you to specify when you want your email to be delivered.
///
///
/// > Important: Scheduling more than 72 hours in advance is forbidden.
public var sendAt: Date?

public init(
to: [EmailAddress]? = nil,
cc: [EmailAddress]? = nil,
Expand All @@ -57,7 +57,7 @@ public struct Personalization<DynamicTemplateData: Codable & Sendable>: Codable,
self.customArgs = customArgs
self.sendAt = sendAt
}

private enum CodingKeys: String, CodingKey {
case to
case cc
Expand All @@ -71,8 +71,8 @@ public struct Personalization<DynamicTemplateData: Codable & Sendable>: Codable,
}
}

public extension Personalization where DynamicTemplateData == [String: String] {
init(
extension Personalization where DynamicTemplateData == [String: String] {
public init(
to: [EmailAddress]? = nil,
cc: [EmailAddress]? = nil,
bcc: [EmailAddress]? = nil,
Expand Down
Loading