Skip to content

Commit 2470125

Browse files
committed
Refactor names in the result package
The change in approach in the result package resulted in some of the use of the term "report" in that package becoming less intuitive, since reports are only one use of the results.
1 parent ede16ce commit 2470125

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

check/check.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ func RunChecks(project project.Type) {
3939
fmt.Printf("Running check %s: ", checkConfiguration.ID)
4040
}
4141
checkResult, checkOutput := checkConfiguration.CheckFunction()
42-
reportText := result.Report.Record(project, checkConfiguration, checkResult, checkOutput)
42+
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
4343
if configuration.OutputFormat() == "text" {
4444
fmt.Print(reportText)
4545
}
4646
}
4747

4848
// Checks are finished for this project, so summarize its check results in the report.
49-
result.Report.AddProjectSummaryReport(project)
49+
result.Results.AddProjectSummary(project)
5050

5151
if configuration.OutputFormat() == "text" {
5252
// Print the project check results summary.
53-
fmt.Print(result.Report.ProjectSummaryText(project))
53+
fmt.Print(result.Results.ProjectSummaryText(project))
5454
}
5555
}
5656

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func main() {
1616
configuration.Initialize()
1717
// Must be called after configuration.Initialize()
18-
result.Report.Initialize()
18+
result.Results.Initialize()
1919

2020
projects, err := project.FindProjects()
2121
if err != nil {
@@ -28,24 +28,24 @@ func main() {
2828
}
2929

3030
// All projects have been checked, so summarize their check results in the report.
31-
result.Report.AddSummaryReport()
31+
result.Results.AddSummary()
3232

3333
if configuration.OutputFormat() == "text" {
3434
if len(projects) > 1 {
3535
// There are multiple projects, print the summary of check results for all projects.
36-
fmt.Print(result.Report.SummaryText())
36+
fmt.Print(result.Results.SummaryText())
3737
}
3838
} else {
3939
// Print the complete JSON formatted report.
40-
fmt.Println(result.Report.JSONReport())
40+
fmt.Println(result.Results.JSONReport())
4141
}
4242

4343
if configuration.ReportFilePath() != nil {
4444
// Write report file.
45-
result.Report.WriteReport()
45+
result.Results.WriteReport()
4646
}
4747

48-
if !result.Report.Passed() {
48+
if !result.Results.Passed() {
4949
os.Exit(errorcodes.ErrGeneric)
5050
}
5151
}

result/result.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"github.com/arduino/go-paths-helper"
2020
)
2121

22-
// Report is the global instance of the check results ReportType struct
23-
var Report ReportType
22+
// Results is the global instance of the check results result.Type struct
23+
var Results Type
2424

25-
// ReportType is the type for the check results report
26-
type ReportType struct {
25+
// Type is the type for the check results data
26+
type Type struct {
2727
Configuration toolConfigurationReportType `json:"configuration"`
2828
Projects []projectReportType `json:"projects"`
2929
Summary summaryReportType `json:"summary"`
@@ -67,17 +67,17 @@ type summaryReportType struct {
6767
ErrorCount int `json:"errorCount"`
6868
}
6969

70-
// Initialize adds the tool configuration data to the report.
71-
func (report *ReportType) Initialize() {
72-
report.Configuration = toolConfigurationReportType{
70+
// Initialize adds the tool configuration data to the results data.
71+
func (results *Type) Initialize() {
72+
results.Configuration = toolConfigurationReportType{
7373
Paths: []*paths.Path{configuration.TargetPath()},
7474
ProjectType: configuration.SuperprojectTypeFilter().String(),
7575
Recursive: configuration.Recursive(),
7676
}
7777
}
7878

7979
// Record records the result of a check and returns a text summary for it.
80-
func (report *ReportType) Record(checkedProject project.Type, checkConfiguration checkconfigurations.Type, checkResult checkresult.Type, checkOutput string) string {
80+
func (results *Type) Record(checkedProject project.Type, checkConfiguration checkconfigurations.Type, checkResult checkresult.Type, checkOutput string) string {
8181
checkMessage := message(checkConfiguration.MessageTemplate, checkOutput)
8282

8383
checkLevel, err := checklevel.CheckLevel(checkConfiguration)
@@ -106,11 +106,11 @@ func (report *ReportType) Record(checkedProject project.Type, checkConfiguration
106106
Message: checkMessage,
107107
}
108108

109-
reportExists, projectReportIndex := report.getProjectReportIndex(checkedProject.Path)
109+
reportExists, projectReportIndex := results.getProjectReportIndex(checkedProject.Path)
110110
if !reportExists {
111111
// There is no existing report for this project.
112-
report.Projects = append(
113-
report.Projects,
112+
results.Projects = append(
113+
results.Projects,
114114
projectReportType{
115115
Path: checkedProject.Path,
116116
ProjectType: checkedProject.ProjectType.String(),
@@ -125,23 +125,23 @@ func (report *ReportType) Record(checkedProject project.Type, checkConfiguration
125125
)
126126
} else {
127127
// There's already a report for this project, just add the checks report to it
128-
report.Projects[projectReportIndex].Checks = append(report.Projects[projectReportIndex].Checks, checkReport)
128+
results.Projects[projectReportIndex].Checks = append(results.Projects[projectReportIndex].Checks, checkReport)
129129
}
130130

131131
return summaryText
132132
}
133133

134-
// AddProjectSummaryReport summarizes the results of all checks on the given project and adds it to the report.
135-
func (report *ReportType) AddProjectSummaryReport(checkedProject project.Type) {
136-
reportExists, projectReportIndex := report.getProjectReportIndex(checkedProject.Path)
134+
// AddProjectSummary summarizes the results of all checks on the given project and adds it to the report.
135+
func (results *Type) AddProjectSummary(checkedProject project.Type) {
136+
reportExists, projectReportIndex := results.getProjectReportIndex(checkedProject.Path)
137137
if !reportExists {
138138
panic(fmt.Sprintf("Unable to find report for %v when generating report summary", checkedProject.Path))
139139
}
140140

141141
pass := true
142142
warningCount := 0
143143
errorCount := 0
144-
for _, checkReport := range report.Projects[projectReportIndex].Checks {
144+
for _, checkReport := range results.Projects[projectReportIndex].Checks {
145145
if checkReport.Result == checkresult.Fail.String() {
146146
if checkReport.Level == checklevel.Warning.String() {
147147
warningCount += 1
@@ -152,56 +152,56 @@ func (report *ReportType) AddProjectSummaryReport(checkedProject project.Type) {
152152
}
153153
}
154154

155-
report.Projects[projectReportIndex].Summary = summaryReportType{
155+
results.Projects[projectReportIndex].Summary = summaryReportType{
156156
Pass: pass,
157157
WarningCount: warningCount,
158158
ErrorCount: errorCount,
159159
}
160160
}
161161

162162
// ProjectSummaryText returns a text summary of the check results for the given project.
163-
func (report ReportType) ProjectSummaryText(checkedProject project.Type) string {
164-
reportExists, projectReportIndex := report.getProjectReportIndex(checkedProject.Path)
163+
func (results Type) ProjectSummaryText(checkedProject project.Type) string {
164+
reportExists, projectReportIndex := results.getProjectReportIndex(checkedProject.Path)
165165
if !reportExists {
166166
panic(fmt.Sprintf("Unable to find report for %v when generating report summary text", checkedProject.Path))
167167
}
168168

169-
projectSummaryReport := report.Projects[projectReportIndex].Summary
169+
projectSummaryReport := results.Projects[projectReportIndex].Summary
170170
return fmt.Sprintf("\nFinished checking project. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n\n", projectSummaryReport.WarningCount, projectSummaryReport.ErrorCount, projectSummaryReport.Pass)
171171
}
172172

173-
// AddSummaryReport summarizes the check results for all projects and adds it to the report.
174-
func (report *ReportType) AddSummaryReport() {
173+
// AddSummary summarizes the check results for all projects and adds it to the report.
174+
func (results *Type) AddSummary() {
175175
pass := true
176176
warningCount := 0
177177
errorCount := 0
178-
for _, projectReport := range report.Projects {
178+
for _, projectReport := range results.Projects {
179179
if !projectReport.Summary.Pass {
180180
pass = false
181181
}
182182
warningCount += projectReport.Summary.WarningCount
183183
errorCount += projectReport.Summary.ErrorCount
184184
}
185185

186-
report.Summary = summaryReportType{
186+
results.Summary = summaryReportType{
187187
Pass: pass,
188188
WarningCount: warningCount,
189189
ErrorCount: errorCount,
190190
}
191191
}
192192

193193
// SummaryText returns a text summary of the cumulative check results.
194-
func (report ReportType) SummaryText() string {
195-
return fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n", report.Summary.WarningCount, report.Summary.ErrorCount, report.Summary.Pass)
194+
func (results Type) SummaryText() string {
195+
return fmt.Sprintf("Finished checking projects. Results:\nWarning count: %v\nError count: %v\nChecks passed: %v\n", results.Summary.WarningCount, results.Summary.ErrorCount, results.Summary.Pass)
196196
}
197197

198-
// Report returns a JSON formatted report of checks on all projects.
199-
func (report ReportType) JSONReport() string {
200-
return string(report.jsonReportRaw())
198+
// JSONReport returns a JSON formatted report of checks on all projects.
199+
func (results Type) JSONReport() string {
200+
return string(results.jsonReportRaw())
201201
}
202202

203-
func (report ReportType) jsonReportRaw() []byte {
204-
reportJSON, err := json.MarshalIndent(report, "", " ")
203+
func (results Type) jsonReportRaw() []byte {
204+
reportJSON, err := json.MarshalIndent(results, "", " ")
205205
if err != nil {
206206
panic(fmt.Sprintf("Error while formatting checks report: %v", err))
207207
}
@@ -210,24 +210,24 @@ func (report ReportType) jsonReportRaw() []byte {
210210
}
211211

212212
// WriteReport writes a report for all projects to the specified file.
213-
func (report ReportType) WriteReport() {
213+
func (results Type) WriteReport() {
214214
// Write report file
215-
err := configuration.ReportFilePath().WriteFile(report.jsonReportRaw())
215+
err := configuration.ReportFilePath().WriteFile(results.jsonReportRaw())
216216
if err != nil {
217217
feedback.Errorf("Error while writing report: %v", err)
218218
os.Exit(errorcodes.ErrGeneric)
219219
}
220220
}
221221

222222
// Passed returns whether the checks passed cumulatively.
223-
func (report ReportType) Passed() bool {
224-
return report.Summary.Pass
223+
func (results Type) Passed() bool {
224+
return results.Summary.Pass
225225
}
226226

227-
func (report ReportType) getProjectReportIndex(projectPath *paths.Path) (bool, int) {
227+
func (results Type) getProjectReportIndex(projectPath *paths.Path) (bool, int) {
228228
var index int
229229
var projectReport projectReportType
230-
for index, projectReport = range report.Projects {
230+
for index, projectReport = range results.Projects {
231231
if projectReport.Path == projectPath {
232232
return true, index
233233
}

0 commit comments

Comments
 (0)