Skip to content

Commit

Permalink
Simplify summary output
Browse files Browse the repository at this point in the history
This less verbose approach to the project and projects linting summary output provides the same amount of information in
a more approachable format.
  • Loading branch information
per1234 committed Jul 19, 2021
1 parent dccb221 commit 6b719bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 17 additions & 3 deletions internal/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,15 @@ func (results Type) ProjectSummaryText(lintedProject project.Type) string {
panic(fmt.Sprintf("Unable to find report for %v when generating report summary text", lintedProject.Path))
}

projectSummaryReport := results.Projects[projectReportIndex].Summary
return fmt.Sprintf("Finished linting project. Results:\nWarning count: %v\nError count: %v\nRules passed: %v", projectSummaryReport.WarningCount, projectSummaryReport.ErrorCount, projectSummaryReport.Pass)
projectSummaryReport := "Linter results for project: "
projectSummaryData := results.Projects[projectReportIndex].Summary
if projectSummaryData.ErrorCount == 0 && projectSummaryData.WarningCount == 0 {
projectSummaryReport += "no errors or warnings"
} else {
projectSummaryReport += fmt.Sprintf("%v ERRORS, %v WARNINGS", projectSummaryData.ErrorCount, projectSummaryData.WarningCount)
}

return projectSummaryReport
}

// AddSummary summarizes the rule results for all projects and adds it to the report.
Expand All @@ -220,7 +227,14 @@ func (results *Type) AddSummary() {

// SummaryText returns a text summary of the cumulative rule results.
func (results Type) SummaryText() string {
return fmt.Sprintf("Finished linting projects. Results:\nWarning count: %v\nError count: %v\nRules passed: %v", results.Summary.WarningCount, results.Summary.ErrorCount, results.Summary.Pass)
summaryReport := "Linter results for projects: "
if results.Summary.ErrorCount == 0 && results.Summary.WarningCount == 0 {
summaryReport += "no errors or warnings"
} else {
summaryReport += fmt.Sprintf("%v ERRORS, %v WARNINGS", results.Summary.ErrorCount, results.Summary.WarningCount)
}

return summaryReport
}

// JSONReport returns a JSON formatted report of rules on all projects in string encoding.
Expand Down
12 changes: 10 additions & 2 deletions internal/result/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ func TestAddProjectSummary(t *testing.T) {
assert.Equal(t, testTable.expectedPass, results.Projects[0].Summary.Pass)
assert.Equal(t, testTable.expectedWarningCount, results.Projects[0].Summary.WarningCount)
assert.Equal(t, testTable.expectedErrorCount, results.Projects[0].Summary.ErrorCount)
assert.Equal(t, fmt.Sprintf("Finished linting project. Results:\nWarning count: %v\nError count: %v\nRules passed: %v", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.ProjectSummaryText(lintedProject))
if testTable.expectedErrorCount == 0 && testTable.expectedWarningCount == 0 {
assert.Equal(t, "Linter results for project: no errors or warnings", results.ProjectSummaryText(lintedProject))
} else {
assert.Equal(t, fmt.Sprintf("Linter results for project: %v ERRORS, %v WARNINGS", testTable.expectedErrorCount, testTable.expectedWarningCount), results.ProjectSummaryText(lintedProject))
}
}
}

Expand Down Expand Up @@ -290,7 +294,11 @@ func TestAddSummary(t *testing.T) {
assert.Equal(t, testTable.expectedPass, results.Passed())
assert.Equal(t, testTable.expectedWarningCount, results.Summary.WarningCount)
assert.Equal(t, testTable.expectedErrorCount, results.Summary.ErrorCount)
assert.Equal(t, fmt.Sprintf("Finished linting projects. Results:\nWarning count: %v\nError count: %v\nRules passed: %v", testTable.expectedWarningCount, testTable.expectedErrorCount, testTable.expectedPass), results.SummaryText())
if testTable.expectedErrorCount == 0 && testTable.expectedWarningCount == 0 {
assert.Equal(t, "Linter results for projects: no errors or warnings", results.SummaryText())
} else {
assert.Equal(t, fmt.Sprintf("Linter results for projects: %v ERRORS, %v WARNINGS", testTable.expectedErrorCount, testTable.expectedWarningCount), results.SummaryText())
}
}
}

Expand Down

0 comments on commit 6b719bc

Please sign in to comment.