From a98a9da5d7659a61876931719b8c5e4e8b0398f7 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Mon, 24 Jul 2023 22:51:18 +0900 Subject: [PATCH] fix lint warnings --- cmd/gocloc/main.go | 12 ++++++------ file.go | 2 +- language.go | 10 +++++----- utils.go | 10 +++++----- xml.go | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/gocloc/main.go b/cmd/gocloc/main.go index 493607a..684dd13 100644 --- a/cmd/gocloc/main.go +++ b/cmd/gocloc/main.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/hhatto/gocloc" - flags "github.com/jessevdk/go-flags" + "github.com/jessevdk/go-flags" ) // Version is version string for gocloc command @@ -41,7 +41,7 @@ var rowLen = 79 // CmdOptions is gocloc command options. // It is necessary to use notation that follows go-flags. type CmdOptions struct { - Byfile bool `long:"by-file" description:"report results for every encountered source file"` + ByFile bool `long:"by-file" description:"report results for every encountered source file"` SortTag string `long:"sort" default:"code" description:"sort based on a certain column" choice:"name" choice:"files" choice:"blank" choice:"comment" choice:"code"` OutputType string `long:"output-type" default:"default" description:"output type [values: default,cloc-xml,sloccount,json]"` ExcludeExt string `long:"exclude-ext" description:"exclude file name extensions (separated commas)"` @@ -73,7 +73,7 @@ func (o *outputBuilder) WriteHeader() { headerLen := 28 header := languageHeader - if o.opts.Byfile { + if o.opts.ByFile { headerLen = maxPathLen + 1 rowLen = maxPathLen + len(commonHeader) + 2 header = fileHeader @@ -91,7 +91,7 @@ func (o *outputBuilder) WriteFooter() { if o.opts.OutputType == OutputTypeDefault { fmt.Printf("%.[2]*[1]s\n", defaultOutputSeparator, rowLen) - if o.opts.Byfile { + if o.opts.ByFile { fmt.Printf("%-[1]*[2]v %6[3]v %14[4]v %14[5]v %14[6]v\n", maxPathLen, "TOTAL", total.Total, total.Blanks, total.Comments, total.Code) } else { @@ -173,7 +173,7 @@ func (o *outputBuilder) WriteResult() { clocLangs := o.result.Languages total := o.result.Total - if o.opts.Byfile { + if o.opts.ByFile { writeResultWithByFile(o.opts, o.result) } else { var sortedLanguages gocloc.Languages @@ -251,7 +251,7 @@ func main() { } // check sort tag option with other options - if opts.Byfile && opts.SortTag == "files" { + if opts.ByFile && opts.SortTag == "files" { fmt.Println("`--sort files` option cannot be used in conjunction with the `--by-file` option") os.Exit(1) } diff --git a/file.go b/file.go index 3bfebbc..cbdf8d0 100644 --- a/file.go +++ b/file.go @@ -80,7 +80,7 @@ func AnalyzeReader(filename string, language *Language, file io.Reader, opts *Cl } isFirstLine := true - inComments := [][2]string{} + var inComments [][2]string buf := getByteSlice() defer putByteSlice(buf) scanner := bufio.NewScanner(file) diff --git a/language.go b/language.go index d089a00..61c994d 100644 --- a/language.go +++ b/language.go @@ -11,10 +11,10 @@ import ( "strings" "unicode" - enry "github.com/go-enry/go-enry/v2" + "github.com/go-enry/go-enry/v2" ) -// ClocLanguage is provide for xml-cloc and json format. +// ClocLanguage is provided for xml-cloc and json format. type ClocLanguage struct { Name string `xml:"name,attr" json:"name,omitempty"` FilesCount int32 `xml:"files_count,attr" json:"files"` @@ -449,7 +449,7 @@ func NewLanguage(name string, lineComments []string, multiLines [][]string) *Lan } func lang2exts(lang string) (exts string) { - es := []string{} + var es []string for ext, l := range Exts { if lang == l { switch lang { @@ -477,10 +477,10 @@ type DefinedLanguages struct { Langs map[string]*Language } -// GetFormattedString return DefinedLanguages as a human readable string. +// GetFormattedString return DefinedLanguages as a human-readable string. func (langs *DefinedLanguages) GetFormattedString() string { var buf bytes.Buffer - printLangs := []string{} + var printLangs []string for _, lang := range langs.Langs { printLangs = append(printLangs, lang.Name) } diff --git a/utils.go b/utils.go index 5812071..46e2150 100644 --- a/utils.go +++ b/utils.go @@ -20,8 +20,8 @@ func trimBOM(line string) string { } func containsComment(line string, multiLines [][]string) bool { - for _, mlcomm := range multiLines { - for _, comm := range mlcomm { + for _, comments := range multiLines { + for _, comm := range comments { if strings.Contains(line, comm) { return true } @@ -69,11 +69,11 @@ func isVCSDir(path string) bool { func checkDefaultIgnore(path string, info os.FileInfo, isVCS bool) bool { if info.IsDir() { - // directory is ignore + // directory is ignored return true } if !isVCS && isVCSDir(path) { - // vcs file or directory is ignore + // vcs file or directory is ignored return true } @@ -101,7 +101,7 @@ func checkOptionMatch(path string, info os.FileInfo, opts *ClocOptions) bool { return true } -// getAllFiles return all of the files to be analyzed in paths. +// getAllFiles return all the files to be analyzed in paths. func getAllFiles(paths []string, languages *DefinedLanguages, opts *ClocOptions) (result map[string]*Language, err error) { result = make(map[string]*Language, 0) fileCache := make(map[string]struct{}) diff --git a/xml.go b/xml.go index 26058cb..26761e6 100644 --- a/xml.go +++ b/xml.go @@ -58,7 +58,7 @@ func (x *XMLResult) Encode() { } // NewXMLResultFromCloc returns XMLResult with default data set. -func NewXMLResultFromCloc(total *Language, sortedLanguages Languages, option XMLResultType) *XMLResult { +func NewXMLResultFromCloc(total *Language, sortedLanguages Languages, _ XMLResultType) *XMLResult { var langs []ClocLanguage for _, language := range sortedLanguages { c := ClocLanguage{