Skip to content

Commit

Permalink
Include final counts in multiline mint-lint output. (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
doxavore authored Aug 15, 2024
1 parent a04e2a4 commit ac203a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions internal/cli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (s Service) Lint(cfg LintConfig) (*api.LintResult, error) {
case LintOutputOneLine:
err = outputLintOneLine(cfg.Output, sortLintProblems(lintResult.Problems))
case LintOutputMultiLine:
err = outputLintMultiLine(cfg.Output, sortLintProblems(lintResult.Problems))
err = outputLintMultiLine(cfg.Output, sortLintProblems(lintResult.Problems), len(targetPaths))
}
if err != nil {
return nil, errors.Wrap(err, "unable to output lint results")
Expand All @@ -275,12 +275,8 @@ func (s Service) Lint(cfg LintConfig) (*api.LintResult, error) {
return lintResult, nil
}

func outputLintMultiLine(w io.Writer, lintedFiles []api.LintProblem) error {
if len(lintedFiles) == 0 {
return nil
}

for i, lf := range lintedFiles {
func outputLintMultiLine(w io.Writer, problems []api.LintProblem, fileCount int) error {
for i, lf := range problems {
if i > 0 {
fmt.Fprintln(w)
}
Expand All @@ -300,6 +296,13 @@ func outputLintMultiLine(w io.Writer, lintedFiles []api.LintProblem) error {
fmt.Fprintln(w)
}

pluralized := "problems"
if len(problems) == 1 {
pluralized = "problem"
}

fmt.Fprintf(w, "\nChecked %d files and found %d %s.\n", fileCount, len(problems), pluralized)

return nil
}

Expand Down
6 changes: 4 additions & 2 deletions internal/cli/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ advice 1a
mint1.yml:15:4 [error]
message 2
message 2a
Checked 2 files and found 4 problems.
`))
})
})
Expand Down Expand Up @@ -1700,10 +1702,10 @@ message 2a
lintConfig.OutputFormat = cli.LintOutputMultiLine
})

It("doesn't output", func() {
It("outputs check counts", func() {
_, err := service.Lint(lintConfig)
Expect(err).NotTo(HaveOccurred())
Expect(stdout.String()).To(Equal(""))
Expect(stdout.String()).To(Equal("\nChecked 2 files and found 0 problems.\n"))
})
})

Expand Down

0 comments on commit ac203a2

Please sign in to comment.