linter

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

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

func AddCommandOptions(cmd *mybase.Command)

AddCommandOptions adds linting-related mybase options to the supplied mybase.Command.

func RegisterProblem

func RegisterProblem(name string, fn Detector)

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

func OptionsForDir(dir *fs.Dir) (Options, error)

OptionsForDir returns Options based on the configuration in an fs.Dir, effectively converting between mybase options and linter options.

func (Options) ShouldIgnore

func (opts Options) ShouldIgnore(key tengo.ObjectKey) bool

ShouldIgnore returns true if the option configuration indicates the supplied tengo.ObjectKey should be ignored.

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

func BadConfigResult(dir *fs.Dir, err error) *Result

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

func LintDir(dir *fs.Dir, wsOpts workspace.Options) *Result

LintDir lints all logical schemas in dir, returning a combined result. Does not recurse into subdirs.

func (*Result) Merge

func (r *Result) Merge(other *Result)

Merge combines other into r's value in-place.

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.

type Severity

type Severity string

Severity represents different annotation severity levels.

const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
)

Constants enumerating valid severity levels

Jump to

Keyboard shortcuts

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