toolshonnef.co/go/tools/stylecheck Index | Files

package stylecheck

import "honnef.co/go/tools/stylecheck"

Package stylecheck contains analyzes that enforce style rules. Most of the recommendations made are universally agreed upon by the wider Go community. Some analyzes, however, implement stricter rules that not everyone will agree with. In the context of Staticcheck, these analyzes are not enabled by default.

For the most part it is recommended to follow the advice given by the analyzers that are enabled by default, but you may want to disable additional analyzes on a case by case basis.

Index

Variables

var Analyzers = lint.InitializeAnalyzers(Docs, map[string]*analysis.Analyzer{
	"ST1000": {
		Run: CheckPackageComment,
	},
	"ST1001": {
		Run:      CheckDotImports,
		Requires: []*analysis.Analyzer{facts.Generated, config.Analyzer},
	},
	"ST1003": {
		Run:      CheckNames,
		Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated, config.Analyzer},
	},
	"ST1005": {
		Run:      CheckErrorStrings,
		Requires: []*analysis.Analyzer{buildir.Analyzer},
	},
	"ST1006": {
		Run:      CheckReceiverNames,
		Requires: []*analysis.Analyzer{buildir.Analyzer, facts.Generated},
	},
	"ST1008": {
		Run:      CheckErrorReturn,
		Requires: []*analysis.Analyzer{buildir.Analyzer},
	},
	"ST1011": {
		Run:      CheckTimeNames,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"ST1012": {
		Run: CheckErrorVarNames,
	},
	"ST1013": {
		Run: CheckHTTPStatusCodes,

		Requires: []*analysis.Analyzer{facts.Generated, facts.TokenFile, config.Analyzer, inspect.Analyzer},
	},
	"ST1015": {
		Run:      CheckDefaultCaseOrder,
		Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated, facts.TokenFile},
	},
	"ST1016": {
		Run:      CheckReceiverNamesIdentical,
		Requires: []*analysis.Analyzer{buildir.Analyzer, facts.Generated},
	},
	"ST1017": {
		Run:      CheckYodaConditions,
		Requires: []*analysis.Analyzer{inspect.Analyzer, facts.Generated, facts.TokenFile},
	},
	"ST1018": {
		Run:      CheckInvisibleCharacters,
		Requires: []*analysis.Analyzer{inspect.Analyzer},
	},
	"ST1019": {
		Run:      CheckDuplicatedImports,
		Requires: []*analysis.Analyzer{facts.Generated},
	},
	"ST1020": {
		Run:      CheckExportedFunctionDocs,
		Requires: []*analysis.Analyzer{facts.Generated, inspect.Analyzer},
	},
	"ST1021": {
		Run:      CheckExportedTypeDocs,
		Requires: []*analysis.Analyzer{facts.Generated, inspect.Analyzer},
	},
	"ST1022": {
		Run:      CheckExportedVarDocs,
		Requires: []*analysis.Analyzer{facts.Generated, inspect.Analyzer},
	},
	"ST1023": sharedcheck.RedundantTypeInDeclarationChecker("should", false),
})
var Docs = lint.Markdownify(map[string]*lint.RawDocumentation{
	"ST1000": {
		Title: `Incorrect or missing package comment`,
		Text:  "" /* 167 byte string literal not displayed */,

		Since:      "2019.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAny,
	},

	"ST1001": {
		Title: `Dot imports are discouraged`,
		Text:  "" /* 902 byte string literal not displayed */,

		Since:   "2019.1",
		Options: []string{"dot_import_whitelist"},
		MergeIf: lint.MergeIfAny,
	},

	"ST1003": {
		Title: `Poorly chosen identifier`,
		Text:  "" /* 359 byte string literal not displayed */,

		Since:      "2019.1",
		NonDefault: true,
		Options:    []string{"initialisms"},
		MergeIf:    lint.MergeIfAny,
	},

	"ST1005": {
		Title: `Incorrectly formatted error string`,
		Text:  "" /* 497 byte string literal not displayed */,

		Since:   "2019.1",
		MergeIf: lint.MergeIfAny,
	},

	"ST1006": {
		Title: `Poorly chosen receiver name`,
		Text:  "" /* 727 byte string literal not displayed */,

		Since:   "2019.1",
		MergeIf: lint.MergeIfAny,
	},

	"ST1008": {
		Title:   `A function's error value should be its last return value`,
		Text:    `A function's error value should be its last return value.`,
		Since:   `2019.1`,
		MergeIf: lint.MergeIfAny,
	},

	"ST1011": {
		Title: `Poorly chosen name for variable of type \'time.Duration\'`,
		Text:  "" /* 304 byte string literal not displayed */,

		Since:   `2019.1`,
		MergeIf: lint.MergeIfAny,
	},

	"ST1012": {
		Title: `Poorly chosen name for error variable`,
		Text: `Error variables that are part of an API should be called \'errFoo\' or
\'ErrFoo\'.`,
		Since:   "2019.1",
		MergeIf: lint.MergeIfAny,
	},

	"ST1013": {
		Title: `Should use constants for HTTP error codes, not magic numbers`,
		Text:  "" /* 363 byte string literal not displayed */,

		Since:   "2019.1",
		Options: []string{"http_status_code_whitelist"},
		MergeIf: lint.MergeIfAny,
	},

	"ST1015": {
		Title:   `A switch's default case should be the first or last case`,
		Since:   "2019.1",
		MergeIf: lint.MergeIfAny,
	},

	"ST1016": {
		Title:      `Use consistent method receiver names`,
		Since:      "2019.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAny,
	},

	"ST1017": {
		Title: `Don't use Yoda conditions`,
		Text:  "" /* 330 byte string literal not displayed */,

		Since:   "2019.2",
		MergeIf: lint.MergeIfAny,
	},

	"ST1018": {
		Title:   `Avoid zero-width and control characters in string literals`,
		Since:   "2019.2",
		MergeIf: lint.MergeIfAny,
	},

	"ST1019": {
		Title: `Importing the same package multiple times`,
		Text:  "" /* 713 byte string literal not displayed */,

		Since:   "2020.1",
		MergeIf: lint.MergeIfAny,
	},

	"ST1020": {
		Title: "The documentation of an exported function should start with the function's name",
		Text:  "" /* 466 byte string literal not displayed */,

		Since:      "2020.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAny,
	},

	"ST1021": {
		Title: "The documentation of an exported type should start with type's name",
		Text:  "" /* 466 byte string literal not displayed */,

		Since:      "2020.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAny,
	},

	"ST1022": {
		Title: "The documentation of an exported variable or constant should start with variable's name",
		Text:  "" /* 466 byte string literal not displayed */,

		Since:      "2020.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAny,
	},

	"ST1023": {
		Title:      "Redundant type in variable declaration",
		Since:      "2021.1",
		NonDefault: true,
		MergeIf:    lint.MergeIfAll,
	},
})

