config

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigName = "staticcheck.conf"

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "config",
	Doc:  "loads configuration for the current package tree",
	Run: func(pass *analysis.Pass) (interface{}, error) {
		dir := dirAST(pass.Files, pass.Fset)
		if dir == "" {
			cfg := DefaultConfig
			return &cfg, nil
		}
		cfg, err := Load(dir)
		if err != nil {
			return nil, fmt.Errorf("error loading staticcheck.conf: %s", err)
		}
		return &cfg, nil
	},
	RunDespiteErrors: true,
	ResultType:       reflect.TypeOf((*Config)(nil)),
}
View Source
var DefaultConfig = Config{
	Checks: []string{"all"},
	Initialisms: []string{
		"ACL", "API", "ASCII", "CPU", "CSS", "DNS",
		"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
		"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
		"SMTP", "SQL", "SSH", "TCP", "TLS", "TTL",
		"UDP", "UI", "GID", "UID", "UUID", "URI",
		"URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
		"XSS", "SIP", "RTP", "AMQP", "DB", "TS",
	},
	DotImportWhitelist: []string{
		"github.com/mmcloughlin/avo/build",
		"github.com/mmcloughlin/avo/operand",
		"github.com/mmcloughlin/avo/reg",
	},
	HTTPStatusCodeWhitelist: []string{"200", "400", "404", "500"},
}

DefaultConfig is the default configuration. Its initial value describes the majority of the default configuration, but the Checks field can be updated at runtime based on the analyzers being used, to disable non-default checks. For cmd/staticcheck, this is handled by (*lintcmd.Command).Run.

Note that DefaultConfig shouldn't be modified while analyzers are executing.

Functions

func Dir

func Dir(files []string) string

Dir looks at a list of absolute file names, which should make up a single package, and returns the path of the directory that may contain a staticcheck.conf file. It returns the empty string if no such directory could be determined, for example because all files were located in Go's build cache.

Types

type Config

type Config struct {
	Checks                  []string `toml:"checks"`
	Initialisms             []string `toml:"initialisms"`
	DotImportWhitelist      []string `toml:"dot_import_whitelist"`
	HTTPStatusCodeWhitelist []string `toml:"http_status_code_whitelist"`
}

func For

func For(pass *analysis.Pass) *Config

func Load

func Load(dir string) (Config, error)

func (Config) Merge

func (cfg Config) Merge(ocfg Config) Config

func (Config) String

func (c Config) String() string

type ParseError

type ParseError struct {
	Filename string
	toml.ParseError
}

Jump to

Keyboard shortcuts

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