Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDiagnostic ¶
func NewDiagnostic( level DiagnosticLevel, position parser.PositionRange, message string, colored bool, ) *diagnostic
NewDiagnostic creates a new default diagnostic.
func NewDiagnostics ¶
func NewDiagnostics() *diagnostics
NewDiagnostics creates a new default Diagnostics.
Types ¶
type Diagnostic ¶
type Diagnostic interface { // Level returns the diagnostic level. Level() DiagnosticLevel // Report outputs the lint result to the out stream. Report(pluginName string, rawExpr *string, out io.Writer) error }
Diagnostic is the detailed message from linter plugin's rules.
type DiagnosticLevel ¶
type DiagnosticLevel uint
DiagnosticLevel represents the level of a diagnostic.
const ( // DiagnosticLevelInfo represents the "information" level. DiagnosticLevelInfo DiagnosticLevel = iota // DiagnosticLevelWarning represents the "warning" level. DiagnosticLevelWarning // DiagnosticLevelError represents the "error" level. DiagnosticLevelError )
func (DiagnosticLevel) String ¶
func (d DiagnosticLevel) String() string
String implements fmt.Stringer
type Diagnostics ¶
type Diagnostics interface { // Slice returns the list of the diagnostic. Slice() []Diagnostic }
Diagnostics holds the set of the linter diagnostic.
type PromQLinter ¶
type PromQLinter struct {
// contains filtered or unexported fields
}
PromQLinter is the actual PromQL linter. users can configure this struct for controlling the behaviors of the linter.
func (*PromQLinter) Execute ¶
func (pq *PromQLinter) Execute( rawExpr string, filter DiagnosticLevel, ) (bool, error)
Execute starts the lint process. the rawExpr parameter is a PromQL expression. filter determines whether the reported diagnostics from plugin(s) are ignored.
type PromQLinterOption ¶
type PromQLinterOption func(*PromQLinter)
PromQLinterOption enables the initialization of the PromQLinter by FOP(Functional-Options-Pattern)
func WithANSIColored ¶ added in v0.1.2
func WithANSIColored(colored bool) PromQLinterOption
WithANSIColored sets the colored flag to the linter.
func WithOutStream ¶
func WithOutStream(out io.Writer) PromQLinterOption
WithOutStream sets the output stream to the linter.
func WithPlugin ¶
func WithPlugin(plugin PromQLinterPlugin) PromQLinterOption
WithPlugins appends the given plugin to the linter plugins.
func WithPlugins ¶
func WithPlugins(plugins ...PromQLinterPlugin) PromQLinterOption
WithPlugins sets the set of the linter plugin to the linter. Note that this function should be called before WithPlugin(). Because this function updates the plugin set entirely.
type PromQLinterPlugin ¶
type PromQLinterPlugin interface { // Name represents the name of the plugin. // the name is used in the reporting message from the linter. Name() string // Execute lints the PromQL expression. Execute(expr parser.Expr) (Diagnostics, error) }
PromQLinterPlugin is an interface that all linter plugin must implement.