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 ¶ added in v0.53.0
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 ¶ added in v0.53.0
NewFile creates a new File.
Do not modify the data after calling this function, Lines will point to it.
func (File) PrintHighlights ¶ added in v0.63.0
func (f File) PrintHighlights(w io.Writer, msg string, highlights []Highlight, opts PrintListingOptions) error
PrintHighlights prints all given highlights.
func (File) PrintListing ¶ added in v0.63.0
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 ¶ added in v0.53.0
SetPosition sets the position of the value.
type MultiError ¶ added in v0.63.0
type MultiError struct {
// contains filtered or unexported fields
}
MultiError contains multiple Reports.
func (*MultiError) Error ¶ added in v0.63.0
func (e *MultiError) Error() string
Error implements error.
func (*MultiError) Format ¶ added in v0.63.0
func (e *MultiError) Format(s fmt.State, verb rune)
Format implements fmt.Formatter.
func (*MultiError) FormatError ¶ added in v0.63.0
func (e *MultiError) FormatError(p errors.Printer) error
FormatError implements errors.Formatter.
func (*MultiError) Report ¶ added in v0.63.0
func (e *MultiError) Report(file File, l Locator, msg string)
Report adds report to the list.
func (*MultiError) ReportPtr ¶ added in v0.63.0
func (e *MultiError) ReportPtr(ptr Pointer, msg string)
ReportPtr adds report to the list at given pointer.
type Pointer ¶ added in v0.54.0
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 ¶ added in v0.62.0
Field tries to find the child node using given key and returns its pointer.
See Field method of Locator.
func (Pointer) Index ¶ added in v0.62.0
Index tries to find the child node using given index and returns its pointer.
See Index method of Locator.
type Position ¶ added in v0.53.0
Position is a value position.
func (Position) Field ¶ added in v0.53.0
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) FromNode ¶ added in v0.53.0
FromNode sets the position of the value from the given node.
func (Position) Index ¶ added in v0.53.0
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 ¶ added in v0.53.0
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 ¶ added in v0.53.0
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 ¶ added in v0.52.0
func (o PrintListingOptions) WithoutColor() PrintListingOptions
WithoutColor creates a copy of the options with disabled color.