utils

package
v0.0.0-...-5d63770 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package utils contains shared methods that can be used by different implementations of buildifier binary

Index

Constants

This section is empty.

Variables

This section is empty.

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, lint string, warningsList *[]string, verbose bool) []*warn.Finding

Lint calls the linter and returns a list of unresolved findings

func ValidateFormat

func ValidateFormat(format, mode *string) error

ValidateFormat validates the value of --format

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

Types

type Diagnostics

type Diagnostics struct {
	Success bool               `json:"success"` // overall success (whether all files are formatted properly and have no warnings)
	Files   []*FileDiagnostics `json:"files"`   // diagnostics per file
}

Diagnostics contains diagnostic information returned by formatter and linter

func NewDiagnostics

func NewDiagnostics(fileDiagnostics ...*FileDiagnostics) *Diagnostics

NewDiagnostics returns a new Diagnostics object

func (*Diagnostics) Format

func (d *Diagnostics) Format(format string, verbose bool) string

Format formats a Diagnostics object either as plain text or as json

type FileDiagnostics

type FileDiagnostics struct {
	Filename  string         `json:"filename"`
	Formatted bool           `json:"formatted"`
	Valid     bool           `json:"valid"`
	Warnings  []*warning     `json:"warnings"`
	Rewrites  map[string]int `json:"rewrites,omitempty"`
}

FileDiagnostics contains diagnostics information for a file

func InvalidFileDiagnostics

func InvalidFileDiagnostics(filename string) *FileDiagnostics

InvalidFileDiagnostics returns a new FileDiagnostics object for an invalid file

func NewFileDiagnostics

func NewFileDiagnostics(filename string, warnings []*warn.Finding) *FileDiagnostics

NewFileDiagnostics returns a new FileDiagnostics object

func (*FileDiagnostics) SetRewrites

func (fd *FileDiagnostics) SetRewrites(categories map[string]int)

SetRewrites adds information about rewrites to the diagnostics

type TempFile

type TempFile struct {
	// contains filtered or unexported fields
}

TempFile keeps track of temporary files and cleans them up in the end

func (*TempFile) Clean

func (tf *TempFile) Clean() error

Clean removes all created temporary files

func (*TempFile) WriteTemp

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

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

Jump to

Keyboard shortcuts

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