Skip to content

Simplify summary output #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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