linter

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACL_SYNTAX                           = "acl/syntax"
	ACL_DUPLICATED                       = "acl/duplicated"
	BACKEND_SYNTAX                       = "backend/syntax"
	BACKEND_DUPLICATED                   = "backend/duplicated"
	BACKEND_NOTFOUND                     = "backend/notfound"
	BACKEND_PROBER_CONFIGURATION         = "backend/prober-configuration"
	DIRECTOR_SYNTAX                      = "director/syntax"
	DIRECTOR_DUPLICATED                  = "director/duplicated"
	DIRECTOR_PROPS_RANDOM                = "director/props-random"
	DIRECTOR_PROPS_FALLBACK              = "director/props-fallback"
	DIRECTOR_PROPS_HASH                  = "director/props-hash"
	DIRECTOR_PROPS_CLIENT                = "director/props-client"
	DIRECTOR_PROPS_CHASH                 = "director/props-chash"
	DIRECTOR_BACKEND_REQUIRED            = "director/backend-required"
	TABLE_SYNTAX                         = "table/syntax"
	TABLE_TYPE_VARIATION                 = "table/type-variation"
	TABLE_ITEM_LIMITATION                = "table/item-limitation"
	TABLE_DUPLICATED                     = "table/duplicated"
	SUBROUTINE_SYNTAX                    = "subroutine/syntax"
	SUBROUTINE_BOILERPLATE_MACRO         = "subroutine/boilerplate-macro"
	SUBROUTINE_DUPLICATED                = "subroutine/duplicated"
	SUBROUTINE_INVALID_RETURN_TYPE       = "subroutine/invalid-return-type"
	PENALTYBOX_SYNTAX                    = "penaltybox/syntax"
	PENALTYBOX_DUPLICATED                = "penaltybox/duplicated"
	PENALTYBOX_NONEMPTY_BLOCK            = "penaltybox/nonempty-block"
	RATECOUNTER_SYNTAX                   = "ratecounter/syntax"
	RATECOUNTER_DUPLICATED               = "ratecounter/duplicated"
	RATECOUNTER_NONEMPTY_BLOCK           = "ratecounter/nonempty-block"
	DECLARE_STATEMENT_SYNTAX             = "declare-statement/syntax"
	DECLARE_STATEMENT_INVALID_TYPE       = "declare-statement/invalid-type"
	DECLARE_STATEMENT_DUPLICATED         = "declare-statement/duplicated"
	SET_STATEMENT_SYNTAX                 = "set-statement/syntax"
	OPERATOR_ASSIGNMENT                  = "operator/assignment"
	UNSET_STATEMENT_SYNTAX               = "unset-statement/syntax"
	REMOVE_STATEMENT_SYNTAX              = "remote-statement/syntax"
	OPERATOR_CONDITIONAL                 = "operator/conditional"
	RESTART_STATEMENT_SCOPE              = "restart-statement/scope"
	ADD_STATEMENT_SYNTAX                 = "add-statement/syntax"
	CALL_STATEMENT_SYNTAX                = "call-statement/syntax"
	CALL_STATEMENT_SUBROUTINE_NOTFOUND   = "call-statement/subroutine-notfound"
	ERROR_STATEMENT_SCOPE                = "error-statement/scope"
	ERROR_STATEMENT_CODE                 = "error-statement/code"
	SYNTHETIC_STATEMENT_SCOPE            = "synthetic-statement/scope"
	SYNTHETIC_BASE64_STATEMENT_SCOPE     = "synthetic-base64-statement/scope"
	CONDITION_LITERAL                    = "condition/literal"
	VALID_IP                             = "valid-ip"
	FUNCTION_ARGUMENTS                   = "function/arguments"
	FUNCTION_ARGUMENT_TYPE               = "function/argument-type"
	INCLUDE_STATEMENT_MODULE_NOT_FOUND   = "include/module-not-found"
	INCLUDE_STATEMENT_MODULE_LOAD_FAILED = "include/module-load-failed"
	REGEX_MATCHED_VALUE_MAY_OVERRIDE     = "regex/matched-value-override"
	UNUSED_DECLARATION                   = "unused/declaration"
	UNUSED_VARIABLE                      = "unused/variable"
)

