Skip to content

Commit 592badc

Browse files
authored
Merge pull request #109 from arduino/per1234/add-check-ids
Define unique IDs for all check configurations
2 parents 88632d3 + 14b046d commit 592badc

File tree

7 files changed

+866
-836
lines changed

7 files changed

+866
-836
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+379-379
Large diffs are not rendered by default.

Diff for: check/checkconfigurations/checkconfigurations_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"github.com/arduino/arduino-lint/check/checkconfigurations"
2424
"github.com/arduino/arduino-lint/check/checklevel"
2525
"github.com/arduino/arduino-lint/configuration/checkmode"
26+
"github.com/arduino/arduino-lint/project/projecttype"
2627
"github.com/stretchr/testify/assert"
28+
"github.com/stretchr/testify/require"
2729
)
2830

2931
func TestConfigurationResolution(t *testing.T) {
@@ -65,3 +67,31 @@ func checkModeConflict(configurations ...[]checkmode.Type) (bool, checkmode.Type
6567
}
6668
return false, checkmode.Default
6769
}
70+
71+
func TestIncorrectCheckIDPrefix(t *testing.T) {
72+
for checkIndex, checkConfiguration := range checkconfigurations.Configurations() {
73+
var IDPrefix byte
74+
switch checkConfiguration.ProjectType {
75+
case projecttype.Sketch:
76+
IDPrefix = 'S'
77+
case projecttype.Library:
78+
IDPrefix = 'L'
79+
case projecttype.Platform:
80+
IDPrefix = 'P'
81+
case projecttype.PackageIndex:
82+
IDPrefix = 'I'
83+
default:
84+
panic(fmt.Errorf("No prefix configured for project type %s", checkConfiguration.ProjectType))
85+
}
86+
require.NotEmptyf(t, checkConfiguration.ID, "No check ID defined for check configuration #%v", checkIndex)
87+
assert.Equalf(t, IDPrefix, checkConfiguration.ID[0], "Check ID %s has incorrect prefix for project type %s.", checkConfiguration.ID, checkConfiguration.ProjectType)
88+
}
89+
}
90+
91+
func TestDuplicateCheckID(t *testing.T) {
92+
checkIDMap := make(map[string]bool)
93+
for checkIndex, checkConfiguration := range checkconfigurations.Configurations() {
94+
checkIDMap[checkConfiguration.ID] = true
95+
require.Equalf(t, checkIndex+1, len(checkIDMap), "ID %s of check #%v is a duplicate", checkConfiguration.ID, checkIndex)
96+
}
97+
}

Diff for: check/checkfunctions/checkfunctions.go

+37-37
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,6 @@ import (
3232
// The `output` result is the contextual information that will be inserted into the check's message template.
3333
type Type func() (result checkresult.Type, output string)
3434

35-
// validProjectPathBaseName checks whether the provided library folder or sketch filename contains prohibited characters.
36-
func validProjectPathBaseName(name string) bool {
37-
baseNameRegexp := regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
38-
return baseNameRegexp.MatchString(name)
39-
}
40-
41-
func containsMisspelledPathBaseName(pathList paths.PathList, correctBaseName string, misspellingQuery string) (*paths.Path, bool) {
42-
misspellingRegexp := regexp.MustCompile(misspellingQuery)
43-
for _, path := range pathList {
44-
if path.Base() == correctBaseName {
45-
return nil, false
46-
}
47-
48-
if misspellingRegexp.MatchString(path.Base()) {
49-
return path, true
50-
}
51-
}
52-
53-
return nil, false
54-
}
55-
56-
func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName string) (*paths.Path, bool) {
57-
for _, path := range pathList {
58-
if path.Base() == correctBaseName {
59-
// There was a case-sensitive match (paths package's Exist() is not always case-sensitive, so can't be used here).
60-
return nil, false
61-
}
62-
63-
if strings.EqualFold(path.Base(), correctBaseName) {
64-
// There was a case-insensitive match.
65-
return path, true
66-
}
67-
}
68-
69-
return nil, false
70-
}
71-
7235
// MissingReadme checks if the project has a readme that will be recognized by GitHub.
7336
func MissingReadme() (result checkresult.Type, output string) {
7437
if checkdata.ProjectType() != checkdata.SuperProjectType() {
@@ -138,6 +101,43 @@ func IncorrectArduinoDotHFileNameCase() (result checkresult.Type, output string)
138101
return checkresult.Pass, ""
139102
}
140103

104+
// validProjectPathBaseName checks whether the provided library folder or sketch filename contains prohibited characters.
105+
func validProjectPathBaseName(name string) bool {
106+
baseNameRegexp := regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
107+
return baseNameRegexp.MatchString(name)
108+
}
109+
110+
func containsMisspelledPathBaseName(pathList paths.PathList, correctBaseName string, misspellingQuery string) (*paths.Path, bool) {
111+
misspellingRegexp := regexp.MustCompile(misspellingQuery)
112+
for _, path := range pathList {
113+
if path.Base() == correctBaseName {
114+
return nil, false
115+
}
116+
117+
if misspellingRegexp.MatchString(path.Base()) {
118+
return path, true
119+
}
120+
}
121+
122+
return nil, false
123+
}
124+
125+
func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName string) (*paths.Path, bool) {
126+
for _, path := range pathList {
127+
if path.Base() == correctBaseName {
128+
// There was a case-sensitive match (paths package's Exist() is not always case-sensitive, so can't be used here).
129+
return nil, false
130+
}
131+
132+
if strings.EqualFold(path.Base(), correctBaseName) {
133+
// There was a case-insensitive match.
134+
return path, true
135+
}
136+
}
137+
138+
return nil, false
139+
}
140+
141141
// pathContainsRegexpMatch checks if the provided path contains a file name matching the given regular expression.
142142
func pathContainsRegexpMatch(path *paths.Path, pathRegexp *regexp.Regexp) bool {
143143
listing, err := path.ReadDir()

0 commit comments

Comments
 (0)