linter

package
v0.0.0-...-cbf15e1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompilationError

type CompilationError struct {
	// Path represents the path to the schema node containing the expression.
	Path *field.Path
	// Message represents the error message generated by CEL..
	Message string
}

CompilationError represents an expression that contained a compile-time error.

func (*CompilationError) Error

func (c *CompilationError) Error() string

func (*CompilationError) MarshalJSON

func (c *CompilationError) MarshalJSON() ([]byte, error)

MarshalJSON returns the CompilationError in JSON format.

type CostError

type CostError struct {
	// Path represents the path to the schema node containing the expression.
	Path *field.Path
	// Cost represents the cost of the expression. This is a unitless value.
	Cost uint64
	// Limit represents the cost limit that was exceeded. This is a unitless value.
	Limit uint64
}

CostError represents an expression whose cost is beyond the per-expression limit.

func (*CostError) Error

func (c *CostError) Error() string

func (*CostError) HumanReadableError

func (c *CostError) HumanReadableError() string

HumanReadableError returns an error message containing the amount by which the expression exceeded the cost limit as a ratio.

func (*CostError) MarshalJSON

func (c *CostError) MarshalJSON() ([]byte, error)

MarshalJSON returns the CostError in JSON format.

type Errors

type Errors struct {
	LimitErrors    []*LimitError
	CostErrors     []*CostError
	CompileErrors  []*CompilationError
	InternalErrors []error
	// contains filtered or unexported fields
}

Errors is meant to track the errors found during a linting pass.

func CheckExprCost

func CheckExprCost(schema *structuralschema.Structural, version *int) *Errors

CheckExprCost checks the given schema for expressions whose estimated cost is greater than the per-expression cost limit. If any compilation errors are encountered during this process, then those are returned as well. The last set of errors returned is for internal errors returned by cel.Compile.

func CheckMaxLimits

func CheckMaxLimits(schema *structuralschema.Structural, version *int) *Errors

CheckMaxLimits takes a schema and returns a list of linter errors for every missing limit that could be set on a list/map/string belonging to that schema or any level beneath it.

func NewLinterErrors

func NewLinterErrors() *Errors

NewLinterErrors returns a new initialized LinterErrors struct.

func (*Errors) AddCompilationErrors

func (l *Errors) AddCompilationErrors(compileErrors []*CompilationError)

AddCompilationErrors adds a list of compilation linter errors.

func (*Errors) AddCostErrors

func (l *Errors) AddCostErrors(costErrors []*CostError)

AddCostErrors adds a list of cost linter errors.

func (*Errors) AddInternalErrors

func (l *Errors) AddInternalErrors(internalErrors []error)

AddInternalErrors adds a list of internal errors.

func (*Errors) AddLimitErrors

func (l *Errors) AddLimitErrors(limitErrors []*LimitError)

AddLimitErrors adds a list of limit linter errors.

func (*Errors) AddLinterErrors

func (l *Errors) AddLinterErrors(otherLinterErrors *Errors)

AddLinterErrors adds all errors from another LinterErrors struct.

func (*Errors) HasErrors

func (l *Errors) HasErrors() bool

HasErrors returns true if a non-zero amount of errors has been added, false otherwise.

func (*Errors) MarshalJSON

func (l *Errors) MarshalJSON() ([]byte, error)

MarshalJSON returns the LinterErrors in JSON format.

type LimitError

type LimitError struct {
	// Path represents the path to the list, map or string without the limit.
	Path *field.Path
	// Type indicates the type of the schema node that caused the error.
	Type SchemaType
}

LimitError represents a list, map, or string that lacks a user-set limit. For lists, this means maxItems has not been set. For maps, this means maxProperties has not been set. And for strings this means maxLength has not been set.

func (*LimitError) Error

func (l *LimitError) Error() string

func (*LimitError) MarshalJSON

func (l *LimitError) MarshalJSON() ([]byte, error)

MarshalJSON returns the LimitError in JSON format.

type SchemaType

type SchemaType int

SchemaType represents an array, map or string as used by LimitError.

const (
	// SchemaTypeArray represents an array as used by LimitError.
	SchemaTypeArray SchemaType = iota
	// SchemaTypeObject represents an object with additionalProperties
	// as used by LimitError.
	SchemaTypeObject
	// SchemaTypeString represents a string as used by LimitError.
	SchemaTypeString
)

Jump to

Keyboard shortcuts

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