Functions

func CheckBlankImports

func CheckBlankImports(pass *analysis.Pass) (interface{}, error)

func CheckContextFirstArg

func CheckContextFirstArg(pass *analysis.Pass) (interface{}, error)

func CheckDefaultCaseOrder

func CheckDefaultCaseOrder(pass *analysis.Pass) (interface{}, error)

func CheckDotImports

func CheckDotImports(pass *analysis.Pass) (interface{}, error)

func CheckDuplicatedImports

func CheckDuplicatedImports(pass *analysis.Pass) (interface{}, error)

func CheckErrorReturn

func CheckErrorReturn(pass *analysis.Pass) (interface{}, error)

func CheckErrorStrings

func CheckErrorStrings(pass *analysis.Pass) (interface{}, error)

func CheckErrorVarNames

func CheckErrorVarNames(pass *analysis.Pass) (interface{}, error)

func CheckExportedFunctionDocs

func CheckExportedFunctionDocs(pass *analysis.Pass) (interface{}, error)

func CheckExportedTypeDocs

func CheckExportedTypeDocs(pass *analysis.Pass) (interface{}, error)

func CheckExportedVarDocs

func CheckExportedVarDocs(pass *analysis.Pass) (interface{}, error)

func CheckHTTPStatusCodes

func CheckHTTPStatusCodes(pass *analysis.Pass) (interface{}, error)

func CheckIncDec

func CheckIncDec(pass *analysis.Pass) (interface{}, error)

func CheckInvisibleCharacters

func CheckInvisibleCharacters(pass *analysis.Pass) (interface{}, error)

func CheckNames

func CheckNames(pass *analysis.Pass) (interface{}, error)

func CheckPackageComment

func CheckPackageComment(pass *analysis.Pass) (interface{}, error)

func CheckReceiverNames

func CheckReceiverNames(pass *analysis.Pass) (interface{}, error)

func CheckReceiverNamesIdentical

func CheckReceiverNamesIdentical(pass *analysis.Pass) (interface{}, error)

func CheckTimeNames

func CheckTimeNames(pass *analysis.Pass) (interface{}, error)

func CheckUnexportedReturn

func CheckUnexportedReturn(pass *analysis.Pass) (interface{}, error)

CheckUnexportedReturn checks that exported functions on exported types do not return unexported types.

func CheckYodaConditions

func CheckYodaConditions(pass *analysis.Pass) (interface{}, error)

Source Files

analysis.go doc.go lint.go names.go

Version
v0.4.0-0.dev
Published
Mar 30, 2022
Platform
js/wasm
Imports
27 packages
Last checked
1 minute ago

Tools for package owners.