func FindConfigPath(rootDir string) string
FindConfigPath locates the nearest buildifier configuration file. First tries the value of the BUILDIFIER_CONFIG environment variable. If no environment variable is defined, The configuration file will be resolved starting from the process cwd and searching up the file tree until a config file is (or isn't) found.
func ValidateFormat(format, mode *string) error
ValidateFormat validates the value of --format
func ValidateInputType(inputType *string) error
ValidateInputType validates the value of --type
func ValidateModes(mode, lint *string, dflag *bool, additionalModes ...string) error
ValidateModes validates flags --mode, --lint, and -d
func ValidateWarnings(warnings *string, allWarnings, defaultWarnings *[]string) ([]string, error)
ValidateWarnings validates the value of the --warnings flag
ArrayFlags is a string slice that satisfies the flag.Value interface
type ArrayFlags []string
func (i *ArrayFlags) Set(value string) error
Set implements part of the flag.Value interface
func (i *ArrayFlags) String() string
String implements part of the flag.Value interface
Config is used to configure buildifier
type Config struct { // InputType determines the input file type: build (for BUILD files), bzl // (for .bzl files), workspace (for WORKSPACE files), default (for generic // Starlark files), module (for MODULE.bazel files) // or auto (default, based on the filename) InputType string `json:"type,omitempty"` // Format sets the diagnostics format: text or json (default text) Format string `json:"format,omitempty"` // Mode determines the formatting mode: check, diff, or fix (default fix) Mode string `json:"mode,omitempty"` // DiffMode is an alias for DiffMode bool `json:"diffMode,omitempty"` // Lint determines the lint mode: off, warn, or fix (default off) Lint string `json:"lint,omitempty"` // Warnings is a comma-separated list of warning identifiers used in the lint mode or "all" Warnings string `json:"warnings,omitempty"` // WarningsList is a list of warnings (alternative to comma-separated warnings string) WarningsList []string `json:"warningsList,omitempty"` // Recursive instructs buildifier to find starlark files recursively Recursive bool `json:"recursive,omitempty"` // Verbose instructs buildifier to output verbose diagnostics Verbose bool `json:"verbose,omitempty"` // DiffCommand is the command to run when the formatting mode is diff // (default uses the BUILDIFIER_DIFF, BUILDIFIER_MULTIDIFF, and DISPLAY // environment variables to create the diff command) DiffCommand string `json:"diffCommand,omitempty"` // MultiDiff means the command specified by the -diff_command flag can diff // multiple files in the style of tkdiff (default false) MultiDiff bool `json:"multiDiff,omitempty"` // TablesPath is the path to JSON file with custom table definitions that // will replace the built-in tables TablesPath string `json:"tables,omitempty"` // AddTablesPath path to JSON file with custom table definitions which will be merged with the built-in tables AddTablesPath string `json:"addTables,omitempty"` // WorkspaceRelativePath - assume BUILD file has this path relative to the workspace directory WorkspaceRelativePath string `json:"path,omitempty"` // DisableRewrites configures the list of buildifier rewrites to disable DisableRewrites ArrayFlags `json:"buildifier_disable,omitempty"` // AllowSort specifies additional sort contexts to treat as safe AllowSort ArrayFlags `json:"allowsort,omitempty"` // Help is true if the -h flag is set Help bool `json:"-"` // Version is true if the -v flag is set Version bool `json:"-"` // ConfigPath is the path to this config ConfigPath string `json:"-"` // LintWarnings is the final validated list of Lint/Fix warnings LintWarnings []string `json:"-"` }
func Example() *Config
Example creates a sample configuration file for the -config=example flag.
▹ Example
func New() *Config
New constructs a Config with default values.
▹ Example
func (c *Config) FlagSet(name string, errorHandling flag.ErrorHandling) *flag.FlagSet
FlagSet returns a flag.FlagSet that can be used to override the config.
func (c *Config) LoadFile() error
LoadFile unmarshals JSON file from the ConfigPath field.
func (c *Config) LoadReader(in io.Reader) error
LoadReader unmarshals JSON data from the given reader.
func (c *Config) String() string
String renders the config as a formatted JSON string and satisfies the Stringer interface.
func (c *Config) Validate(args []string) error
Validate checks that the input type, format, and lint modes are correctly set. It computes the final set of warnings used for linting. The tables package is configured as a side-effect.