linter

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColoredErrorDiagnostic added in v0.1.3

func ColoredErrorDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func ColoredInfoDiagnostic added in v0.1.3

func ColoredInfoDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func ColoredWarningDiagnostic added in v0.1.3

func ColoredWarningDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func ErrorDiagnostic added in v0.1.3

func ErrorDiagnostic(
	position parser.PositionRange,
	message string,
	color PromQLinterColorMode,
) *diagnostic

func InfoDiagnostic added in v0.1.3

func InfoDiagnostic(
	position parser.PositionRange,
	message string,
	color PromQLinterColorMode,
) *diagnostic

func NewDiagnostics

func NewDiagnostics() *diagnostics

NewDiagnostics creates a new default Diagnostics.

func NoncoloredErrorDiagnostic added in v0.1.3

func NoncoloredErrorDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func NoncoloredInfoDiagnostic added in v0.1.3

func NoncoloredInfoDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func NoncoloredWarningDiagnostic added in v0.1.3

func NoncoloredWarningDiagnostic(
	position parser.PositionRange,
	message string,
) *diagnostic

func WarningDiagnostic added in v0.1.3

func WarningDiagnostic(
	position parser.PositionRange,
	message string,
	color PromQLinterColorMode,
) *diagnostic

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 PromQLintResult added in v0.1.3

type PromQLintResult uint
const (
	PromQLintResultOK PromQLintResult = iota
	PromQLintResultFailed
)

func (PromQLintResult) Failed added in v0.1.3

func (r PromQLintResult) Failed() bool

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,
) (PromQLintResult, 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 PromQLinterColorMode added in v0.1.3

type PromQLinterColorMode uint
const (
	PromQLinterColorModeEnable PromQLinterColorMode = iota
	PromQLinterColorModeDisable
)

type PromQLinterOption

type PromQLinterOption func(*PromQLinter)

PromQLinterOption enables the initialization of the PromQLinter by FOP(Functional-Options-Pattern)

func WithANSIColorMode added in v0.1.3

func WithANSIColorMode(mode PromQLinterColorMode) PromQLinterOption

WithANSIColorMode sets the color mode 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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