Skip to content

0.1.1

Choose a tag to compare

@WendellXY WendellXY released this 25 Sep 03:56
· 8 commits to main since this release

Compile-time-validated descriptions for Swift enums, structs, classes, and actors.

.package(url: "https://github.com/WendellXY/Description.git", from: "0.1.1")
@Describable
enum RequestState {
    case idle

    @Description("Loading {url}")
    case loading(url: URL)
}

@Describable("HTTPError(code: {code})", error: "The request failed with HTTP {code}.")
struct HTTPError: Error {
    let code: Int
}

Features

  • @Describable synthesizes CustomStringConvertible for enums, structs, classes, and actors. It also synthesizes LocalizedError when the type lists Error in its inheritance clause.
  • @Description configures individual enum cases. Cases without one are described by their name.
  • Templates support {name}, {0}, and {{ / }}. Placeholders are validated during macro expansion.
  • Diagnostics point inside the template. Fix-its correct misspelled fields, escape stray braces, insert a memberwise template, and add Error conformance.
  • Actor descriptions are nonisolated, and actor-isolated state is rejected at compile time.
  • Existing description, errorDescription, and conformances are reported instead of overridden.

Changes since 0.1.0

  • Added the MIT license.
  • Added GitHub Actions CI, which runs the test suite on macOS and on Linux with Swift 6.0, 6.1, and 6.2.
  • Made the test suite compatible with Swift 6.0.
  • Documented a Foundation crash on Linux before Swift 6.2: localizedDescription crashes on any class-based Error, with or without @Describable. Read errorDescription directly, or use a struct or enum error.

No changes to the macros or their generated code.

Requirements: Swift 6.0 or later, and swift-syntax 600 through 604.