Skip to content

Commit b9c4887

Browse files
committed
Remove "Pass" check level
There is no valid reason for a check to be defined, only for the results to be ignored. This was used as a default behavior when no level was configured for the check, but that indicates a configuration error and should not be ignored. So I now error exit when this situation occurs.
1 parent 746a908 commit b9c4887

File tree

4 files changed

+26
-37
lines changed

4 files changed

+26
-37
lines changed

check/check.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package check
33
import (
44
"bytes"
55
"fmt"
6+
"os"
67
"text/template"
78

89
"github.com/arduino/arduino-check/check/checkconfigurations"
@@ -12,6 +13,8 @@ import (
1213
"github.com/arduino/arduino-check/configuration"
1314
"github.com/arduino/arduino-check/configuration/checkmode"
1415
"github.com/arduino/arduino-check/project"
16+
"github.com/arduino/arduino-cli/cli/errorcodes"
17+
"github.com/arduino/arduino-cli/cli/feedback"
1518
)
1619

1720
func shouldRun(checkConfiguration checkconfigurations.Type, currentProject project.Type) bool {
@@ -79,7 +82,12 @@ func RunChecks(project project.Type) {
7982
// TODO: make the check functions output an explanation for why they didn't run
8083
fmt.Printf("%s: %s\n", checklevel.Notice, output)
8184
} else if result != checkresult.Pass {
82-
fmt.Printf("%s: %s\n", checklevel.CheckLevel(checkConfiguration).String(), message(checkConfiguration.MessageTemplate, output))
85+
checkLevel, err := checklevel.CheckLevel(checkConfiguration)
86+
if err != nil {
87+
feedback.Errorf("Error while determining check level: %v", err)
88+
os.Exit(errorcodes.ErrGeneric)
89+
}
90+
fmt.Printf("%s: %s\n", checkLevel.String(), message(checkConfiguration.MessageTemplate, output))
8391
}
8492
}
8593
}

check/checkconfigurations/checkconfigurations.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type Type struct {
2424
// Check is only enabled when tool is in one of these modes
2525
EnableModes []checkmode.Type
2626
// The following fields define the check level in each configuration mode
27-
PassModes []checkmode.Type
2827
InfoModes []checkmode.Type
2928
WarningModes []checkmode.Type
3029
ErrorModes []checkmode.Type
@@ -44,7 +43,6 @@ var Configurations = []Type{
4443
MessageTemplate: "library.properties has an invalid format: {{.}}",
4544
DisableModes: nil,
4645
EnableModes: []checkmode.Type{checkmode.All},
47-
PassModes: nil,
4846
InfoModes: nil,
4947
WarningModes: nil,
5048
ErrorModes: []checkmode.Type{checkmode.All},
@@ -60,7 +58,6 @@ var Configurations = []Type{
6058
MessageTemplate: "missing name field in library.properties",
6159
DisableModes: nil,
6260
EnableModes: []checkmode.Type{checkmode.All},
63-
PassModes: nil,
6461
InfoModes: nil,
6562
WarningModes: nil,
6663
ErrorModes: []checkmode.Type{checkmode.All},
@@ -76,7 +73,6 @@ var Configurations = []Type{
7673
MessageTemplate: "disallowed characters in library.properties name field. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
7774
DisableModes: nil,
7875
EnableModes: []checkmode.Type{checkmode.All},
79-
PassModes: nil,
8076
InfoModes: nil,
8177
WarningModes: nil,
8278
ErrorModes: []checkmode.Type{checkmode.All},
@@ -92,7 +88,6 @@ var Configurations = []Type{
9288
MessageTemplate: "missing version field in library.properties",
9389
DisableModes: nil,
9490
EnableModes: []checkmode.Type{checkmode.All},
95-
PassModes: nil,
9691
InfoModes: nil,
9792
WarningModes: nil,
9893
ErrorModes: []checkmode.Type{checkmode.All},
@@ -108,7 +103,6 @@ var Configurations = []Type{
108103
MessageTemplate: "{{.}} uses deprecated .pde file extension. Use .ino for Arduino sketches",
109104
DisableModes: nil,
110105
EnableModes: []checkmode.Type{checkmode.All},
111-
PassModes: nil,
112106
InfoModes: nil,
113107
WarningModes: []checkmode.Type{checkmode.Permissive},
114108
ErrorModes: []checkmode.Type{checkmode.Default},

check/checklevel/checklevel.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package checklevel
22

33
import (
4+
"fmt"
5+
46
"github.com/arduino/arduino-check/check/checkconfigurations"
57
"github.com/arduino/arduino-check/configuration"
68
"github.com/arduino/arduino-check/configuration/checkmode"
@@ -11,64 +13,50 @@ type Type int
1113

1214
// Line comments set the string for each level
1315
const (
14-
Pass Type = iota // pass
15-
Info // info
16+
Info Type = iota // info
1617
Warning // warning
1718
Error // error
1819
Notice // notice
1920
)
2021

21-
func CheckLevel(checkConfiguration checkconfigurations.Type) Type {
22+
func CheckLevel(checkConfiguration checkconfigurations.Type) (Type, error) {
2223
configurationCheckModes := configuration.CheckModes(checkConfiguration.ProjectType)
2324
for _, errorMode := range checkConfiguration.ErrorModes {
2425
if configurationCheckModes[errorMode] == true {
25-
return Error
26+
return Error, nil
2627
}
2728
}
2829

2930
for _, warningMode := range checkConfiguration.WarningModes {
3031
if configurationCheckModes[warningMode] == true {
31-
return Warning
32+
return Warning, nil
3233
}
3334
}
3435

3536
for _, infoMode := range checkConfiguration.InfoModes {
3637
if configurationCheckModes[infoMode] == true {
37-
return Info
38-
}
39-
}
40-
41-
for _, passMode := range checkConfiguration.PassModes {
42-
if configurationCheckModes[passMode] == true {
43-
return Pass
38+
return Info, nil
4439
}
4540
}
4641

4742
// Use default level
4843
for _, errorMode := range checkConfiguration.ErrorModes {
4944
if errorMode == checkmode.Default {
50-
return Error
45+
return Error, nil
5146
}
5247
}
5348

5449
for _, warningMode := range checkConfiguration.WarningModes {
5550
if warningMode == checkmode.Default {
56-
return Warning
51+
return Warning, nil
5752
}
5853
}
5954

6055
for _, infoMode := range checkConfiguration.InfoModes {
6156
if infoMode == checkmode.Default {
62-
return Info
63-
}
64-
}
65-
66-
for _, passMode := range checkConfiguration.PassModes {
67-
if passMode == checkmode.Default {
68-
return Pass
57+
return Info, nil
6958
}
7059
}
7160

72-
// TODO: this should return an error
73-
return Pass
61+
return Notice, fmt.Errorf("Check %s is incorrectly configured", checkConfiguration.ID)
7462
}

check/checklevel/type_string.go

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)