Documentation
¶
Overview ¶
Package diag carries the widget validator's location-anchored findings and the identifiers of the error catalogue every finding belongs to.
A finding is data, never a Go error: the validator runs both its passes to completion and reports every finding, so the caller receives a sorted slice rather than the first failure. The rendering rules — the message template, the truncation of quoted author text, the enumeration of closed sets — live here because the validator's output is a publication surface, and one implementation of those rules is the only way they stay true.
The catalogue itself is candace/pkg/widget/docs/errors.md. Every class constant below names its identifier there.
Index ¶
Constants ¶
const EnumerationLimit = 8
EnumerationLimit is the largest closed set a message lists in full, per message rule M4.
const QuoteLimit = 40
QuoteLimit is the longest author-written literal a message may echo, per message rule M6. Longer text is truncated and elided.
Variables ¶
This section is empty.
Functions ¶
func EditDistance ¶
EditDistance is the Levenshtein distance between two strings, counted in Unicode code points. It ranks the members of a closed set by how near they are to what the author wrote.
func Enumerate ¶
Enumerate renders a closed set for a message: in full when it has EnumerationLimit members or fewer, otherwise the three nearest to the value the author wrote followed by the count of the rest.
func Quote ¶
Quote renders author-written text as a double-quoted literal, truncated to QuoteLimit code points with an ellipsis. A message never grows without bound with text the author controls.
Types ¶
type Class ¶
type Class string
Class identifies one error class of the catalogue. Its string value is the identifier printed in a message and cited in docs/errors.md.
const ( ClassPreambleFirstStatement Class = "W001" ClassPreambleDirectiveMissing Class = "W002" ClassDialectVersionUnsupported Class = "W003" ClassBlockNameUnknown Class = "W004" ClassBlockOutOfOrder Class = "W005" ClassBlockDuplicated Class = "W006" ClassBlockEmpty Class = "W007" ClassBlockUnclosed Class = "W008" ClassEndWithoutBlock Class = "W009" ClassStatementAtDocumentScope Class = "W010" ClassRequiredBlockMissing Class = "W011" ClassBlockNestedTooDeep Class = "W012" ClassStatementKeywordUnknown Class = "W013" )
The document and block structure classes.
const ( ClassIdentifierCase Class = "W101" ClassStringUnterminated Class = "W102" ClassInterpolationMalformed Class = "W103" ClassIntegerOutOfRange Class = "W104" ClassValueNotEnumerated Class = "W105" ClassClauseMissing Class = "W106" ClassClauseDuplicated Class = "W107" ClassRegionIdentityMalformed Class = "W108" ClassWireNameMalformed Class = "W109" ClassClauseArgumentsMalformed Class = "W110" )
The lexical and literal classes.
const ( ClassIdentifierUndeclared Class = "W201" ClassForwardReference Class = "W202" ClassIdentifierWrongKind Class = "W203" ClassTokenNameUnknown Class = "W204" ClassSignalUnknown Class = "W205" ClassInterpolationNotStateField Class = "W206" ClassInterpolationOfFlag Class = "W207" ClassPaletteUnknown Class = "W208" )
The reference classes.
const ( ClassIdentifierDuplicated Class = "W301" ClassSingularStatementRepeated Class = "W302" ClassContainerUnderfilled Class = "W303" ClassEdgePairDuplicated Class = "W304" ClassPulseDuplicated Class = "W305" ClassEmphasisDuplicated Class = "W307" )
The cardinality and duplication classes.
const ( ClassBindingNotTotal Class = "W401" ClassLabelSourceCount Class = "W402" ClassEdgeSelfLoop Class = "W403" ClassPulseChannelNotCarried Class = "W404" ClassMotionTickMissing Class = "W405" ClassTickNotCounter Class = "W406" ClassEmphasisForbiddenByRole Class = "W407" ClassPredicateCycle Class = "W408" ClassStateFieldUnwritten Class = "W409" ClassDeclarationUnreferenced Class = "W410" ClassControlEventUndeclared Class = "W411" ClassEventFieldTypeMismatch Class = "W412" ClassRuntimeMintedEvent Class = "W413" ClassTickWithoutAnimation Class = "W414" ClassBindingClauseUnreachable Class = "W415" ClassBoundFieldNotNumeric Class = "W416" ClassToggleFieldNotFlag Class = "W417" ClassOrderingFieldNotCounter Class = "W418" ClassSignalFieldNotFlag Class = "W419" )
The semantic invariant classes.
const ( ClassMermaidEdgeOperator Class = "W501" ClassMermaidShapeBracket Class = "W502" ClassMermaidKeyword Class = "W503" ClassMermaidInitDirective Class = "W504" ClassColourLiteral Class = "W505" ClassTimeUnitSigil Class = "W506" ClassLiteralWhereLabelExpected Class = "W507" ClassTrailingComment Class = "W508" )
The canonical-form classes: the four Anka rules, enforced.
type Finding ¶
type Finding struct {
Class Class
At SourcePosition
Message string
Fix string
Related []Related
}
Finding is one location-anchored report. Message states what is wrong in the present indicative and names its subject; Fix is one imperative sentence naming the exact spelling to write.
func New ¶
func New(class Class, at SourcePosition, message string, fix string) Finding
New builds a finding anchored at one position. It closes the message and the fix with a full stop when the caller has not, because the template in docs/errors.md ends both with one and a rule every call site has to remember is a rule that holds until somebody forgets.
func (Finding) WithRelated ¶
func (finding Finding) WithRelated(at SourcePosition, note string) Finding
WithRelated returns a copy of the finding carrying one more secondary anchor.
type Related ¶
type Related struct {
At SourcePosition
Note string
}
Related is a secondary anchor: the declaration a reference error points back at (A2), or the first occurrence a duplicate is compared against (A4).
type SourcePosition ¶
SourcePosition is one anchor in a document. Columns are 1-based and counted in Unicode code points, per anchoring rule A7. File is the path the author gave, unmodified: no absolute path is ever constructed (message rule M5).
func (SourcePosition) String ¶
func (position SourcePosition) String() string
String renders the anchor as `document:line:column`.
type SourceSpan ¶
SourceSpan is the extent of one construct, carried by every IR record so a generator can trace emitted output back to the statement that produced it.
func (SourceSpan) Start ¶
func (span SourceSpan) Start() SourcePosition
Start is the span's opening anchor, which is where a finding about the construct is reported.