buildifier

package
v0.0.0-...-03780a1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 5

Documentation

Overview

Package buildifier implements processing of Starlark files via buildifier.

Buildifier is primarily intended for Bazel files. We try to disable as much of Bazel-specific logic as possible, keeping only generally useful Starlark rules.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrActionableFindings is returned by Lint if there are actionable findings.
	ErrActionableFindings = errors.New("some *.star files have linter warnings, please fix them")
)
View Source
var File_lucicfgfmtrc_proto protoreflect.FileDescriptor

Functions

func Visit

func Visit(loader interpreter.Loader, paths []string, v Visitor) errors.MultiError

Visit parses Starlark files using Buildifier and calls the callback for each parsed file, in parallel.

Collects all errors from all callbacks in a single joint multi-error.

Types

type Finding

type Finding struct {
	Path       string    `json:"path"`
	Start      *Position `json:"start,omitempty"`
	End        *Position `json:"end,omitempty"`
	Category   string    `json:"string,omitempty"`
	Message    string    `json:"message,omitempty"`
	Actionable bool      `json:"actionable,omitempty"`
}

Finding is information about one linting or formatting error.

Implements error interface. Non-actionable findings are assumed to be non-blocking errors.

func Lint

func Lint(loader interpreter.Loader, paths []string, lintChecks []string, getRewriterForPath func(path string) (*build.Rewriter, error)) (findings []*Finding, err error)

Lint applies linting and formatting checks to the given files.

getRewriterForPath should return a Rewriter, given the path which needs linting. This will be used to check the 'format' lint check. If getRewriterForPath is nil, we will use vars.GetDefaultRewriter for this.

Returns all findings and a non-nil error (usually a MultiError) if some findings are blocking.

func (*Finding) Error

func (f *Finding) Error() string

Error returns a short summary of the finding.

func (*Finding) Format

func (f *Finding) Format() string

Format returns a detailed reported that can be printed to stderr.

type LucicfgFmtConfig

type LucicfgFmtConfig struct {
	Rules []*LucicfgFmtConfig_Rules `protobuf:"bytes,1,rep,name=rules,proto3" json:"rules,omitempty"`
	// contains filtered or unexported fields
}

func (*LucicfgFmtConfig) Descriptor deprecated

func (*LucicfgFmtConfig) Descriptor() ([]byte, []int)

Deprecated: Use LucicfgFmtConfig.ProtoReflect.Descriptor instead.

func (*LucicfgFmtConfig) GetRules

func (x *LucicfgFmtConfig) GetRules() []*LucicfgFmtConfig_Rules

func (*LucicfgFmtConfig) ProtoMessage

func (*LucicfgFmtConfig) ProtoMessage()

func (*LucicfgFmtConfig) ProtoReflect

func (x *LucicfgFmtConfig) ProtoReflect() protoreflect.Message

func (*LucicfgFmtConfig) Reset

func (x *LucicfgFmtConfig) Reset()

func (*LucicfgFmtConfig) String

func (x *LucicfgFmtConfig) String() string

type LucicfgFmtConfig_Rules

