From eb804a2dd67e4f19839e1d838860249cee7bc20e Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Mon, 17 Jul 2023 14:26:19 +0100 Subject: [PATCH] following `gofmt -s` --- examples/syncat.go | 12 ++++++------ ftdetect.go | 6 +++--- highlighter.go | 41 ++++++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/examples/syncat.go b/examples/syncat.go index c076dc9..3b2804e 100644 --- a/examples/syncat.go +++ b/examples/syncat.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" "io/ioutil" + "log" "os" "strings" - "log" "github.com/fatih/color" "github.com/jessp01/highlight" @@ -22,16 +22,16 @@ func main() { var syn_dir string if gopath == "" { - syn_dir = "/etc/highlight" - }else{ - syn_dir = gopath + "/src/github.com/jessp01/highlight/syntax_files" + syn_dir = "/etc/highlight" + } else { + syn_dir = gopath + "/src/github.com/jessp01/highlight/syntax_files" } syn_dir = os.Getenv("SYNDIR") var defs []*highlight.Def - err := highlight.ParseSyntaxFiles (syn_dir, &defs) + err := highlight.ParseSyntaxFiles(syn_dir, &defs) if err != nil { - log.Fatal(err) + log.Fatal(err) } highlight.ResolveIncludes(defs) diff --git a/ftdetect.go b/ftdetect.go index 80ad807..e04130f 100644 --- a/ftdetect.go +++ b/ftdetect.go @@ -9,9 +9,9 @@ func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def { return d } if len(d.ftdetect) > 1 { - if d.ftdetect[1].MatchString(string(firstLine)) { - return d - } + if d.ftdetect[1].MatchString(string(firstLine)) { + return d + } } } diff --git a/highlighter.go b/highlighter.go index 1f93403..d83c520 100644 --- a/highlighter.go +++ b/highlighter.go @@ -1,11 +1,11 @@ package highlight import ( + "io/ioutil" + "path/filepath" "regexp" "strings" "unicode/utf8" - "path/filepath" - "io/ioutil" ) // RunePos returns the rune index of a given byte index @@ -62,27 +62,27 @@ func NewHighlighter(def *Def) *Highlighter { // color's group (represented as one byte) type LineMatch map[int]Group -func ParseSyntaxFiles (dir string, defs *[]*Def) error{ - pattern := "*.yaml" - files, err := filepath.Glob(dir + "/" + pattern) - if err != nil { - return err - } - - for _, file_path := range(files){ - file, err := ioutil.ReadFile(file_path) +func ParseSyntaxFiles(dir string, defs *[]*Def) error { + pattern := "*.yaml" + files, err := filepath.Glob(dir + "/" + pattern) if err != nil { return err } - d, err := ParseDef(file) - if err != nil { - return err - continue + for _, file_path := range files { + file, err := ioutil.ReadFile(file_path) + if err != nil { + return err + } + + d, err := ParseDef(file) + if err != nil { + return err + continue + } + *defs = append(*defs, d) } - *defs = append(*defs, d) - } - return nil + return nil } func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int { @@ -225,9 +225,8 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canMatchEnd bool, lineNum int, line []rune, statesOnly bool) LineMatch { if h.Def.rules == nil { - return nil - } - + return nil + } if len(line) == 0 { if canMatchEnd {