Documentation ¶
Overview ¶
Package location provides utilities to track values over the spec.
Index ¶
- Constants
- func PrintPrettyError(w io.Writer, color bool, err error) bool
- type ColorFunc
- type Error
- type File
- type Highlight
- type Lines
- type Locatable
- type Locator
- func (l Locator) Field(key string) (loc Locator)
- func (l Locator) Index(idx int) (loc Locator)
- func (l Locator) Key(key string) (loc Locator)
- func (l Locator) Pointer(file File) Pointer
- func (l Locator) Position() (Position, bool)
- func (l *Locator) SetPosition(loc Position)
- func (l *Locator) UnmarshalYAML(n *yaml.Node) error
- type MultiError
- type Pointer
- type Position
- type PrintListingOptions
- type Report
Constants ¶
const (
// BugLine is a fallback line when the line is not available.
BugLine = `Cannot render line properly, please fill a bug report`
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
Error is a wrapper for an error that has a location.
func (*Error) FormatError ¶
FormatError implements errors.Formatter.
type File ¶
type File struct { // Name is the file name. Name string // Source is the path or URL of the file. Source string // Lines stores newline offsets. Lines Lines }
File is a source file.
func NewFile ¶
NewFile creates a new File.
Do not modify the data after calling this function, Lines will point to it.
func (File) PrintHighlights ¶
func (f File) PrintHighlights(w io.Writer, msg string, highlights []Highlight, opts PrintListingOptions) error
PrintHighlights prints all given highlights.
func (File) PrintListing ¶
PrintListing prints given message with line number and file listing to the writer.
The context parameter defines the number of lines to print before and after.
type Lines ¶
type Lines struct {
// contains filtered or unexported fields
}
Lines is a sorted slice of newline offsets.
type Locatable ¶
type Locatable interface { // SetPosition sets the position of the value. SetPosition(Position) // Position returns the position of the value if it is set. Position() (Position, bool) }
Locatable is an interface for JSON value position store.
type Locator ¶
type Locator struct {
// contains filtered or unexported fields
}
Locator is a Position holder.
Basically, it is a simple wrapper around Position to embed it to spec types.
func (Locator) Field ¶
Field tries to find the child node using given key and returns its position.
See Field method of Position.
func (Locator) Index ¶
Index tries to find the child node using given index and returns its position.
See Index method of Position.
func (Locator) Key ¶
Key tries to find the child node using given key and returns its position.
See Key method of Position.
func (*Locator) SetPosition ¶
SetPosition sets the position of the value.
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError contains multiple Reports.
func (*MultiError) Format ¶
func (e *MultiError) Format(s fmt.State, verb rune)
Format implements fmt.Formatter.
func (*MultiError) FormatError ¶
func (e *MultiError) FormatError(p errors.Printer) error
FormatError implements errors.Formatter.
func (*MultiError) Report ¶
func (e *MultiError) Report(file File, l Locator, msg string)
Report adds report to the list.
func (*MultiError) ReportPtr ¶
func (e *MultiError) ReportPtr(ptr Pointer, msg string)
ReportPtr adds report to the list at given pointer.
type Pointer ¶
type Pointer struct { // Source is the File where the value is located. Source File // Locator stores the Position of a value. Locator Locator }
Pointer is a location of a value.
func (Pointer) Field ¶
Field tries to find the child node using given key and returns its pointer.
See Field method of Locator.
func (Pointer) Index ¶
Index tries to find the child node using given index and returns its pointer.
See Index method of Locator.
type Position ¶
Position is a value position.
func (Position) Field ¶
Field tries to find the child node using given key and returns its position. If such node is not found or parent node is not a mapping, Field returns position of the parent node.
NOTE: child position will point to the value node, not to the key node. Use Key if you want position of the key.
func (Position) Index ¶
Index tries to find the child node using given index and returns its position. If such node is not found or parent node is not a sequence, Field returns position of the parent node.
func (Position) Key ¶
Key tries to find the child node using given key and returns its position. If such node is not found or parent node is not a mapping, Key returns position of the parent node.
NOTE: child position will point to the key node, not to the value node. Use Field if you want position of the value.
func (Position) WithFilename ¶
WithFilename prints the position with the given filename.
If filename is empty, the position is printed as is.
type PrintListingOptions ¶
type PrintListingOptions struct { // Context is the number of lines to print before and after the error line. // // If is zero, the default value 5 is used. Context int // MsgColor sets message color. MsgColor ColorFunc // TextColor sets text color. PlainColor ColorFunc }
PrintListingOptions is a set of options for PrintListing.
func (PrintListingOptions) WithoutColor ¶
func (o PrintListingOptions) WithoutColor() PrintListingOptions
WithoutColor creates a copy of the options with disabled color.