config

package
v0.0.0-...-ba14292 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 14

Documentation

Overview

Package config implements the configurations for NilAway.

Index

Constants

View Source
const (
	// PrettyPrintFlag is the flag for pretty printing the error messages.
	PrettyPrintFlag = "pretty-print"
	// GroupErrorMessagesFlag is the flag for grouping similar error messages.
	GroupErrorMessagesFlag = "group-error-messages"
	// IncludePkgsFlag is the flag name for include package prefixes.
	IncludePkgsFlag = "include-pkgs"
	// ExcludePkgsFlag is the flag name for exclude package prefixes.
	ExcludePkgsFlag = "exclude-pkgs"
	// ExcludeFileDocStringsFlag is the flag name for the docstrings that exclude files from analysis.
	ExcludeFileDocStringsFlag = "exclude-file-docstrings"
	// ExperimentalStructInitEnableFlag is the flag name for the experimental struct init support.
	ExperimentalStructInitEnableFlag = "experimental-struct-init"
	// ExperimentalAnonymousFunctionFlag is the flag name for the experimental anonymous function support.
	ExperimentalAnonymousFunctionFlag = "experimental-anonymous-function"
)
View Source
const DirLevelsToPrintForTriggers = 1

DirLevelsToPrintForTriggers controls the number of enclosing directories to print when referring to the locations that triggered errors - right now it seems as if 1 is sufficient disambiguation, but feel free to increase.

View Source
const NilAwayNoInferString = "<nilaway no inference>"

NilAwayNoInferString is the string that may be inserted into the docstring for a package to prevent NilAway from inferring the annotations for that package - this is useful for unit tests

View Source
const NilAwayPkgPathPrefix = uberPkgPathPrefix + "/nilaway"

NilAwayPkgPathPrefix is the package prefix for NilAway.

View Source
const StableRoundLimit = 5

StableRoundLimit is the number of rounds in backpropagation algorithm after which, if there is no change in the collected triggers, the algorithm halts. It is possible to carefully craft known false negative for any value of StableRoundLimit (check test loopflow.go/longRotNilLoop). Setting this value too low may result in false negatives going undetected, while setting it too high may lead to longer analysis times without significant precision gains. In practice, a value of StableRoundLimit >= 2 has shown to provide sound analysis, capturing most false negatives. After experimentation, we observed that using StableRoundLimit = 5 with NilAway yields similar analysis time compared to lower values, making it a good compromise for precise results.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:       "nilaway_config",
	Doc:        _doc,
	Run:        run,
	Flags:      newFlagSet(),
	ResultType: reflect.TypeOf((*Config)(nil)),
}

Analyzer is the pseudo-analyzer that takes the flags and share them among the sub-analyzers of NilAway. All sub-analyzers have to depend on this analyzer to get the flags.

This is required due to our multi-sub-analyzer architecture in NilAway: by the time the top-level analyzer is run, the analysis is already done (by the sub-analyzers), hence the flags controlling the analysis behaviors will be meaningless. Instead, we add this pseudo-analyzer to run first (since all sub-analyzers will depend on it), and make the flags available via its return value.

Unfortunately, this also means for some analyzer drivers (such as nogo), flags will have to be specified for this pseudo-analyzer ("nilaway_config"), and the error suppression lists will have to be specified for the top-level analyzer ("nilaway") since that is the one that outputs errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	// PrettyPrint indicates whether the error messages should be pretty printed.
	PrettyPrint bool
	// GroupErrorMessages indicates whether similar error messages should be grouped.
	GroupErrorMessages bool
	// ExperimentalStructInitEnable indicates whether experimental struct initialization is enabled.
	ExperimentalStructInitEnable bool
	// ExperimentalAnonymousFuncEnable indicates whether experimental anonymous function support is enabled.
	ExperimentalAnonymousFuncEnable bool
	// contains filtered or unexported fields
}

Config is the struct that stores the user-configurable options for NilAway.

func (*Config) IsFileInScope

func (c *Config) IsFileInScope(file *ast.File) bool

IsFileInScope returns true iff we should analyze the file. It checks the docstring of the file and returns false if any of the strings in ExcludeFileDocStrings appear in the file docstring.

func (*Config) IsPkgInScope

func (c *Config) IsPkgInScope(pkg *types.Package) bool

IsPkgInScope returns true iff the passed package is in scope for analysis, i.e., it is in the configured include list but not in the exclude list.

Jump to

Keyboard shortcuts

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