Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6894049

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 fbe79ee commit 6894049

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
@@ -38,18 +38,18 @@ func RunChecks(project project.Type) {
3838
fmt.Printf("Running check %s: ", checkConfiguration.ID)
3939
}
4040
checkResult, checkOutput := checkConfiguration.CheckFunction()
41-
reportText := result.Report.Record(project, checkConfiguration, checkResult, checkOutput)
41+
reportText := result.Results.Record(project, checkConfiguration, checkResult, checkOutput)
4242
if configuration.OutputFormat() == "text" {
4343
fmt.Print(reportText)
4444
}
4545
}
4646

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

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

‎main.go‎

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

1919
projects, err := project.FindProjects()
2020
if err != nil {
@@ -27,24 +27,24 @@ func main() {
2727
}
2828

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

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

4242
if configuration.ReportFilePath() != nil {
4343
// Write report file.
44-
result.Report.WriteReport()
44+
result.Results.WriteReport()
4545
}
4646

47-
if !result.Report.Passed() {
47+
if !result.Results.Passed() {
4848
os.Exit(1)
4949
}
5050
}

‎result/result.go‎

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

21-
// Report is the global instance of the check results ReportType struct
22-
var ReportReportType
21+
// Results is the global instance of the check results result.Type struct
22+
var ResultsType
2323

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

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

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

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

108-
reportExists, projectReportIndex := report.getProjectReportIndex(checkedProject.Path)
108+
reportExists, projectReportIndex := results.getProjectReportIndex(checkedProject.Path)
109109
if !reportExists {
110110
// There is no existing report for this project.
111-
report.Projects = append(
112-
report.Projects,
111+
results.Projects = append(
112+
results.Projects,
113113
projectReportType{
114114
Path: checkedProject.Path,
115115
ProjectType: checkedProject.ProjectType.String(),
@@ -124,23 +124,23 @@ func (report *ReportType) Record(checkedProject project.Type, checkConfiguration
124124
)
125125
} else {
126126
// There's already a report for this project, just add the checks report to it
127-
report.Projects[projectReportIndex].Checks = append(report.Projects[projectReportIndex].Checks, checkReport)
127+
results.Projects[projectReportIndex].Checks = append(results.Projects[projectReportIndex].Checks, checkReport)
128128
}
129129

130130
return summaryText
131131
}
132132

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

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

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

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

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

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

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

192192
// SummaryText returns a text summary of the cumulative check results.
193-
func (reportReportType) SummaryText() string {
194-
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)
193+
func (resultsType) SummaryText() string {
194+
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)
195195
}
196196

197-
// Report returns a JSON formatted report of checks on all projects.
198-
func (reportReportType) JSONReport() string {
199-
return string(report.jsonReportRaw())
197+
// JSONReport returns a JSON formatted report of checks on all projects.
198+
func (resultsType) JSONReport() string {
199+
return string(results.jsonReportRaw())
200200
}
201201

202-
func (reportReportType) jsonReportRaw() []byte {
203-
reportJSON, err := json.MarshalIndent(report, "", " ")
202+
func (resultsType) jsonReportRaw() []byte {
203+
reportJSON, err := json.MarshalIndent(results, "", " ")
204204
if err != nil {
205205
panic(fmt.Sprintf("Error while formatting checks report: %v", err))
206206
}
@@ -209,24 +209,24 @@ func (report ReportType) jsonReportRaw() []byte {
209209
}
210210

211211
// WriteReport writes a report for all projects to the specified file.
212-
func (reportReportType) WriteReport() {
212+
func (resultsType) WriteReport() {
213213
// Write report file
214-
err := configuration.ReportFilePath().WriteFile(report.jsonReportRaw())
214+
err := configuration.ReportFilePath().WriteFile(results.jsonReportRaw())
215215
if err != nil {
216216
feedback.Errorf("Error while writing report: %v", err)
217217
os.Exit(1)
218218
}
219219
}
220220

221221
// Passed returns whether the checks passed cumulatively.
222-
func (reportReportType) Passed() bool {
223-
return report.Summary.Pass
222+
func (resultsType) Passed() bool {
223+
return results.Summary.Pass
224224
}
225225

226-
func (reportReportType) getProjectReportIndex(projectPath *paths.Path) (bool, int) {
226+
func (resultsType) getProjectReportIndex(projectPath *paths.Path) (bool, int) {
227227
var index int
228228
var projectReport projectReportType
229-
for index, projectReport = range report.Projects {
229+
for index, projectReport = range results.Projects {
230230
if projectReport.Path == projectPath {
231231
return true, index
232232
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /