Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

    Engine is the main ruleguard package API object.

    First, load some ruleguard files with Load() to build a rule set. Then use Run() to execute the rules.

    It's advised to have only 1 engine per application as it does a lot of caching. The Run() method is synchronized, so it can be used concurrently.

    An Engine must be created with NewEngine() function.

    func NewEngine

    func NewEngine() *Engine

      NewEngine creates an engine with empty rule set.

      func (*Engine) Load

      func (e *Engine) Load(ctx *ParseContext, filename string, r io.Reader) error

        Load reads a ruleguard file from r and adds it to the engine rule set.

        Load() is not thread-safe, especially if used concurrently with Run() method. It's advised to Load() all ruleguard files under a critical section (like sync.Once) and then use Run() to execute all of them.

        func (*Engine) LoadedGroups

        func (e *Engine) LoadedGroups() []GoRuleGroup

          LoadedGroups returns information about all currently loaded rule groups.

          func (*Engine) Run

          func (e *Engine) Run(ctx *RunContext, f *ast.File) error

            Run executes all loaded rules on a given file. Matched rules invoke `RunContext.Report()` method.

            Run() is thread-safe, unless used in parallel with Load(), which modifies the engine state.

            type GoRuleGroup

            type GoRuleGroup struct {
            	// Name is a function name associated with this rule group.
            	Name string
            
            	// Pos is a location where this rule group was defined.
            	Pos token.Position
            
            	// Line is a source code line number inside associated file.
            	// A pair of Filename:Line form a conventional location string.
            	Line int
            
            	// Filename is a file that defined this rule group.
            	Filename string
            
            	// DocTags contains a list of keys from the `gorules:tags` comment.
            	DocTags []string
            
            	// DocSummary is a short one sentence description.
            	// Filled from the `doc:summary` pragma content.
            	DocSummary string
            
            	// DocBefore is a code snippet of code that will violate rule.
            	// Filled from the `doc:before` pragma content.
            	DocBefore string
            
            	// DocAfter is a code snippet of fixed code that complies to the rule.
            	// Filled from the `doc:after` pragma content.
            	DocAfter string
            
            	// DocNote is an optional caution message or advice.
            	// Usually, it's used to reference some external resource, like
            	// issue on the GitHub.
            	// Filled from the `doc:note` pragma content.
            	DocNote string
            }

            type GoRuleInfo

            type GoRuleInfo struct {
            	// Line is a line inside a file that defined this rule.
            	Line int
            
            	// Group is a function that contains this rule.
            	Group *GoRuleGroup
            }

            type ImportError

            type ImportError struct {
            	// contains filtered or unexported fields
            }

              ImportError is returned when a ruleguard file references a package that cannot be imported.

              func (*ImportError) Error

              func (e *ImportError) Error() string

              func (*ImportError) Unwrap

              func (e *ImportError) Unwrap() error

              type ParseContext

              type ParseContext struct {
              	DebugFilter  string
              	DebugImports bool
              	DebugPrint   func(string)
              
              	// GroupFilter is called for every rule group being parsed.
              	// If function returns false, that group will not be included
              	// in the resulting rules set.
              	// Nil filter accepts all rule groups.
              	GroupFilter func(string) bool
              
              	Fset *token.FileSet
              }

              type RunContext

              type RunContext struct {
              	Debug        string
              	DebugImports bool
              	DebugPrint   func(string)
              
              	Types  *types.Info
              	Sizes  types.Sizes
              	Fset   *token.FileSet
              	Report func(rule GoRuleInfo, n ast.Node, msg string, s *Suggestion)
              	Pkg    *types.Package
              }

              type Suggestion

              type Suggestion struct {
              	From        token.Pos
              	To          token.Pos
              	Replacement []byte
              }

              Directories

              Path Synopsis
              Package quasigo implements a Go subset compiler and interpreter.
              Package quasigo implements a Go subset compiler and interpreter.