FunctionLengthDocstringThreshold is a limit for a function size (in statements), above which a public function is required to have a docstring.
const FunctionLengthDocstringThreshold = 5
AllWarnings is the list of all available warnings.
var AllWarnings = collectAllWarnings()
DefaultWarnings is the list of all warnings that should be used inside google3
var DefaultWarnings = collectDefaultWarnings()
FileWarningMap lists the warnings that run on the whole file.
var FileWarningMap = map[string]func(f *build.File) []*LinterFinding{ "attr-applicable_licenses": attrApplicableLicensesWarning, "attr-cfg": attrConfigurationWarning, "attr-license": attrLicenseWarning, "attr-licenses": attrLicensesWarning, "attr-non-empty": attrNonEmptyWarning, "attr-output-default": attrOutputDefaultWarning, "attr-single-file": attrSingleFileWarning, "build-args-kwargs": argsKwargsInBuildFilesWarning, "bzl-visibility": bzlVisibilityWarning, "confusing-name": confusingNameWarning, "constant-glob": constantGlobWarning, "ctx-actions": ctxActionsWarning, "ctx-args": contextArgsAPIWarning, "depset-items": depsetItemsWarning, "depset-iteration": depsetIterationWarning, "depset-union": depsetUnionWarning, "dict-method-named-arg": dictMethodNamedArgWarning, "dict-concatenation": dictionaryConcatenationWarning, "duplicated-name": duplicatedNameWarning, "filetype": fileTypeWarning, "function-docstring": functionDocstringWarning, "function-docstring-header": functionDocstringHeaderWarning, "function-docstring-args": functionDocstringArgsWarning, "function-docstring-return": functionDocstringReturnWarning, "git-repository": nativeGitRepositoryWarning, "http-archive": nativeHTTPArchiveWarning, "integer-division": integerDivisionWarning, "keyword-positional-params": keywordPositionalParametersWarning, "list-append": listAppendWarning, "load": unusedLoadWarning, "module-docstring": moduleDocstringWarning, "name-conventions": nameConventionsWarning, "native-android": nativeAndroidRulesWarning, "native-build": nativeInBuildFilesWarning, "native-cc": nativeCcRulesWarning, "native-java": nativeJavaRulesWarning, "native-package": nativePackageWarning, "native-proto": nativeProtoRulesWarning, "native-py": nativePyRulesWarning, "no-effect": noEffectWarning, "output-group": outputGroupWarning, "overly-nested-depset": overlyNestedDepsetWarning, "package-name": packageNameWarning, "package-on-top": packageOnTopWarning, "print": printWarning, "provider-params": providerParamsWarning, "redefined-variable": redefinedVariableWarning, "repository-name": repositoryNameWarning, "rule-impl-return": ruleImplReturnWarning, "return-value": missingReturnValueWarning, "skylark-comment": skylarkCommentWarning, "skylark-docstring": skylarkDocstringWarning, "string-iteration": stringIterationWarning, "uninitialized": uninitializedVariableWarning, "unreachable": unreachableStatementWarning, "unsorted-dict-items": unsortedDictItemsWarning, "unused-variable": unusedVariableWarning, }
MultiFileWarningMap lists the warnings that run on the whole file, but may use other files.
var MultiFileWarningMap = map[string]func(f *build.File, fileReader *FileReader) []*LinterFinding{ "deprecated-function": deprecatedFunctionWarning, "unnamed-macro": unnamedMacroWarning, }
RuleWarningMap lists the warnings that run on a single rule. These warnings run only on BUILD files (not bzl files).
var RuleWarningMap = map[string]func(call *build.CallExpr, pkg string) *LinterFinding{ "positional-args": positionalArgumentsWarning, }
func DetectTypes(f *build.File) map[build.Expr]Type
DetectTypes tries to infer the type of expressions in the current file, using basic heuristics.
Warning: the types inferred by the function might change in the future, as we update the heuristics.
func DisabledWarning(f *build.File, findingLine int, warning string) bool
DisabledWarning checks if the warning was disabled by a comment. The comment format is buildozer: disable=<warning>
func FixWarnings(f *build.File, enabledWarnings []string, verbose bool, fileReader *FileReader)
FixWarnings fixes all warnings that can be fixed automatically.
func HasDisablingComment(expr build.Expr, warning string) bool
HasDisablingComment checks if a node has a comment that disables a certain warning
FileReader is a class that can read an arbitrary Starlark file from the repository and cache the results.
type FileReader struct {
// contains filtered or unexported fields
}
func NewFileReader(readFile func(string) ([]byte, error)) *FileReader
NewFileReader creates and initializes a FileReader instance with a custom readFile function that can read an arbitrary file in the repository using a path relative to the workspace root (OS-independent, with forward slashes).
func (fr *FileReader) GetFile(pkg, label string) *build.File
GetFile reads a Starlark file from the repository or the cache. Returns nil if the file is not found or not valid.
A Finding is a warning reported by the analyzer. It may contain an optional suggested fix.
type Finding struct { File *build.File Start build.Position End build.Position Category string Message string URL string Actionable bool AutoFixable bool Replacement *Replacement }
func FileWarnings(f *build.File, enabledWarnings []string, formatted *[]byte, mode LintMode, fileReader *FileReader) []*Finding
FileWarnings returns a list of all warnings found in the file.
LintMode is an enum representing a linter mode. Can be either "warn", "fix", or "suggest"
type LintMode int
const ( // ModeWarn means only warnings should be returned for each finding. ModeWarn LintMode = iota // ModeFix means that all warnings that can be fixed automatically should be fixed and // no warnings should be returned for them. ModeFix // ModeSuggest means that automatic fixes shouldn't be applied, but instead corresponding // suggestions should be attached to all warnings that can be fixed automatically. ModeSuggest )
LinterFinding is a low-level warning reported by single linter/fixer functions.
type LinterFinding struct { Start build.Position End build.Position Message string URL string Replacement []LinterReplacement }
func NotLoadedFunctionUsageCheck(f *build.File, globals []string, loadFrom string) []*LinterFinding
NotLoadedFunctionUsageCheck checks whether there's a usage of a given not imported function in the file and adds a load statement if necessary.
LinterReplacement is a low-level object returned by single fixer functions.
type LinterReplacement struct { Old *build.Expr New build.Expr }
A Replacement is a suggested fix. Text between Start and End should be replaced with Content.
type Replacement struct { Description string Start int End int Content string }
Type describes an expression type in Starlark.
type Type int
List of known types
const ( Unknown Type = iota Bool Ctx CtxActions CtxActionsArgs Depset Dict Int None String List Float )
func (t Type) String() string