Skip to content

Commit

Permalink
Merge branch 'summary-mode' into 'master'
Browse files Browse the repository at this point in the history
main: add summary mode

See merge request greut/eclint!4
  • Loading branch information
greut committed Nov 12, 2019
2 parents cec60ee + d0fd5ac commit ddcae23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ $ eclint -exclude "testdata/**/*"
- `-exclude` to filter out some files
- unset / alter properties via the `eclint_` prefix
- [Docker images](https://hub.docker.com/r/greut/eclint)
- colored output _à la_ ripgrep
- colored output _à la_ ripgrep (use `-no_colors` to disable)
- `-summary` mode showing only the number of errors per file
- only the X first errors are shown (use `-show_all_errors` to disable)

## Missing features

Expand Down
35 changes: 26 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ func main() {

exclude := ""
noColors := false
summary := false
showAllErrors := false
showErrorQuantity := 10

klog.InitFlags(nil)
flag.BoolVar(&flagVersion, "version", false, "print the version number")
flag.BoolVar(&noColors, "no-colors", false, "enable or disable colors")
flag.BoolVar(&noColors, "no_colors", false, "enable or disable colors")
flag.BoolVar(&summary, "summary", false, "enable the summary view")
flag.BoolVar(&showAllErrors, "show_all_errors", false, fmt.Sprintf("display all errors for each file (otherwise %d are kept)", showErrorQuantity))
flag.StringVar(&exclude, "exclude", "", "paths to exclude")
flag.Parse()

Expand Down Expand Up @@ -126,29 +131,41 @@ func main() {
errs := lint(filename, log)
for _, err := range errs {
if err != nil {
if d == 0 {
if d == 0 && !summary {
fmt.Fprintf(stdout, "%s:\n", au.Magenta(filename))
}

if ve, ok := err.(validationError); ok {
log.V(4).Info("lint error", "error", ve)
fmt.Fprintf(stdout, "%s:%s: %s\n", au.Green(strconv.Itoa(ve.index)), au.Green(strconv.Itoa(ve.position)), ve.error)
l, err := errorAt(au, ve.line, ve.position-1)
if err != nil {
log.Error(err, "line formating failure", "error", ve)
continue
if !summary {
fmt.Fprintf(stdout, "%s:%s: %s\n", au.Green(strconv.Itoa(ve.index)), au.Green(strconv.Itoa(ve.position)), ve.error)
l, err := errorAt(au, ve.line, ve.position-1)
if err != nil {
log.Error(err, "line formating failure", "error", ve)
continue
}
fmt.Fprintln(stdout, l)
}
fmt.Fprintln(stdout, l)
} else {
log.V(4).Info("lint error", "filename", filename, "error", err)
fmt.Fprintln(stdout, err)
}

if d >= showErrorQuantity && len(errs) > d {
fmt.Fprintln(stdout, fmt.Sprintf(" ... skipping at most %s errors", au.BrightRed(strconv.Itoa(len(errs)-d))))
break
}

d++
c++
}
}
if d > 0 {
fmt.Fprintln(stdout, "")
if !summary {
fmt.Fprintln(stdout, "")
} else {
fmt.Fprintf(stdout, "%s: %d errors\n", au.Magenta(filename), d)
}
}
}
if c > 0 {
Expand Down
2 changes: 1 addition & 1 deletion validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func indentStyle(style string, size int, data []byte) error {
}
if data[i] == x {
return validationError{
error: fmt.Sprintf("indentation style mismatch expected %s", style),
error: fmt.Sprintf("indentation style mismatch expected %q (%s) got %q", c, style, x),
position: i + 1,
}
}
Expand Down

0 comments on commit ddcae23

Please sign in to comment.