linter

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diagnostic

type Diagnostic struct {
	// contains filtered or unexported fields
}

Diagnostic is the detailed message from linter plugin from its rules.

func NewDiagnostic

func NewDiagnostic(
	level DiagnosticLevel,
	position parser.PositionRange,
	message string,
) Diagnostic

NewDiagnostic creates a new diagnostic.

func (*Diagnostic) Report

func (d *Diagnostic) Report(out io.Writer) error

Report outputs the diagnostic message to the given io.Writer.

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 struct {
	// contains filtered or unexported fields
}

Diagnostics holds the set of the linter diagnostic.

func NewDiagnostics

func NewDiagnostics() *Diagnostics

NewDiagnostics creates a new Diagnostics.

func (*Diagnostics) Add

func (ds *Diagnostics) Add(d Diagnostic)

Add appends the given diagnostic to the set.

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 New

func New(options ...PromQLinterOption) *PromQLinter

New creates a new PromQLinter.

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 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL