Documentation ¶
Overview ¶
Package linter handles logic around linting schemas and returning results.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCommandOptions ¶
AddCommandOptions adds linting-related mybase options to the supplied mybase.Command.
func RegisterProblem ¶
RegisterProblem adds a new named problem, along with its detector function.
Types ¶
type Annotation ¶
type Annotation struct { Statement *fs.Statement LineOffset int Summary string Message string Problem string }
Annotation is an error, warning, or notice from linting a single SQL statement.
func (*Annotation) LineNo ¶ added in v1.2.3
func (a *Annotation) LineNo() int
LineNo returns the line number of the annotation within its file.
func (*Annotation) Location ¶ added in v1.2.3
func (a *Annotation) Location() string
Location returns information on which file and line caused the Annotation to be generated. This may include character number also, if available.
func (*Annotation) MessageWithLocation ¶
func (a *Annotation) MessageWithLocation() string
MessageWithLocation prepends statement location information to a.Message, if location information is available. Otherwise, it appends the full SQL statement that the message refers to.
type ConfigError ¶
type ConfigError string
ConfigError represents a configuration problem encountered at runtime.
func (ConfigError) Error ¶
func (ce ConfigError) Error() string
Error satisfies the builtin error interface.
type Detector ¶
type Detector func(*tengo.Schema, *fs.LogicalSchema, Options) []*Annotation
A Detector function analyzes a schema for a particular problem, returning annotations for cases of the problem found.
type Options ¶
type Options struct { ProblemSeverity map[string]Severity AllowedCharSets []string AllowedEngines []string IgnoreSchema *regexp.Regexp IgnoreTable *regexp.Regexp }
Options contains parsed settings controlling linter behavior.
func OptionsForDir ¶
OptionsForDir returns Options based on the configuration in an fs.Dir, effectively converting between mybase options and linter options.
type Result ¶
type Result struct { Errors []*Annotation // "Errors" in the linting sense, not in the Golang sense Warnings []*Annotation FormatNotices []*Annotation DebugLogs []string Exceptions []error Schemas map[string]*tengo.Schema // Keyed by dir path and optionally schema name }
Result is a combined set of linter annotations and/or Golang errors found when linting a directory and its subdirs.
func BadConfigResult ¶
BadConfigResult returns a *Result containing a single ConfigError in the Exceptions field. The supplied err will be converted to a ConfigError if it is not already one.
func ExecLogicalSchema ¶
func ExecLogicalSchema(logicalSchema *fs.LogicalSchema, wsOpts workspace.Options, opts Options) (*tengo.Schema, *Result)
ExecLogicalSchema is a wrapper around workspace.ExecLogicalSchema. After the tengo.Schema is obtained and introspected, it is also linted. Any errors are captured as part of the *Result. However, the schema itself is not yet placed into the *Result; this is the caller's responsibility.
func LintDir ¶
LintDir lints all logical schemas in dir, returning a combined result. Does not recurse into subdirs.
func (*Result) SortByFile ¶ added in v1.2.3
func (r *Result) SortByFile()
SortByFile sorts the error, warning and format notice messages according to the filenames they appear relate to.