Skip to content

Commit ae07d21

Browse files
committed
Improve organization of code
1 parent a7cc168 commit ae07d21

File tree

4 files changed

+89
-79
lines changed

4 files changed

+89
-79
lines changed

check/check.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ import (
1818
"github.com/arduino/arduino-cli/cli/feedback"
1919
)
2020

21+
// RunChecks runs all checks for the given project and outputs the results.
22+
func RunChecks(project project.Type) {
23+
fmt.Printf("Checking %s in %s\n", project.ProjectType.String(), project.Path.String())
24+
25+
checkdata.Initialize(project)
26+
27+
for _, checkConfiguration := range checkconfigurations.Configurations() {
28+
if !shouldRun(checkConfiguration, project) {
29+
// TODO: this should only be printed to log and in verbose mode
30+
fmt.Printf("Skipping check: %s\n", checkConfiguration.ID)
31+
continue
32+
}
33+
34+
fmt.Printf("Running check %s: ", checkConfiguration.ID)
35+
result, output := checkConfiguration.CheckFunction()
36+
fmt.Printf("%s\n", result.String())
37+
if result == checkresult.NotRun {
38+
// TODO: make the check functions output an explanation for why they didn't run
39+
fmt.Printf("%s: %s\n", checklevel.Notice, output)
40+
} else if result != checkresult.Pass {
41+
checkLevel, err := checklevel.CheckLevel(checkConfiguration)
42+
if err != nil {
43+
feedback.Errorf("Error while determining check level: %v", err)
44+
os.Exit(errorcodes.ErrGeneric)
45+
}
46+
fmt.Printf("%s: %s\n", checkLevel.String(), message(checkConfiguration.MessageTemplate, output))
47+
}
48+
}
49+
}
50+
2151
// shouldRun returns whether a given check should be run for the given project under the current tool configuration.
2252
func shouldRun(checkConfiguration checkconfigurations.Type, currentProject project.Type) bool {
2353
configurationCheckModes := configuration.CheckModes(currentProject.SuperprojectType)
@@ -65,33 +95,3 @@ func message(templateText string, checkOutput string) string {
6595

6696
return messageBuffer.String()
6797
}
68-
69-
// RunChecks runs all checks for the given project and outputs the results.
70-
func RunChecks(project project.Type) {
71-
fmt.Printf("Checking %s in %s\n", project.ProjectType.String(), project.Path.String())
72-
73-
checkdata.Initialize(project)
74-
75-
for _, checkConfiguration := range checkconfigurations.Configurations() {
76-
if !shouldRun(checkConfiguration, project) {
77-
// TODO: this should only be printed to log and in verbose mode
78-
fmt.Printf("Skipping check: %s\n", checkConfiguration.ID)
79-
continue
80-
}
81-
82-
fmt.Printf("Running check %s: ", checkConfiguration.ID)
83-
result, output := checkConfiguration.CheckFunction()
84-
fmt.Printf("%s\n", result.String())
85-
if result == checkresult.NotRun {
86-
// TODO: make the check functions output an explanation for why they didn't run
87-
fmt.Printf("%s: %s\n", checklevel.Notice, output)
88-
} else if result != checkresult.Pass {
89-
checkLevel, err := checklevel.CheckLevel(checkConfiguration)
90-
if err != nil {
91-
feedback.Errorf("Error while determining check level: %v", err)
92-
os.Exit(errorcodes.ErrGeneric)
93-
}
94-
fmt.Printf("%s: %s\n", checkLevel.String(), message(checkConfiguration.MessageTemplate, output))
95-
}
96-
}
97-
}

check/checkconfigurations/checkconfigurations.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type Type struct {
3434
CheckFunction checkfunctions.Type // The function that implements the check.
3535
}
3636

37+
// Configurations returns the slice of check configurations.
38+
func Configurations() []Type {
39+
return configurations
40+
}
41+
3742
// configurations is an array of structs that define the configuration of each check.
3843
var configurations = []Type{
3944
{
@@ -112,8 +117,3 @@ var configurations = []Type{
112117
CheckFunction: checkfunctions.PdeSketchExtension,
113118
},
114119
}
115-
116-
// Configurations returns the slice of check configurations.
117-
func Configurations() []Type {
118-
return configurations
119-
}

check/checkdata/checkdata.go

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ package checkdata
66

77
import (
88
"github.com/arduino/arduino-check/project"
9-
"github.com/arduino/arduino-check/project/library/libraryproperties"
109
"github.com/arduino/arduino-check/project/projecttype"
1110
"github.com/arduino/go-paths-helper"
12-
"github.com/arduino/go-properties-orderedmap"
13-
"github.com/xeipuuv/gojsonschema"
1411
)
1512

13+
// Initialize gathers the check data for the specified project.
14+
func Initialize(project project.Type) {
15+
projectType = project.ProjectType
16+
projectPath = project.Path
17+
switch project.ProjectType {
18+
case projecttype.Sketch:
19+
case projecttype.Library:
20+
InitializeForLibrary(project)
21+
case projecttype.Platform:
22+
case projecttype.PackageIndex:
23+
}
24+
}
25+
1626
var projectType projecttype.Type
1727

1828
// ProjectType returns the type of the project being checked.
@@ -26,44 +36,3 @@ var projectPath *paths.Path
2636
func ProjectPath() *paths.Path {
2737
return projectPath
2838
}
29-
30-
var libraryPropertiesLoadError error
31-
32-
// LibraryPropertiesLoadError returns the error output from loading the library.properties metadata file.
33-
func LibraryPropertiesLoadError() error {
34-
return libraryPropertiesLoadError
35-
}
36-
37-
var libraryProperties *properties.Map
38-
39-
// LibraryProperties returns the data from the library.properties metadata file
40-
func LibraryProperties() *properties.Map {
41-
return libraryProperties
42-
}
43-
44-
var libraryPropertiesSchemaValidationResult *gojsonschema.Result
45-
46-
// LibraryPropertiesSchemaValidationResult returns the result of validating library.properties against the JSON schema.
47-
// See: https://github.com/xeipuuv/gojsonschema
48-
func LibraryPropertiesSchemaValidationResult() *gojsonschema.Result {
49-
return libraryPropertiesSchemaValidationResult
50-
}
51-
52-
// Initialize gathers the check data for the specified project.
53-
func Initialize(project project.Type) {
54-
projectType = project.ProjectType
55-
projectPath = project.Path
56-
switch project.ProjectType {
57-
case projecttype.Sketch:
58-
case projecttype.Library:
59-
libraryProperties, libraryPropertiesLoadError = libraryproperties.Properties(project.Path)
60-
if libraryPropertiesLoadError != nil {
61-
// TODO: can I even do this?
62-
libraryPropertiesSchemaValidationResult = nil
63-
} else {
64-
libraryPropertiesSchemaValidationResult = libraryproperties.Validate(libraryProperties)
65-
}
66-
case projecttype.Platform:
67-
case projecttype.PackageIndex:
68-
}
69-
}

check/checkdata/library.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package checkdata
2+
3+
import (
4+
"github.com/arduino/arduino-check/project"
5+
"github.com/arduino/arduino-check/project/library/libraryproperties"
6+
"github.com/arduino/go-properties-orderedmap"
7+
"github.com/xeipuuv/gojsonschema"
8+
)
9+
10+
// Initialize gathers the library check data for the specified project.
11+
func InitializeForLibrary(project project.Type) {
12+
libraryProperties, libraryPropertiesLoadError = libraryproperties.Properties(project.Path)
13+
if libraryPropertiesLoadError != nil {
14+
// TODO: can I even do this?
15+
libraryPropertiesSchemaValidationResult = nil
16+
} else {
17+
libraryPropertiesSchemaValidationResult = libraryproperties.Validate(libraryProperties)
18+
}
19+
}
20+
21+
var libraryPropertiesLoadError error
22+
23+
// LibraryPropertiesLoadError returns the error output from loading the library.properties metadata file.
24+
func LibraryPropertiesLoadError() error {
25+
return libraryPropertiesLoadError
26+
}
27+
28+
var libraryProperties *properties.Map
29+
30+
// LibraryProperties returns the data from the library.properties metadata file
31+
func LibraryProperties() *properties.Map {
32+
return libraryProperties
33+
}
34+
35+
var libraryPropertiesSchemaValidationResult *gojsonschema.Result
36+
37+
// LibraryPropertiesSchemaValidationResult returns the result of validating library.properties against the JSON schema.
38+
// See: https://github.com/xeipuuv/gojsonschema
39+
func LibraryPropertiesSchemaValidationResult() *gojsonschema.Result {
40+
return libraryPropertiesSchemaValidationResult
41+
}

0 commit comments

Comments
 (0)