Skip to content

Commit

Permalink
Cleanup and update
Browse files Browse the repository at this point in the history
  • Loading branch information
KaQuMiQ authored Feb 2, 2023
1 parent 8a8929b commit 67d1bd8
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_13.4.1.app
run: sudo xcode-select -s /Applications/Xcode_14.2.0.app
- name: Run tests
run: make test
16 changes: 8 additions & 8 deletions FormatTool/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "82905286cc3f0fa8adc4674bf49437cab65a8373",
"version" : "1.1.1"
"revision" : "9f39744e025c7d377987f30b03770805dcb0bcd1",
"version" : "1.1.4"
}
},
{
"identity" : "swift-format",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-format.git",
"state" : {
"revision" : "e6b8c60c7671066d229e30efa1e31acf57be412e",
"version" : "0.50600.1"
"revision" : "5f184220d032a019a63df457cdea4b9c8241e911",
"version" : "0.50700.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "0b6c22b97f8e9320bca62e82cdbee601cf37ad3f",
"version" : "0.50600.1"
"revision" : "72d3da66b085c2299dd287c2be3b92b5ebd226de",
"version" : "0.50700.1"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-tools-support-core.git",
"state" : {
"revision" : "b7667f3e266af621e5cc9c77e74cacd8e8c00cb4",
"version" : "0.2.5"
"revision" : "4f07be3dc201f6e2ee85b6942d0c220a16926811",
"version" : "0.2.7"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions FormatTool/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription

let package = Package(
Expand All @@ -7,7 +7,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/apple/swift-format.git",
exact: "0.50600.1"
exact: "0.50700.1"
),
],
targets: [
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test:
swift test

lint:
swift run --configuration release --package-path ./FormatTool --build-path ./.toolsCache -- swift-format lint --configuration ./FormatTool/formatterConfig.json --parallel --recursive ./Package.swift ./Sources ./Tests
swift run --configuration release --package-path ./FormatTool --scratch-path ./.toolsCache -- swift-format lint --configuration ./FormatTool/formatterConfig.json --parallel --recursive ./Package.swift ./Sources ./Tests

format:
swift run --configuration release --package-path ./FormatTool --build-path ./.toolsCache -- swift-format format --configuration ./FormatTool/formatterConfig.json --parallel --recursive ./Package.swift ./Sources ./Tests --in-place
swift run --configuration release --package-path ./FormatTool --scratch-path ./.toolsCache -- swift-format format --configuration ./FormatTool/formatterConfig.json --parallel --recursive ./Package.swift ./Sources ./Tests --in-place
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// swift-tools-version:5.6
// swift-tools-version:5.7
import PackageDescription

let package = Package(
name: "MQ",
platforms: [
.iOS(.v13),
.macOS(.v11),
.macCatalyst(.v13),
.tvOS(.v13),
.iOS(.v14),
.macOS(.v12),
.macCatalyst(.v14),
.tvOS(.v14),
.watchOS(.v7),
],
products: [
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Platforms](https://img.shields.io/badge/platform-iOS%20|%20iPadOS%20|%20macOS-gray.svg?style=flat)]()
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
[![SwiftVersion](https://img.shields.io/badge/Swift-5.5-brightgreen.svg)]()
[![SwiftVersion](https://img.shields.io/badge/Swift-5.7-brightgreen.svg)]()

## MQ is:
- a Swift package providing extensions for the language
Expand All @@ -21,16 +21,17 @@ Preferred code style is described as a part of this repository.
MQ is a library providing Swift language extensions. It includes:
- `SourceCodeLocation`, `SourceCodeMeta`, `SourceCodeContext` - tools for gathering metadata from the source code.
- `TheError` - base interface for errors and error handling with a bunch of common error implementations.
- `Lock` - abstraction over locking
- `CriticalSection` - easy to use data synchronization.
- `DisplayableString`, `LocalizationKey` - helpers for localization and displaying data.
- `void`, `always`, `noop` - placeholders for various of contexts.
- `runtimeAssert`, `runtimeAssertionFailure` - replacement for Swift assertions that can be manually controlled i.e. to allow unit test coverage for paths using assertions.

## License

Copyright 2021 Miquido
Copyright 2021-2023 Miquido

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
20 changes: 11 additions & 9 deletions Sources/MQ/Errors/TheError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,28 @@ extension TheError /* CustomStringConvertible */ {
extension TheError /* CustomDebugStringConvertible */ {

public var debugDescription: String {
let propertiesDescription: String = self.propertiesDebugDescription
let propertiesDescription: String = self.propertiesPrettyDescription
let propertiesDescriptionEmpty: Bool = propertiesDescription.isEmpty

return """
⎡ ⚠️ \(Self.self)
⎜ 📺 \(self.displayableMessageDebugDescription)\(propertiesDescriptionEmpty ? "" : "\n⎜ 📦 Properties: \(propertiesDescription)")
⎜ 🧵 Context: \(self.context.errorDebugDescription)
⎣ ⚠️ \(Self.self)
"""
⎡ ⚠️ \(Self.self)
⎜ 📺 \(self.displayableMessagePrettyDescription)\(propertiesDescriptionEmpty ? "" : "\n⎜ 📦 Properties: \(propertiesDescription)")
⎜ 🧵 Context: \(self.context.prettyDescription)
⎣ ⚠️ \(Self.self)
"""
}

private var displayableMessageDebugDescription: String {
private var displayableMessagePrettyDescription: String {
self.displayableMessage
.resolved
.replacingOccurrences( // keep indentation
of: "\n",
with: "\n⎜ ⮑ "
)
}
private var propertiesDebugDescription: String {

private var propertiesPrettyDescription: String {
Mirror(reflecting: self)
.children // ignoring "displayStyle"
.reduce(into: String()) { result, child in
Expand Down Expand Up @@ -256,8 +257,9 @@ extension TheError {
line: UInt = #line
) -> Self {
runtimeWarning(
"%@\n%@",
"%s\n%s\n%s",
[
String(describing: Self.self),
message().asString,
self.context
.debugDescription,
Expand Down
37 changes: 20 additions & 17 deletions Sources/MQ/SourceCodeMeta/SourceCodeContext.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
/// Source code context metadata that can be collected across the application.
/// Source code metadata that can be collected across the application.
///
/// ``SourceCodeContext`` can be used to provide additional metadata for the errors or invalid application states.
/// Debug builds are allowed to collect additional dynamic values for more precise tracking and diagnostic.
/// ``SourceCodeContext`` can be used to provide additional metadata for extended application diagnostics.
/// It allows making diagnostics stack similar to stack traces.
/// However it is selected by programmer what informations are included.
/// Debug builds are allowed to collect additional dynamic values for more precise tracking and details.
/// Dynamic values are striped out in release builds to prevent potential security issues.
/// Only static metadata is collected in release builds.
///
/// ``SourceCodeContext`` consists of stack of ``SourceCodeMeta`` giving informations
/// pointing to the concrete source code locations. Locations and dynamic values can be appended when passing
/// ``SourceCodeContext`` consists of stack of ``SourceCodeMeta``
/// pointing to the concrete source code locations.
/// Locations and dynamic values can be appended when passing
/// ``SourceCodeContext`` through method calls in order to add more detailed context.
///
/// ``SourceCodeContext`` should be always avoided in application logic.
/// Collected data should be used only for diagnostics purposes.
///
/// - warning: ``SourceCodeContext`` is not intended to provide any data across application.
/// ``SourceCodeContext`` should be avoided in application logic.
/// Collected data is intended to be used
/// for diagnostics purposes.
public struct SourceCodeContext: Sendable {

/// Create ``SourceCodeMeta`` info for further diagnostics using given source code location.
/// Create ``SourceCodeMeta`` using given source code location and message.
///
/// - Parameters:
/// - message: Message associated with given source code location.
/// - file: Source code file identifier.
/// Filled automatically based on compile time constants.
/// - line: Line in given source code file.
/// Filled automatically based on compile time constants.
/// - Returns: Instance of ``SourceCodeContext`` for given message.
/// - Returns: Instance of ``SourceCodeContext`` for given message and location.
public static func context(
message: StaticString,
file: StaticString = #fileID,
Expand Down Expand Up @@ -175,9 +177,10 @@ extension SourceCodeContext: CustomStringConvertible {
.reduce(
into: "---",
{ (result: inout String, meta: SourceCodeMeta) in
result.append("\n\(meta.description)\n---")
result.append("\n\(meta.description)")
}
)
.appending("\n---")
}
}

Expand All @@ -189,17 +192,18 @@ extension SourceCodeContext: CustomDebugStringConvertible {
.reduce(
into: "---",
{ (result: inout String, meta: SourceCodeMeta) in
result.append("\n\(meta.debugDescription)\n---")
result.append("\n\(meta.debugDescription)")
}
)
.appending("\n---")
}

internal var errorDebugDescription: String {
internal var prettyDescription: String {
self.contextStack
.reduce(
into: "",
{ (result: inout String, meta: SourceCodeMeta) in
result.append("\n\(meta.errorDebugDescription)\n")
result.append("\n\(meta.prettyDescription)")
}
)
}
Expand All @@ -214,8 +218,7 @@ extension SourceCodeContext: CustomLeafReflectable {
children: [
"contextStack": self.contextStack
],
displayStyle: .struct,
ancestorRepresentation: .suppressed
displayStyle: .struct
)
}
}
19 changes: 10 additions & 9 deletions Sources/MQ/SourceCodeMeta/SourceCodeLocation.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/// Location in the source code.
///
/// ``SourceCodeLocation`` should be always avoided in application logic.
/// Collected data should be used only for diagnostics purposes.
///
/// - warning: ``SourceCodeLocation`` is not intended to provide any data across application.
public struct SourceCodeLocation: Sendable {
/// ``SourceCodeLocation`` keeps information about location
/// in the source code. It should be avoided in application logic.
/// Collected data is intended to be used
/// for diagnostics purposes.
public struct SourceCodeLocation {

/// Create instance of ``SourceCodeLocation`` pointing at given location in source code.
///
/// Default location provided is this function call location.
/// Default location is this function call location.
/// `file` and `line` arguments should not be provided manually unless it is required.
///
/// - Parameters:
/// - file: Source code file identifier.
/// Filled automatically based on compile time constants.
/// - line: Line in given source code file.
/// Filled automatically based on compile time constants.
/// - column: Optional column in given line in given source code file.
/// - column: Optional column of given line in given source code file.
/// Filled automatically based on compile time constants.
/// - Returns: Instance of ``SourceCodeLocation`` for given file and line.
public static func here(
Expand All @@ -36,6 +36,8 @@ public struct SourceCodeLocation: Sendable {
private let column: UInt?
}

extension SourceCodeLocation: Sendable {}

extension SourceCodeLocation: Hashable {}

// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
Expand Down Expand Up @@ -65,8 +67,7 @@ extension SourceCodeLocation: CustomLeafReflectable {
"line": self.line,
"column": self.column as Any,
],
displayStyle: .struct,
ancestorRepresentation: .suppressed
displayStyle: .struct
)
}
}
Loading

0 comments on commit 67d1bd8

Please sign in to comment.