type LucicfgFmtConfig_Rules struct {

	// Forward-slash delimited path prefixes for which this Rules message applies.
	//
	// When loading this config, lucicfg will organize all Rules by path. Rules with
	// duplicate path values are not permitted (i.e. you cannot have two Rules with
	// a path of "something", nor can you have the path "something" duplicated within
	// a single Rules entry).
	//
	// When processing files, lucicfg will calculate the file's path as relative to
	// this .lucicfgfmtrc file, and will select a single Rules set based on the longest
	// matching path prefix. For example, if there are two Rules sets, one formatting
	// "a" and another formatting "a/folder", then for the file "a/folder/file.star",
	// only the second Rules set would apply.
	//
	// If NO Rules set matches the file path, then only default formatting will
	// occur (i.e. lucicfg will only apply formatting which is not controlled by
	// this Rules message. In particular, this means that formatting will not
	// attempt to reorder function call arguments in any way).
	Path []string `protobuf:"bytes,1,rep,name=path,proto3" json:"path,omitempty"`
	// FunctionArgsSort allows you to reorder the arguments at function call sites,
	// based on the name of the arguments.
	//
	// If this is set, then all functions will be sorted first by the order of its
	// `arg` field, and then alphanumerically. This implies that setting this message
	// without setting any `arg` values will sort all function call sites
	// alphabetically.
	//
	// If this message is completely omitted, no call site function argument reordering
	// will occur.
	//
	// The sorting only applies to kwarg-style arguments in files we want to format.
	FunctionArgsSort *LucicfgFmtConfig_Rules_FunctionArgsSort `protobuf:"bytes,2,opt,name=function_args_sort,json=functionArgsSort,proto3" json:"function_args_sort,omitempty"`
	// contains filtered or unexported fields
}

Rules will contain paths that are associated with a specific ordering rule

func (*LucicfgFmtConfig_Rules) Descriptor deprecated

func (*LucicfgFmtConfig_Rules) Descriptor() ([]byte, []int)

Deprecated: Use LucicfgFmtConfig_Rules.ProtoReflect.Descriptor instead.

func (*LucicfgFmtConfig_Rules) GetFunctionArgsSort

func (*LucicfgFmtConfig_Rules) GetPath

func (x *LucicfgFmtConfig_Rules) GetPath() []string

func (*LucicfgFmtConfig_Rules) ProtoMessage

func (*LucicfgFmtConfig_Rules) ProtoMessage()

func (*LucicfgFmtConfig_Rules) ProtoReflect

func (x *LucicfgFmtConfig_Rules) ProtoReflect() protoreflect.Message

func (*LucicfgFmtConfig_Rules) Reset

func (x *LucicfgFmtConfig_Rules) Reset()

func (*LucicfgFmtConfig_Rules) String

func (x *LucicfgFmtConfig_Rules) String() string

type LucicfgFmtConfig_Rules_FunctionArgsSort

type LucicfgFmtConfig_Rules_FunctionArgsSort struct {

	// Argument names in the order they should appear in calls.
	//
	// The ordering of an argument can be specific to a function by
	// specifying the argument name as <function-name>.<arg-name>, where
	// <function-name> is the name used at the callsite. The name the
	// function is defined with is not considered. This means that loading a
	// function with an alias will change which entries apply to calls to the
	// function. When the ordering for an argument is determined, if
	// <function-name>.<arg-name> is present, it will use the relative
	// ordering of that entry to determine the order of the argument in the
	// call. If <function-name>.<arg-name> is not present and <arg-name> is
	// present, it will use the relative ordering of that entry to determine
	// the order of the argument in the call. If neither
	// <function-name>.<arg-name> nor <arg-name> are present, then the
	// argument will appear in lexicographic order after any arguments that
	// are specified in the list.
	Arg []string `protobuf:"bytes,1,rep,name=arg,proto3" json:"arg,omitempty"`
	// contains filtered or unexported fields
}

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) Descriptor deprecated

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) Descriptor() ([]byte, []int)

Deprecated: Use LucicfgFmtConfig_Rules_FunctionArgsSort.ProtoReflect.Descriptor instead.

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) GetArg

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) ProtoMessage

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) ProtoReflect

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) Reset

func (*LucicfgFmtConfig_Rules_FunctionArgsSort) String

type Position

type Position struct {
	Line   int `json:"line"`   // starting from 1
	Column int `json:"column"` // in runes, starting from 1
	Offset int `json:"offset"` // absolute offset in bytes
}

Position indicates a position within a file.

type Visitor

type Visitor func(path string, body []byte, f *build.File) errors.MultiError

Visitor processes a parsed Starlark file, returning all errors encountered when processing it.

Jump to

Keyboard shortcuts

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