Variables

View Source
var BackendProbePropertyTypes = map[string]types.Type{
	"dummy":             types.BoolType,
	"request":           types.StringType,
	"expected_response": types.IntegerType,
	"interval":          types.RTimeType,
	"timeout":           types.RTimeType,
	"window":            types.IntegerType,
	"initial":           types.IntegerType,
	"threshold":         types.IntegerType,
}
View Source
var BackendPropertyTypes = map[string]types.Type{
	"dynamic":                types.BoolType,
	"share_key":              types.StringType,
	"host":                   types.StringType,
	"port":                   types.StringType,
	"ssl":                    types.BoolType,
	"ssl_cert_hostname":      types.StringType,
	"max_tls_version":        types.StringType,
	"min_tls_version":        types.StringType,
	"ssl_check_cert":         types.IDType,
	"ssl_sni_hostname":       types.StringType,
	"between_bytes_timeout":  types.RTimeType,
	"connect_timeout":        types.RTimeType,
	"first_byte_timeout":     types.RTimeType,
	"max_connections":        types.IntegerType,
	"host_header":            types.StringType,
	"always_use_host_header": types.BoolType,
}
View Source
var DirectorPropertyTypes = map[string]DirectorProps{
	"random": {
		Rule: DIRECTOR_PROPS_RANDOM,
		Props: map[string]types.Type{
			"retries": types.IntegerType,
			"quorum":  types.StringType,
			"backend": types.BackendType,
			"weight":  types.IntegerType,
		},
		Requires: []string{"weight"},
	},
	"fallback": {
		Rule: DIRECTOR_PROPS_FALLBACK,
		Props: map[string]types.Type{
			"backend": types.BackendType,
		},
		Requires: []string{},
	},
	"hash": {
		Rule: DIRECTOR_PROPS_HASH,
		Props: map[string]types.Type{
			"quorum":  types.StringType,
			"backend": types.BackendType,
			"weight":  types.IntegerType,
		},
		Requires: []string{"weight"},
	},
	"client": {
		Rule: DIRECTOR_PROPS_CLIENT,
		Props: map[string]types.Type{
			"quorum":  types.StringType,
			"backend": types.BackendType,
			"weight":  types.IntegerType,
		},
		Requires: []string{"weight"},
	},
	"chash": {
		Rule: DIRECTOR_PROPS_CHASH,
		Props: map[string]types.Type{
			"key":             types.BackendType,
			"seed":            types.IntegerType,
			"vnodes_per_node": types.IntegerType,
			"quorum":          types.StringType,
			"weight":          types.IntegerType,
			"id":              types.StringType,
		},
		Requires: []string{"id"},
	},
}
View Source
var ValueTypeMap = map[string]types.Type{
	"INTEGER": types.IntegerType,
	"FLOAT":   types.FloatType,
	"BOOL":    types.BoolType,
	"ACL":     types.AclType,
	"BACKEND": types.BackendType,
	"IP":      types.IPType,
	"STRING":  types.StringType,
	"ID":      types.IDType,
	"RTIME":   types.RTimeType,
	"TIME":    types.TimeType,
}

Functions

This section is empty.

Types

type DirectorProps

type DirectorProps struct {
	Rule     Rule
	Props    map[string]types.Type
	Requires []string
}

type LintError

type LintError struct {
	Severity  Severity
	Token     token.Token
	Message   string
	Reference string
	Rule      Rule
}

func AccessDenied added in v0.9.3

func AccessDenied(m *ast.Meta, name, scope string) *LintError

func Duplicated

func Duplicated(m *ast.Meta, name, ident string) *LintError

func ErrorCodeRange

