Skip to content

Commit 857d74b

Browse files
committedDec 15, 2020
Reorder check configurations
During the course of development, the order of the check configurations in the array has become quite random. The checks are run in order of the configurations, so this is exposed to the user, and also makes the code a bit less easy to follow. The check functions and their tests have reordered to match the check configurations.
·
1.3.01.0.0
1 parent 88632d3 commit 857d74b

File tree

6 files changed

+770
-770
lines changed

6 files changed

+770
-770
lines changed
 

‎check/checkconfigurations/checkconfigurations.go

Lines changed: 313 additions & 313 deletions
Large diffs are not rendered by default.

‎check/checkfunctions/checkfunctions.go

Lines changed: 37 additions & 37 deletions
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()

‎check/checkfunctions/library.go

Lines changed: 229 additions & 229 deletions
Large diffs are not rendered by default.

‎check/checkfunctions/library_test.go

Lines changed: 150 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,135 @@ func checkLibraryCheckFunction(checkFunction Type, testTables []libraryCheckFunc
6464
}
6565
}
6666

67-
func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
67+
func TestLibraryInvalid(t *testing.T) {
6868
testTables := []libraryCheckFunctionTestTable{
69-
{"Incorrect", "MisspelledLibraryProperties", checkresult.Fail, ""},
70-
{"Correct", "Recursive", checkresult.Pass, ""},
69+
{"Invalid library.properties", "InvalidLibraryProperties", checkresult.Fail, ""},
70+
{"Invalid flat layout", "FlatWithoutHeader", checkresult.Fail, ""},
71+
{"Invalid recursive layout", "RecursiveWithoutLibraryProperties", checkresult.Fail, ""},
72+
{"Valid library", "Recursive", checkresult.Pass, ""},
7173
}
7274

73-
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
75+
checkLibraryCheckFunction(LibraryInvalid, testTables, t)
7476
}
7577

