Documentation
¶
Overview ¶
Package config provides configuration objects for buildifier
Index ¶
- func FindConfigPath(rootDir string) string
- func ValidateFormat(format, mode *string) error
- func ValidateInputType(inputType *string) error
- func ValidateModes(mode, lint *string, dflag *bool, additionalModes ...string) error
- func ValidateWarnings(warnings *string, allWarnings, defaultWarnings *[]string) ([]string, error)
- type ArrayFlags
- type Config
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindConfigPath ¶
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 ¶
ValidateFormat validates the value of --format
func ValidateInputType ¶
ValidateInputType validates the value of --type
func ValidateModes ¶
ValidateModes validates flags --mode, --lint, and -d
Types ¶
type ArrayFlags ¶
type ArrayFlags []string
ArrayFlags is a string slice that satisfies the flag.Value interface
func (*ArrayFlags) Set ¶
func (i *ArrayFlags) Set(value string) error
Set implements part of the flag.Value interface
func (*ArrayFlags) String ¶
func (i *ArrayFlags) String() string
String implements part of the flag.Value interface
type Config ¶
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:"-"`
}
Config is used to configure buildifier
func Example ¶
func Example() *Config
Example creates a sample configuration file for the -config=example flag.
Example ¶
c := Example() fmt.Print(c.String())
Output: { "type": "auto", "mode": "fix", "lint": "fix", "warningsList": [ "attr-applicable_licenses", "attr-cfg", "attr-license", "attr-licenses", "attr-non-empty", "attr-output-default", "attr-single-file", "build-args-kwargs", "bzl-visibility", "canonical-repository", "confusing-name", "constant-glob", "ctx-actions", "ctx-args", "deprecated-function", "depset-items", "depset-iteration", "depset-union", "dict-concatenation", "dict-method-named-arg", "duplicated-name", "external-path", "filetype", "function-docstring", "function-docstring-args", "function-docstring-header", "function-docstring-return", "git-repository", "http-archive", "integer-division", "keyword-positional-params", "list-append", "load", "module-docstring", "name-conventions", "native-android", "native-build", "native-cc-binary", "native-cc-common", "native-cc-debug-package-info", "native-cc-fdo-prefetch-hints", "native-cc-fdo-profile", "native-cc-import", "native-cc-info", "native-cc-library", "native-cc-memprof-profile", "native-cc-objc-import", "native-cc-objc-library", "native-cc-propeller-optimize", "native-cc-proto", "native-cc-shared-library", "native-cc-shared-library-hint-info", "native-cc-shared-library-info", "native-cc-test", "native-cc-toolchain", "native-cc-toolchain-suite", "native-java-binary", "native-java-common", "native-java-import", "native-java-info", "native-java-library", "native-java-lite-proto", "native-java-package-config", "native-java-plugin", "native-java-plugin-info", "native-java-proto", "native-java-runtime", "native-java-test", "native-java-toolchain", "native-package", "native-proto", "native-proto-common", "native-proto-info", "native-proto-lang-toolchain", "native-proto-lang-toolchain-info", "native-py", "native-sh-binary", "native-sh-library", "native-sh-test", "no-effect", "output-group", "overly-nested-depset", "package-name", "package-on-top", "positional-args", "print", "provider-params", "redefined-variable", "repository-name", "return-value", "rule-impl-return", "skylark-comment", "skylark-docstring", "string-iteration", "uninitialized", "unnamed-macro", "unreachable", "unsorted-dict-items", "unused-variable" ] }
func New ¶
func New() *Config
New constructs a Config with default values.
Example ¶
c := New() fmt.Print(c.String())
Output: { "type": "auto" }
func (*Config) LoadReader ¶
LoadReader unmarshals JSON data from the given reader.