fmt

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FmtCommand = &cli.Command{
	Name:  "fmt",
	Usage: "Format build and skylark files",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "mode",
			Usage: `Buildifier mode, one of "check", "diff", "fix", "print_if_changed"`,
			Value: "fix",
		},
		cli.StringFlag{
			Name:  "lint",
			Usage: `lint mode, one of "warn", "fix"`,
			Value: "fix",
		},
		cli.StringSliceFlag{
			Name:  "disable",
			Usage: "Disable rewrites on target",
		},
		cli.StringSliceFlag{
			Name:  "allow_sort",
			Usage: "Allow sorting on target",
		},
		cli.StringSliceFlag{
			Name:  "warning",
			Usage: "Warning flags",
		},
		cli.StringFlag{
			Name:  "type",
			Usage: "Input type (build|workspace|bzl)",
			Value: "build",
		},
		cli.StringFlag{
			Name:  "add_tables",
			Usage: "Path to tables file that will be merged with {SOMETHING}",
			Value: "build",
		},
		cli.BoolFlag{
			Name:  "no_recursive",
			Usage: "Do not process files recursively",
		},
	},
	Action: func(c *cli.Context) error {
		exitCode, err := execute(c)
		if err != nil {
			return cli.NewExitError(stdfmt.Sprintf("fmt failed: %v", err), exitCode)
		}
		return nil
	},
}
View Source
var LintCommand = &cli.Command{
	Name:  "lint",
	Usage: "Lint build and skylark files",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "mode",
			Usage: `Buildifier mode, one of "check", "diff", "fix", "print_if_changed"`,
			Value: "check",
		},
		cli.StringFlag{
			Name:  "lint",
			Usage: `lint mode, one of "warn", "fix"`,
			Value: "warn",
		},
		cli.StringSliceFlag{
			Name:  "disable",
			Usage: "Disable rewrites on target",
		},
		cli.StringSliceFlag{
			Name:  "allow_sort",
			Usage: "Allow sorting on target",
		},
		cli.StringSliceFlag{
			Name:  "warning",
			Usage: "Warning flags",
		},
		cli.StringFlag{
			Name:  "type",
			Usage: "Input type (build|workspace|bzl)",
			Value: "build",
		},
		cli.StringFlag{
			Name:  "add_tables",
			Usage: "Path to tables file that will be merged with {SOMETHING}",
			Value: "build",
		},
		cli.BoolFlag{
			Name:  "no_recursive",
			Usage: "Do not process files recursively",
		},
	},
	Action: func(c *cli.Context) error {
		exitCode, err := execute(c)
		if err != nil {
			return cli.NewExitError(stdfmt.Sprintf("fmt failed: %v", err), exitCode)
		}
		return nil
	},
}

Functions

func ExpandDirectories

func ExpandDirectories(args []string) ([]string, error)

ExpandDirectories takes a list of file/directory names and returns a list with file names by traversing each directory recursively and searching for relevant Starlark files.

func GetPackageName

func GetPackageName(filename string) string

GetPackageName returns the package name of a file by searching for a WORKSPACE file

func GetParser

func GetParser(inputType string) func(filename string, data []byte) (*build.File, error)

GetParser returns a parser for a given file type

func Lint

func Lint(f *build.File, pkg, lint string, warningsList []string, verbose bool) bool

Lint calls the linter and returns true if there are any unresolved warnings

func ValidateInputType

func ValidateInputType(inputType string) error

ValidateInputType validates the value of --type

func ValidateModes

func ValidateModes(mode, lint string, dflag bool, additionalModes ...string) error

ValidateModes validates flags --mode, --lint, and -d

func ValidateWarnings

func ValidateWarnings(warnings string, allWarnings, defaultWarnings *[]string) ([]string, error)

ValidateWarnings validates the value of the --warnings flag

func WriteTemp

func WriteTemp(data []byte) (file string, err error)

WriteTemp writes data to a temporary file and returns the name of the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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