76-
func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {
78+
func TestLibraryFolderNameGTMaxLength(t *testing.T) {
7779
testTables := []libraryCheckFunctionTestTable{
78-
{"Incorrect", "IncorrectLibraryPropertiesCase", checkresult.Fail, ""},
79-
{"Correct", "Recursive", checkresult.Pass, ""},
80+
{"Has folder name > max length", "FolderNameTooLong12345678901234567890123456789012345678901234567890", checkresult.Fail, "^FolderNameTooLong12345678901234567890123456789012345678901234567890$"},
81+
{"Folder name <= max length", "Recursive", checkresult.Pass, ""},
8082
}
8183

82-
checkLibraryCheckFunction(IncorrectLibraryPropertiesFileNameCase, testTables, t)
84+
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
85+
}
86+
87+
func TestProhibitedCharactersInLibraryFolderName(t *testing.T) {
88+
testTables := []libraryCheckFunctionTestTable{
89+
{"Has prohibited characters", "Prohibited CharactersInFolderName", checkresult.Fail, ""},
90+
{"No prohibited characters", "Recursive", checkresult.Pass, ""},
91+
}
92+
93+
checkLibraryCheckFunction(ProhibitedCharactersInLibraryFolderName, testTables, t)
94+
}
95+
96+
func TestLibraryHasSubmodule(t *testing.T) {
97+
testTables := []libraryCheckFunctionTestTable{
98+
{"Has submodule", "Submodule", checkresult.Fail, ""},
99+
{"No submodule", "Recursive", checkresult.Pass, ""},
100+
}
101+
102+
checkLibraryCheckFunction(LibraryHasSubmodule, testTables, t)
103+
}
104+
105+
func TestLibraryContainsSymlinks(t *testing.T) {
106+
testLibrary := "Recursive"
107+
symlinkPath := librariesTestDataPath.Join(testLibrary, "test-symlink")
108+
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
109+
err := os.Symlink(librariesTestDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
110+
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
111+
defer symlinkPath.RemoveAll() // clean up
112+
113+
testTables := []libraryCheckFunctionTestTable{
114+
{"Has symlink", testLibrary, checkresult.Fail, ""},
115+
}
116+
117+
checkLibraryCheckFunction(LibraryContainsSymlinks, testTables, t)
118+
119+
err = symlinkPath.RemoveAll()
120+
require.Nil(t, err)
121+
122+
testTables = []libraryCheckFunctionTestTable{
123+
{"No symlink", testLibrary, checkresult.Pass, ""},
124+
}
125+
126+
checkLibraryCheckFunction(LibraryContainsSymlinks, testTables, t)
127+
}
128+
129+
func TestLibraryHasDotDevelopmentFile(t *testing.T) {
130+
testTables := []libraryCheckFunctionTestTable{
131+
{"Has .development file", "DotDevelopment", checkresult.Fail, ""},
132+
{"No .development file", "Recursive", checkresult.Pass, ""},
133+
}
134+
135+
checkLibraryCheckFunction(LibraryHasDotDevelopmentFile, testTables, t)
136+
}
137+
138+
func TestLibraryHasExe(t *testing.T) {
139+
testTables := []libraryCheckFunctionTestTable{
140+
{"Has .exe file", "Exe", checkresult.Fail, ""},
141+
{"No .exe files", "Recursive", checkresult.Pass, ""},
142+
}
143+
144+
checkLibraryCheckFunction(LibraryHasExe, testTables, t)
145+
}
146+
147+
func TestLibraryPropertiesNameFieldHeaderMismatch(t *testing.T) {
148+
testTables := []libraryCheckFunctionTestTable{
149+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
150+
{"Mismatch", "NameHeaderMismatch", checkresult.Fail, "^NameHeaderMismatch.h$"},
151+
{"Match", "Recursive", checkresult.Pass, ""},
152+
}
153+
154+
checkLibraryCheckFunction(LibraryPropertiesNameFieldHeaderMismatch, testTables, t)
155+
}
156+
157+
func TestIncorrectLibrarySrcFolderNameCase(t *testing.T) {
158+
testTables := []libraryCheckFunctionTestTable{
159+
{"Flat, not precompiled", "Flat", checkresult.Skip, ""},
160+
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
161+
{"Correct case", "Recursive", checkresult.Pass, ""},
162+
}
163+
164+
checkLibraryCheckFunction(IncorrectLibrarySrcFolderNameCase, testTables, t)
165+
}
166+
167+
func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
168+
testTables := []libraryCheckFunctionTestTable{
169+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
170+
{"Flat", "Flat", checkresult.Skip, ""},
171+
{"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""},
172+
{"Recursive without utility", "Recursive", checkresult.Pass, ""},
173+
}
174+
175+
checkLibraryCheckFunction(RecursiveLibraryWithUtilityFolder, testTables, t)
176+
}
177+
178+
func TestMisspelledExtrasFolderName(t *testing.T) {
179+
testTables := []libraryCheckFunctionTestTable{
180+
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
181+
{"Misspelled", "MisspelledExtrasFolder", checkresult.Fail, ""},
182+
{"No extras folder", "Recursive", checkresult.Pass, ""},
183+
}
184+
185+
checkLibraryCheckFunction(MisspelledExtrasFolderName, testTables, t)
186+
}
187+
188+
func TestIncorrectExtrasFolderNameCase(t *testing.T) {
189+
testTables := []libraryCheckFunctionTestTable{
190+
{"Correct case", "ExtrasFolder", checkresult.Pass, ""},
191+
{"Incorrect case", "IncorrectExtrasFolderCase", checkresult.Fail, ""},
192+
{"No extras folder", "Recursive", checkresult.Pass, ""},
193+
}
194+
195+
checkLibraryCheckFunction(IncorrectExtrasFolderNameCase, testTables, t)
83196
}
84197

85198
func TestLibraryPropertiesMissing(t *testing.T) {
@@ -93,6 +206,24 @@ func TestLibraryPropertiesMissing(t *testing.T) {
93206
checkLibraryCheckFunction(LibraryPropertiesMissing, testTables, t)
94207
}
95208

209+
func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
210+
testTables := []libraryCheckFunctionTestTable{
211+
{"Incorrect", "MisspelledLibraryProperties", checkresult.Fail, ""},
212+
{"Correct", "Recursive", checkresult.Pass, ""},
213+
}
214+
215+
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
216+
}
217+
218+
func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {
219+
testTables := []libraryCheckFunctionTestTable{
220+
{"Incorrect", "IncorrectLibraryPropertiesCase", checkresult.Fail, ""},
221+
{"Correct", "Recursive", checkresult.Pass, ""},
222+
}
223+
224+
checkLibraryCheckFunction(IncorrectLibraryPropertiesFileNameCase, testTables, t)
225+
}
226+
96227
func TestRedundantLibraryProperties(t *testing.T) {
97228
testTables := []libraryCheckFunctionTestTable{
98229
{"Redundant", "RedundantLibraryProperties", checkresult.Fail, ""},
@@ -143,16 +274,6 @@ func TestLibraryPropertiesNameFieldNotInIndex(t *testing.T) {
143274
checkLibraryCheckFunction(LibraryPropertiesNameFieldNotInIndex, testTables, t)
144275
}
145276

146-
func TestLibraryPropertiesNameFieldHeaderMismatch(t *testing.T) {
147-
testTables := []libraryCheckFunctionTestTable{
148-
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
149-
{"Mismatch", "NameHeaderMismatch", checkresult.Fail, "^NameHeaderMismatch.h$"},
150-
{"Match", "Recursive", checkresult.Pass, ""},
151-
}
152-
153-
checkLibraryCheckFunction(LibraryPropertiesNameFieldHeaderMismatch, testTables, t)
154-
}
155-
156277
func TestLibraryPropertiesVersionFieldBehindTag(t *testing.T) {
157278
// Set up the test repository folders.
158279
TagPrereleaseGreaterPath := librariesTestDataPath.Join("TagPrereleaseGreater")
@@ -257,6 +378,17 @@ func TestLibraryPropertiesVersionFieldBehindTag(t *testing.T) {
257378
checkLibraryCheckFunction(LibraryPropertiesVersionFieldBehindTag, testTables, t)
258379
}
259380

381+
func TestLibraryPropertiesEmailFieldAsMaintainerAlias(t *testing.T) {
382+
testTables := []libraryCheckFunctionTestTable{
383+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
384+
{"No email field", "MissingFields", checkresult.Skip, ""},
385+
{"email in place of maintainer", "EmailOnly", checkresult.Fail, ""},
386+
{"email and maintainer", "EmailAndMaintainer", checkresult.Pass, ""},
387+
}
388+
389+
checkLibraryCheckFunction(LibraryPropertiesEmailFieldAsMaintainerAlias, testTables, t)
390+
}
391+
260392
func TestLibraryPropertiesSentenceFieldSpellCheck(t *testing.T) {
261393
testTables := []libraryCheckFunctionTestTable{
262394
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
@@ -281,17 +413,6 @@ func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) {
281413
checkLibraryCheckFunction(LibraryPropertiesParagraphFieldSpellCheck, testTables, t)
282414
}
283415

284-
func TestLibraryPropertiesEmailFieldAsMaintainerAlias(t *testing.T) {
285-
testTables := []libraryCheckFunctionTestTable{
286-
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
287-
{"No email field", "MissingFields", checkresult.Skip, ""},
288-
{"email in place of maintainer", "EmailOnly", checkresult.Fail, ""},
289-
{"email and maintainer", "EmailAndMaintainer", checkresult.Pass, ""},
290-
}
291-
292-
checkLibraryCheckFunction(LibraryPropertiesEmailFieldAsMaintainerAlias, testTables, t)
293-
}
294-
295416
func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) {
296417
testTables := []libraryCheckFunctionTestTable{
297418
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
@@ -396,68 +517,6 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
396517
checkLibraryCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)
397518
}
398519

399-
func TestLibraryInvalid(t *testing.T) {
400-
testTables := []libraryCheckFunctionTestTable{
401-
{"Invalid library.properties", "InvalidLibraryProperties", checkresult.Fail, ""},
402-
{"Invalid flat layout", "FlatWithoutHeader", checkresult.Fail, ""},
403-
{"Invalid recursive layout", "RecursiveWithoutLibraryProperties", checkresult.Fail, ""},
404-
{"Valid library", "Recursive", checkresult.Pass, ""},
405-
}
406-
407-
checkLibraryCheckFunction(LibraryInvalid, testTables, t)
408-
}
409-
410-
func TestLibraryHasSubmodule(t *testing.T) {
411-
testTables := []libraryCheckFunctionTestTable{
412-
{"Has submodule", "Submodule", checkresult.Fail, ""},
413-
{"No submodule", "Recursive", checkresult.Pass, ""},
414-
}
415-
416-
checkLibraryCheckFunction(LibraryHasSubmodule, testTables, t)
417-
}
418-
419-
func TestLibraryContainsSymlinks(t *testing.T) {
420-
testLibrary := "Recursive"
421-
symlinkPath := librariesTestDataPath.Join(testLibrary, "test-symlink")
422-
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
423-
err := os.Symlink(librariesTestDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
424-
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
425-
defer symlinkPath.RemoveAll() // clean up
426-
427-
testTables := []libraryCheckFunctionTestTable{
428-
{"Has symlink", testLibrary, checkresult.Fail, ""},
429-
}
430-
431-
checkLibraryCheckFunction(LibraryContainsSymlinks, testTables, t)
432-
433-
err = symlinkPath.RemoveAll()
434-
require.Nil(t, err)
435-
436-
testTables = []libraryCheckFunctionTestTable{
437-
{"No symlink", testLibrary, checkresult.Pass, ""},
438-
}
439-
440-
checkLibraryCheckFunction(LibraryContainsSymlinks, testTables, t)
441-
}
442-
443-
func TestLibraryHasDotDevelopmentFile(t *testing.T) {
444-
testTables := []libraryCheckFunctionTestTable{
445-
{"Has .development file", "DotDevelopment", checkresult.Fail, ""},
446-
{"No .development file", "Recursive", checkresult.Pass, ""},
447-
}
448-
449-
checkLibraryCheckFunction(LibraryHasDotDevelopmentFile, testTables, t)
450-
}
451-
452-
func TestLibraryHasExe(t *testing.T) {
453-
testTables := []libraryCheckFunctionTestTable{
454-
{"Has .exe file", "Exe", checkresult.Fail, ""},
455-
{"No .exe files", "Recursive", checkresult.Pass, ""},
456-
}
457-
458-
checkLibraryCheckFunction(LibraryHasExe, testTables, t)
459-
}
460-
461520
func TestLibraryHasStraySketches(t *testing.T) {
462521
testTables := []libraryCheckFunctionTestTable{
463522
{"Sketch in root", "SketchInRoot", checkresult.Fail, ""},
@@ -469,34 +528,6 @@ func TestLibraryHasStraySketches(t *testing.T) {
469528
checkLibraryCheckFunction(LibraryHasStraySketches, testTables, t)
470529
}
471530

472-
func TestProhibitedCharactersInLibraryFolderName(t *testing.T) {
473-
testTables := []libraryCheckFunctionTestTable{
474-
{"Has prohibited characters", "Prohibited CharactersInFolderName", checkresult.Fail, ""},
475-
{"No prohibited characters", "Recursive", checkresult.Pass, ""},
476-
}
477-
478-
checkLibraryCheckFunction(ProhibitedCharactersInLibraryFolderName, testTables, t)
479-
}
480-
481-
func TestLibraryFolderNameGTMaxLength(t *testing.T) {
482-
testTables := []libraryCheckFunctionTestTable{
483-
{"Has folder name > max length", "FolderNameTooLong12345678901234567890123456789012345678901234567890", checkresult.Fail, "^FolderNameTooLong12345678901234567890123456789012345678901234567890$"},
484-
{"Folder name <= max length", "Recursive", checkresult.Pass, ""},
485-
}
486-
487-
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
488-
}
489-
490-
func TestIncorrectLibrarySrcFolderNameCase(t *testing.T) {
491-
testTables := []libraryCheckFunctionTestTable{
492-
{"Flat, not precompiled", "Flat", checkresult.Skip, ""},
493-
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
494-
{"Correct case", "Recursive", checkresult.Pass, ""},
495-
}
496-
497-
checkLibraryCheckFunction(IncorrectLibrarySrcFolderNameCase, testTables, t)
498-
}
499-
500531
func TestMissingExamples(t *testing.T) {
501532
testTables := []libraryCheckFunctionTestTable{
502533
{"Has examples", "ExamplesFolder", checkresult.Pass, ""},
@@ -526,34 +557,3 @@ func TestIncorrectExamplesFolderNameCase(t *testing.T) {
526557

527558
checkLibraryCheckFunction(IncorrectExamplesFolderNameCase, testTables, t)
528559
}
529-
530-
func TestMisspelledExtrasFolderName(t *testing.T) {
531-
testTables := []libraryCheckFunctionTestTable{
532-
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
533-
{"Misspelled", "MisspelledExtrasFolder", checkresult.Fail, ""},
534-
{"No extras folder", "Recursive", checkresult.Pass, ""},
535-
}
536-
537-
checkLibraryCheckFunction(MisspelledExtrasFolderName, testTables, t)
538-
}
539-
540-
func TestIncorrectExtrasFolderNameCase(t *testing.T) {
541-
testTables := []libraryCheckFunctionTestTable{
542-
{"Correct case", "ExtrasFolder", checkresult.Pass, ""},
543-
{"Incorrect case", "IncorrectExtrasFolderCase", checkresult.Fail, ""},
544-
{"No extras folder", "Recursive", checkresult.Pass, ""},
545-
}
546-
547-
checkLibraryCheckFunction(IncorrectExtrasFolderNameCase, testTables, t)
548-
}
549-
550-
func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
551-
testTables := []libraryCheckFunctionTestTable{
552-
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
553-
{"Flat", "Flat", checkresult.Skip, ""},
554-
{"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""},
555-
{"Recursive without utility", "Recursive", checkresult.Pass, ""},
556-
}
557-
558-
checkLibraryCheckFunction(RecursiveLibraryWithUtilityFolder, testTables, t)
559-
}

‎check/checkfunctions/sketch.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ import (
2626
"github.com/arduino/arduino-lint/project/sketch"
2727
)
2828

29-
// IncorrectSketchSrcFolderNameCase checks for incorrect case of src subfolder name in recursive format libraries.
30-
func IncorrectSketchSrcFolderNameCase() (result checkresult.Type, output string) {
31-
directoryListing, err := checkdata.ProjectPath().ReadDir()
32-
if err != nil {
33-
panic(err)
34-
}
35-
directoryListing.FilterDirs()
29+
// SketchNameMismatch checks for mismatch between sketch folder name and primary file name.
30+
func SketchNameMismatch() (result checkresult.Type, output string) {
31+
for extension := range globals.MainFileValidExtensions {
32+
validPrimarySketchFilePath := checkdata.ProjectPath().Join(checkdata.ProjectPath().Base() + extension)
33+
exist, err := validPrimarySketchFilePath.ExistCheck()
34+
if err != nil {
35+
panic(err)
36+
}
3637

37-
path, found := containsIncorrectPathBaseCase(directoryListing, "src")
38-
if found {
39-
return checkresult.Fail, path.String()
38+
if exist {
39+
return checkresult.Pass, ""
40+
}
4041
}
4142

42-
return checkresult.Pass, ""
43+
return checkresult.Fail, checkdata.ProjectPath().Base() + ".ino"
4344
}
4445

4546
// ProhibitedCharactersInSketchFileName checks for prohibited characters in the sketch file names.
@@ -102,6 +103,22 @@ func PdeSketchExtension() (result checkresult.Type, output string) {
102103
return checkresult.Pass, ""
103104
}
104105

106+
// IncorrectSketchSrcFolderNameCase checks for incorrect case of src subfolder name in recursive format libraries.
107+
func IncorrectSketchSrcFolderNameCase() (result checkresult.Type, output string) {
108+
directoryListing, err := checkdata.ProjectPath().ReadDir()
109+
if err != nil {
110+
panic(err)
111+
}
112+
directoryListing.FilterDirs()
113+
114+
path, found := containsIncorrectPathBaseCase(directoryListing, "src")
115+
if found {
116+
return checkresult.Fail, path.String()
117+
}
118+
119+
return checkresult.Pass, ""
120+
}
121+
105122
// SketchDotJSONJSONFormat checks whether the sketch.json metadata file is a valid JSON document.
106123
func SketchDotJSONJSONFormat() (result checkresult.Type, output string) {
107124
metadataPath := sketch.MetadataPath(checkdata.ProjectPath())
@@ -129,20 +146,3 @@ func SketchDotJSONFormat() (result checkresult.Type, output string) {
129146

130147
return checkresult.Fail, checkdata.MetadataLoadError().Error()
131148
}
132-
133-
// SketchNameMismatch checks for mismatch between sketch folder name and primary file name.
134-
func SketchNameMismatch() (result checkresult.Type, output string) {
135-
for extension := range globals.MainFileValidExtensions {
136-
validPrimarySketchFilePath := checkdata.ProjectPath().Join(checkdata.ProjectPath().Base() + extension)
137-
exist, err := validPrimarySketchFilePath.ExistCheck()
138-
if err != nil {
139-
panic(err)
140-
}
141-
142-
if exist {
143-
return checkresult.Pass, ""
144-
}
145-
}
146-
147-
return checkresult.Fail, checkdata.ProjectPath().Base() + ".ino"
148-
}

‎check/checkfunctions/sketch_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func checkSketchCheckFunction(checkFunction Type, testTables []sketchCheckFuncti
6060
}
6161
}
6262

63-
func TestIncorrectSketchSrcFolderNameCase(t *testing.T) {
63+
func TestSketchNameMismatch(t *testing.T) {
6464
testTables := []sketchCheckFunctionTestTable{
65-
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
66-
{"Correct case", "Valid", checkresult.Pass, ""},
65+
{"Valid", "Valid", checkresult.Pass, ""},
66+
{"Mismatch", "NameMismatch", checkresult.Fail, ""},
6767
}
6868

69-
checkSketchCheckFunction(IncorrectSketchSrcFolderNameCase, testTables, t)
69+
checkSketchCheckFunction(SketchNameMismatch, testTables, t)
7070
}
7171

7272
func TestProhibitedCharactersInSketchFileName(t *testing.T) {
@@ -96,6 +96,15 @@ func TestPdeSketchExtension(t *testing.T) {
9696
checkSketchCheckFunction(PdeSketchExtension, testTables, t)
9797
}
9898

99+
func TestIncorrectSketchSrcFolderNameCase(t *testing.T) {
100+
testTables := []sketchCheckFunctionTestTable{
101+
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
102+
{"Correct case", "Valid", checkresult.Pass, ""},
103+
}
104+
105+
checkSketchCheckFunction(IncorrectSketchSrcFolderNameCase, testTables, t)
106+
}
107+
99108
func TestSketchDotJSONJSONFormat(t *testing.T) {
100109
testTables := []sketchCheckFunctionTestTable{
101110
{"No metadata file", "NoMetadataFile", checkresult.Skip, ""},
@@ -116,12 +125,3 @@ func TestSketchDotJSONFormat(t *testing.T) {
116125

117126
checkSketchCheckFunction(SketchDotJSONFormat, testTables, t)
118127
}
119-
120-
func TestSketchNameMismatch(t *testing.T) {
121-
testTables := []sketchCheckFunctionTestTable{
122-
{"Valid", "Valid", checkresult.Pass, ""},
123-
{"Mismatch", "NameMismatch", checkresult.Fail, ""},
124-
}
125-
126-
checkSketchCheckFunction(SketchNameMismatch, testTables, t)
127-
}

0 commit comments

Comments
 (0)
Please sign in to comment.