Skip to content

Commit

Permalink
Merge pull request #11 from fireblade-engine/mint-lint
Browse files Browse the repository at this point in the history
Add Mint + Lint/Format
  • Loading branch information
ctreffs authored Apr 21, 2023
2 parents 9d84709 + 5314c2f commit d88fb95
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 197 deletions.
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
lint:
swiftlint autocorrect --format
SWIFT_PACKAGE_VERSION := $(shell swift package tools-version)

genLinuxTests:
swift test --generate-linuxmain
swiftlint autocorrect --format --path Tests/
lint-fix:
mint run swiftlint --fix --quiet
mint run swiftformat --quiet --swiftversion ${SWIFT_PACKAGE_VERSION} .

test: genLinuxTests
swift test
Expand All @@ -18,16 +17,9 @@ clean:
cleanArtifacts:
swift package clean

genXcode:
swift package generate-xcodeproj --enable-code-coverage --skip-extra-files

latest:
swift package update

resolve:
swift package resolve

genXcodeOpen: genXcode
open *.xcodeproj

precommit: lint genLinuxTests
2 changes: 2 additions & 0 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
realm/SwiftLint@0.51.0
nicklockwood/SwiftFormat@0.51.7
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "8f4bfa5bc1951440c15710e9e893721aa4b2765c",
"version": "1.1.3"
"revision": "33a20e650c33f6d72d822d558333f2085effa3dc",
"version": "2.5.0"
}
}
]
Expand Down
13 changes: 8 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import PackageDescription

let swiftSettings: [SwiftSetting]?
#if canImport(Foundation)
swiftSettings = nil
swiftSettings = nil
#else
swiftSettings = [.define("USE_FRB_UUID")]
swiftSettings = [.define("USE_FRB_UUID")]
#endif

let package = Package(
Expand All @@ -20,17 +20,20 @@ let package = Package(
products: [
.library(
name: "FirebladeUUID",
targets: ["FirebladeUUID"])
targets: ["FirebladeUUID"]
),
],
dependencies: [.package(url: "https://github.com/apple/swift-crypto.git", from: "2.5.0")],
targets: [
.target(
name: "FirebladeUUID",
dependencies: [.product(name: "Crypto", package: "swift-crypto")],
swiftSettings: swiftSettings),
swiftSettings: swiftSettings
),
.testTarget(
name: "FirebladeUUIDTests",
dependencies: ["FirebladeUUID"])
dependencies: ["FirebladeUUID"]
),
],
swiftLanguageVersions: [.v5]
)
12 changes: 6 additions & 6 deletions Sources/FirebladeUUID/Shims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//

#if USE_FRB_UUID
public typealias UUID = FRB_UUID
public typealias UUID_t = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
public typealias UUID = FRB_UUID
public typealias UUID_t = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
#else
import struct Foundation.UUID
import typealias Foundation.uuid_t
public typealias UUID = Foundation.UUID
public typealias UUID_t = uuid_t
import struct Foundation.UUID
import typealias Foundation.uuid_t
public typealias UUID = Foundation.UUID
public typealias UUID_t = uuid_t
#endif
4 changes: 2 additions & 2 deletions Sources/FirebladeUUID/UUID+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extension UUID {
}
}
precondition(written == UUID.count)
uuidBytes.6 = (uuidBytes.6 & 0x0f) | 0x40 // version https://tools.ietf.org/html/rfc4122#section-4.1.3
uuidBytes.8 = (uuidBytes.8 & 0x3f) | 0x80 // variant https://tools.ietf.org/html/rfc4122#section-4.1.1
uuidBytes.6 = (uuidBytes.6 & 0x0F) | 0x40 // version https://tools.ietf.org/html/rfc4122#section-4.1.3
uuidBytes.8 = (uuidBytes.8 & 0x3F) | 0x80 // variant https://tools.ietf.org/html/rfc4122#section-4.1.1
self.init(uuid: uuidBytes)
}
}
18 changes: 9 additions & 9 deletions Sources/FirebladeUUID/UUID+Name.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@

import Crypto

extension UUID {
public init(name: String, namespace: UUID) {
public extension UUID {
init(name: String, namespace: UUID) {
var hasher = Crypto.Insecure.SHA1()
hasher.update(uuidBytes: namespace.uuid)
hasher.update(collection: name.utf8)
self.init(contiguous: hasher.finalize())
}
}

extension UUID {
public extension UUID {
/// UUID Namespace
///
/// <https://tools.ietf.org/html/rfc4122#appendix-C>
public enum Namespace { }
enum Namespace {}
}

extension UUID.Namespace {
public extension UUID.Namespace {
/// Name string is a fully-qualified domain name
///
/// `6ba7b810-9dad-11d1-80b4-00c04fd430c8`
public static let DNS = UUID(uuid: UUID_t(0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8))
static let DNS = UUID(uuid: UUID_t(0x6B, 0xA7, 0xB8, 0x10, 0x9D, 0xAD, 0x11, 0xD1, 0x80, 0xB4, 0x00, 0xC0, 0x4F, 0xD4, 0x30, 0xC8))

/// Name string is a URL
///
/// `6ba7b811-9dad-11d1-80b4-00c04fd430c8`
public static let URL = UUID(uuid: UUID_t(0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8))
static let URL = UUID(uuid: UUID_t(0x6B, 0xA7, 0xB8, 0x11, 0x9D, 0xAD, 0x11, 0xD1, 0x80, 0xB4, 0x00, 0xC0, 0x4F, 0xD4, 0x30, 0xC8))

/// Name string is an ISO OID
///
/// `6ba7b812-9dad-11d1-80b4-00c04fd430c8`
public static let OID = UUID(uuid: UUID_t(0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8))
static let OID = UUID(uuid: UUID_t(0x6B, 0xA7, 0xB8, 0x12, 0x9D, 0xAD, 0x11, 0xD1, 0x80, 0xB4, 0x00, 0xC0, 0x4F, 0xD4, 0x30, 0xC8))

/// Name string is an X.500 DN (in DER or a text output format)
///
/// `6ba7b814-9dad-11d1-80b4-00c04fd430c8`
public static let X500 = UUID(uuid: UUID_t(0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8))
static let X500 = UUID(uuid: UUID_t(0x6B, 0xA7, 0xB8, 0x14, 0x9D, 0xAD, 0x11, 0xD1, 0x80, 0xB4, 0x00, 0xC0, 0x4F, 0xD4, 0x30, 0xC8))
}
Loading

0 comments on commit d88fb95

Please sign in to comment.