func ErrorCodeRange(m *ast.Meta, code int64) *LintError

func FunctionArgumentMismatch

func FunctionArgumentMismatch(m *ast.Meta, name string, expect, actual int) *LintError

func FunctionArgumentTypeMismatch

func FunctionArgumentTypeMismatch(m *ast.Meta, name string, num int, expect, actual types.Type) *LintError

func ImplicitTypeConversion

func ImplicitTypeConversion(m *ast.Meta, from, to types.Type) *LintError

func InvalidName

func InvalidName(m *ast.Meta, name, ident string) *LintError

func InvalidOperation

func InvalidOperation(m *ast.Meta, name, operation string) *LintError

func InvalidOperator

func InvalidOperator(m *ast.Meta, op string, left types.Type) *LintError

func InvalidReturnState

func InvalidReturnState(m *ast.Meta, scope, state string, expects ...string) *LintError

func InvalidType

func InvalidType(m *ast.Meta, name string, expect, actual types.Type) *LintError

InvalidType raises ERROR due to strict type assertion failed. Actually, it cause compile error for that VCL.

func InvalidTypeComparison

func InvalidTypeComparison(m *ast.Meta, left, right types.Type) *LintError

func InvalidTypeConversion

func InvalidTypeConversion(m *ast.Meta, vclType string) *LintError

func InvalidTypeExpression

func InvalidTypeExpression(m *ast.Meta, actual types.Type, expects ...types.Type) *LintError

func InvalidTypeOperator

func InvalidTypeOperator(m *ast.Meta, op string, left, right types.Type) *LintError

func InvalidValue

func InvalidValue(m *ast.Meta, tt, val string) *LintError

func NonEmptyPenaltyboxBlock added in v0.9.3

func NonEmptyPenaltyboxBlock(m *ast.Meta, name string) *LintError

func NonEmptyRatecounterBlock added in v0.9.3

func NonEmptyRatecounterBlock(m *ast.Meta, name string) *LintError

func NotFunction

func NotFunction(m *ast.Meta, name string) *LintError

func UndefinedAcl

func UndefinedAcl(m *ast.Meta, name string) *LintError

func UndefinedBackend

func UndefinedBackend(m *ast.Meta, name string) *LintError

func UndefinedBackendProperty

func UndefinedBackendProperty(m *ast.Meta, name string) *LintError

func UndefinedDirectorProperty

func UndefinedDirectorProperty(m *ast.Meta, name, dt string) *LintError

func UndefinedFunction

func UndefinedFunction(m *ast.Meta, name string) *LintError

func UndefinedSubroutine

func UndefinedSubroutine(m *ast.Meta, name string) *LintError

func UndefinedTableType

func UndefinedTableType(m *ast.Meta, name, tt string) *LintError

func UndefinedVariable

func UndefinedVariable(m *ast.Meta, name string) *LintError

func UnusedDeclaration added in v0.6.0

func UnusedDeclaration(m *ast.Meta, name, declType string) *LintError

func UnusedVariable added in v0.6.0

func UnusedVariable(m *ast.Meta, name string) *LintError

func (*LintError) Error

func (e *LintError) Error() string

func (*LintError) Match

func (l *LintError) Match(r Rule) *LintError

func (*LintError) Ref

func (e *LintError) Ref(url string) *LintError

type Linter

type Linter struct {
	Errors []error
}

func New

func New() *Linter

func (*Linter) Error

func (l *Linter) Error(err error)

func (*Linter) Lint

func (l *Linter) Lint(node ast.Node, ctx *context.Context, isMain bool) types.Type

Expose lint function to call from external program. It means this method is bootstrap, called only once.

type Rule

type Rule string

func (Rule) Reference

func (r Rule) Reference() string

type Severity

type Severity string
const (
	WARNING Severity = "Warning"
	ERROR   Severity = "Error"
	INFO    Severity = "Info"
	IGNORE  Severity = "Ignore"
)

Jump to

Keyboard shortcuts

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