PureYAML/Sources/Validation/Validation.Diagnostic.swift
Mihaela M c4f7f9dccc refactor(code-style): one top-level type per source file
Split the six files that declared multiple sibling types under one
namespace extension so each file declares exactly one top-level type:
the Tagged node component types (Node, NodeKind, Scalar, Sequence,
Mapping, Pair), the validation report types (Report, Source,
SourceReport, BatchReport), DiagnosticKind, TokenKind, ScannerFlowContext
kind, and the event-stream composer helpers. Public type names are
unchanged; the shared report-rendering helpers move from file-private to
internal so the split report types still reach them.

Make check-namespacing.sh namespace-aware: the previous column-anchored
scan was blind to types declared inside indented extension blocks, so it
passed while the rule was violated. It now counts direct members of a
PureYAML namespace extension and ignores nested types and private helpers.
2026-06-26 06:14:21 +02:00

59 lines
1.9 KiB
Swift

public extension PureYAML.Validation {
/// A parse or validation diagnostic suitable for batch validation reports.
struct Diagnostic: Equatable, Sendable, CustomStringConvertible {
public var kind: DiagnosticKind
public var code: String?
public var severity: Severity
public var file: String?
public var line: Int?
public var column: Int?
public var documentIndex: Int?
public var path: Path?
public var reason: String
public init(
kind: DiagnosticKind,
code: String? = nil,
severity: Severity,
file: String? = nil,
line: Int? = nil,
column: Int? = nil,
documentIndex: Int? = nil,
path: Path? = nil,
reason: String,
) {
self.kind = kind
self.code = code
self.severity = severity
self.file = file
self.line = line
self.column = column
self.documentIndex = documentIndex
self.path = path
self.reason = reason
}
public var description: String {
var parts: [String] = []
if let file {
parts.append(file)
}
if let line, let column {
parts.append("line \(line), column \(column)")
} else if let line {
parts.append("line \(line)")
} else if let column {
parts.append("column \(column)")
}
if let documentIndex {
parts.append("document[\(documentIndex)]")
}
if let path {
parts.append(path.isRoot ? "root" : path.description)
}
let location = parts.isEmpty ? "input" : parts.joined(separator: ": ")
return "\(location): \(severity): \(kind): \(reason)"
}
}
}