@@ -19,11 +19,11 @@ import (
19
19
"github.com/arduino/go-paths-helper"
20
20
)
21
21
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
24
24
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 {
27
27
Configuration toolConfigurationReportType `json:"configuration"`
28
28
Projects []projectReportType `json:"projects"`
29
29
Summary summaryReportType `json:"summary"`
@@ -67,17 +67,17 @@ type summaryReportType struct {
67
67
ErrorCount int `json:"errorCount"`
68
68
}
69
69
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 {
73
73
Paths : []* paths.Path {configuration .TargetPath ()},
74
74
ProjectType : configuration .SuperprojectTypeFilter ().String (),
75
75
Recursive : configuration .Recursive (),
76
76
}
77
77
}
78
78
79
79
// 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 {
81
81
checkMessage := message (checkConfiguration .MessageTemplate , checkOutput )
82
82
83
83
checkLevel , err := checklevel .CheckLevel (checkConfiguration )
@@ -106,11 +106,11 @@ func (report *ReportType) Record(checkedProject project.Type, checkConfiguration
106
106
Message : checkMessage ,
107
107
}
108
108
109
- reportExists , projectReportIndex := report .getProjectReportIndex (checkedProject .Path )
109
+ reportExists , projectReportIndex := results .getProjectReportIndex (checkedProject .Path )
110
110
if ! reportExists {
111
111
// There is no existing report for this project.
112
- report .Projects = append (
113
- report .Projects ,
112
+ results .Projects = append (
113
+ results .Projects ,
114
114
projectReportType {
115
115
Path : checkedProject .Path ,
116
116
ProjectType : checkedProject .ProjectType .String (),
@@ -125,23 +125,23 @@ func (report *ReportType) Record(checkedProject project.Type, checkConfiguration
125
125
)
126
126
} else {
127
127
// 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 )
129
129
}
130
130
131
131
return summaryText
132
132
}
133
133
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 )
137
137
if ! reportExists {
138
138
panic (fmt .Sprintf ("Unable to find report for %v when generating report summary" , checkedProject .Path ))
139
139
}
140
140
141
141
pass := true
142
142
warningCount := 0
143
143
errorCount := 0
144
- for _ , checkReport := range report .Projects [projectReportIndex ].Checks {
144
+ for _ , checkReport := range results .Projects [projectReportIndex ].Checks {
145
145
if checkReport .Result == checkresult .Fail .String () {
146
146
if checkReport .Level == checklevel .Warning .String () {
147
147
warningCount += 1
@@ -152,56 +152,56 @@ func (report *ReportType) AddProjectSummaryReport(checkedProject project.Type) {
152
152
}
153
153
}
154
154
155
- report .Projects [projectReportIndex ].Summary = summaryReportType {
155
+ results .Projects [projectReportIndex ].Summary = summaryReportType {
156
156
Pass : pass ,
157
157
WarningCount : warningCount ,
158
158
ErrorCount : errorCount ,
159
159
}
160
160
}
161
161
162
162
// 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 )
165
165
if ! reportExists {
166
166
panic (fmt .Sprintf ("Unable to find report for %v when generating report summary text" , checkedProject .Path ))
167
167
}
168
168
169
- projectSummaryReport := report .Projects [projectReportIndex ].Summary
169
+ projectSummaryReport := results .Projects [projectReportIndex ].Summary
170
170
return fmt .Sprintf ("\n Finished checking project. Results:\n Warning count: %v\n Error count: %v\n Checks passed: %v\n \n " , projectSummaryReport .WarningCount , projectSummaryReport .ErrorCount , projectSummaryReport .Pass )
171
171
}
172
172
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 () {
175
175
pass := true
176
176
warningCount := 0
177
177
errorCount := 0
178
- for _ , projectReport := range report .Projects {
178
+ for _ , projectReport := range results .Projects {
179
179
if ! projectReport .Summary .Pass {
180
180
pass = false
181
181
}
182
182
warningCount += projectReport .Summary .WarningCount
183
183
errorCount += projectReport .Summary .ErrorCount
184
184
}
185
185
186
- report .Summary = summaryReportType {
186
+ results .Summary = summaryReportType {
187
187
Pass : pass ,
188
188
WarningCount : warningCount ,
189
189
ErrorCount : errorCount ,
190
190
}
191
191
}
192
192
193
193
// SummaryText returns a text summary of the cumulative check results.
194
- func (report ReportType ) SummaryText () string {
195
- return fmt .Sprintf ("Finished checking projects. Results:\n Warning count: %v\n Error count: %v\n Checks 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:\n Warning count: %v\n Error count: %v\n Checks passed: %v\n " , results .Summary .WarningCount , results .Summary .ErrorCount , results .Summary .Pass )
196
196
}
197
197
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 ())
201
201
}
202
202
203
- func (report ReportType ) jsonReportRaw () []byte {
204
- reportJSON , err := json .MarshalIndent (report , "" , " " )
203
+ func (results Type ) jsonReportRaw () []byte {
204
+ reportJSON , err := json .MarshalIndent (results , "" , " " )
205
205
if err != nil {
206
206
panic (fmt .Sprintf ("Error while formatting checks report: %v" , err ))
207
207
}
@@ -210,24 +210,24 @@ func (report ReportType) jsonReportRaw() []byte {
210
210
}
211
211
212
212
// WriteReport writes a report for all projects to the specified file.
213
- func (report ReportType ) WriteReport () {
213
+ func (results Type ) WriteReport () {
214
214
// Write report file
215
- err := configuration .ReportFilePath ().WriteFile (report .jsonReportRaw ())
215
+ err := configuration .ReportFilePath ().WriteFile (results .jsonReportRaw ())
216
216
if err != nil {
217
217
feedback .Errorf ("Error while writing report: %v" , err )
218
218
os .Exit (errorcodes .ErrGeneric )
219
219
}
220
220
}
221
221
222
222
// 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
225
225
}
226
226
227
- func (report ReportType ) getProjectReportIndex (projectPath * paths.Path ) (bool , int ) {
227
+ func (results Type ) getProjectReportIndex (projectPath * paths.Path ) (bool , int ) {
228
228
var index int
229
229
var projectReport projectReportType
230
- for index , projectReport = range report .Projects {
230
+ for index , projectReport = range results .Projects {
231
231
if projectReport .Path == projectPath {
232
232
return true , index
233
233
}
0 commit comments