Skip to content

Commit 6caf4c6

Browse files
authored
Merge pull request #88 from arduino/per1234/remove-all-check-mode
Remove "All" check mode
2 parents 67e4638 + 1ca97d6 commit 6caf4c6

File tree

7 files changed

+195
-102
lines changed

7 files changed

+195
-102
lines changed

check/check.go

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func shouldRun(checkConfiguration checkconfigurations.Type, currentProject proje
7171
return false, nil
7272
}
7373

74+
return IsEnabled(checkConfiguration, configurationCheckModes)
75+
}
76+
77+
func IsEnabled(checkConfiguration checkconfigurations.Type, configurationCheckModes map[checkmode.Type]bool) (bool, error) {
7478
for _, disableMode := range checkConfiguration.DisableModes {
7579
if configurationCheckModes[disableMode] {
7680
return false, nil

check/checkconfigurations/checkconfigurations.go

+92-92
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkconfigurations_test
17+
18+
import (
19+
"fmt"
20+
"testing"
21+
22+
"github.com/arduino/arduino-check/check"
23+
"github.com/arduino/arduino-check/check/checkconfigurations"
24+
"github.com/arduino/arduino-check/check/checklevel"
25+
"github.com/arduino/arduino-check/configuration/checkmode"
26+
"github.com/stretchr/testify/assert"
27+
)
28+
29+
func TestConfigurationResolution(t *testing.T) {
30+
for _, checkConfiguration := range checkconfigurations.Configurations() {
31+
for checkMode := range checkmode.Types {
32+
enabled, err := check.IsEnabled(checkConfiguration, map[checkmode.Type]bool{checkMode: true})
33+
assert.Nil(t, err, fmt.Sprintf("Enable configuration of check %s doesn't resolve for check mode %s", checkConfiguration.ID, checkMode))
34+
if err == nil && enabled {
35+
_, err := checklevel.CheckLevelForCheckModes(checkConfiguration, map[checkmode.Type]bool{checkMode: true})
36+
assert.Nil(t, err, fmt.Sprintf("Level configuration of check %s doesn't resolve for check mode %s", checkConfiguration.ID, checkMode))
37+
}
38+
}
39+
}
40+
}
41+
42+
func TestConfigurationCheckModeConflict(t *testing.T) {
43+
// Having the same check mode in multiple configurations results in the configuration behavior being dependent on which order the fields are processed in, which may change.
44+
for _, checkConfiguration := range checkconfigurations.Configurations() {
45+
conflict, checkMode := checkModeConflict(checkConfiguration.DisableModes, checkConfiguration.EnableModes)
46+
assert.False(t, conflict, fmt.Sprintf("Duplicated check mode %s in enable configuration of check %s", checkMode, checkConfiguration.ID))
47+
48+
conflict, checkMode = checkModeConflict(checkConfiguration.InfoModes, checkConfiguration.WarningModes, checkConfiguration.ErrorModes)
49+
assert.False(t, conflict, fmt.Sprintf("Duplicated check mode %s in level configuration of check %s", checkMode, checkConfiguration.ID))
50+
}
51+
}
52+
53+
// checkModeConflict checks whether the same check mode is present in multiple configuration fields.
54+
func checkModeConflict(configurations ...[]checkmode.Type) (bool, checkmode.Type) {
55+
modeCounter := 0
56+
checkModeMap := make(map[checkmode.Type]bool)
57+
for _, configuration := range configurations {
58+
for _, checkMode := range configuration {
59+
modeCounter += 1
60+
checkModeMap[checkMode] = true
61+
if len(checkModeMap) < modeCounter {
62+
return true, checkMode
63+
}
64+
}
65+
}
66+
return false, checkmode.Default
67+
}

check/checklevel/checklevel.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const (
3939
// CheckLevel determines the check level assigned to failure of the given check under the current tool configuration.
4040
func CheckLevel(checkConfiguration checkconfigurations.Type) (Type, error) {
4141
configurationCheckModes := configuration.CheckModes(checkConfiguration.ProjectType)
42+
return CheckLevelForCheckModes(checkConfiguration, configurationCheckModes)
43+
}
44+
45+
func CheckLevelForCheckModes(checkConfiguration checkconfigurations.Type, configurationCheckModes map[checkmode.Type]bool) (Type, error) {
4246
for _, errorMode := range checkConfiguration.ErrorModes {
4347
if configurationCheckModes[errorMode] {
4448
return Error, nil

configuration/checkmode/checkmode.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ const (
3535
LibraryManagerSubmission // --library-manager=submit
3636
LibraryManagerIndexed // --library-manager=update
3737
Official // ARDUINO_CHECK_OFFICIAL
38-
All // always
3938
Default // default
4039
)
4140

41+
var empty struct{}
42+
43+
// Types provides an iterator and validator for Type.
44+
var Types = map[Type]struct{}{
45+
Strict: empty,
46+
Specification: empty,
47+
Permissive: empty,
48+
LibraryManagerSubmission: empty,
49+
LibraryManagerIndexed: empty,
50+
Official: empty,
51+
Default: empty,
52+
}
53+
4254
// ComplianceModeFromString parses the --compliance flag value and returns the corresponding check mode settings.
4355
func ComplianceModeFromString(complianceModeString string) (bool, bool, bool, error) {
4456
switch strings.ToLower(complianceModeString) {
@@ -81,9 +93,6 @@ func Modes(defaultCheckModes map[projecttype.Type]map[Type]bool, customCheckMode
8193
logrus.Tracef("Check mode option %s set to %t\n", key, checkModes[key])
8294
}
8395

84-
// This mode is always enabled
85-
checkModes[All] = true
86-
8796
return checkModes
8897
}
8998

configuration/checkmode/checkmode_test.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,29 @@ import (
2323
"github.com/stretchr/testify/assert"
2424
)
2525

26+
func TestTypes(t *testing.T) {
27+
for key := range Types {
28+
_, valid := Types[key]
29+
assert.True(t, valid)
30+
}
31+
32+
_, valid := Types[Strict]
33+
assert.True(t, valid)
34+
_, valid = Types[42]
35+
assert.False(t, valid)
36+
}
37+
2638
func TestMode(t *testing.T) {
2739
defaultCheckModes := map[projecttype.Type]map[Type]bool{
2840
projecttype.Sketch: {
2941
LibraryManagerSubmission: false,
3042
LibraryManagerIndexed: false,
3143
Official: false,
32-
All: true,
3344
},
3445
projecttype.Library: {
3546
LibraryManagerSubmission: true,
3647
LibraryManagerIndexed: false,
3748
Official: false,
38-
All: true,
3949
},
4050
}
4151

configuration/checkmode/type_string.go

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)