...

Package utils

import "github.com/bazelbuild/buildtools/buildifier/utils"
Overview
Index

Overview ▾

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

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 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

type Diagnostics

Diagnostics contains diagnostic information returned by formatter and linter

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
}

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

FileDiagnostics contains diagnostics information for a file

type FileDiagnostics struct {
    Filename  string     `json:"filename"`
    Formatted bool       `json:"formatted"`
    Valid     bool       `json:"valid"`
    Warnings  []*warning `json:"warnings"`
}

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

type TempFile

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

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

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.