Skip to content

Commit 0b0292d

Browse files
authored
Merge pull request #77 from arduino/per1234/src-incorrect-case-check
Add checks for incorrect src subfolder name case
2 parents c65d0cc + 0bcb1ff commit 0b0292d

File tree

17 files changed

+193
-10
lines changed

17 files changed

+193
-10
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,21 @@ var configurations = []Type{
971971
ErrorModes: []checkmode.Type{checkmode.Default},
972972
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
973973
},
974+
{
975+
ProjectType: projecttype.Library,
976+
Category: "structure",
977+
Subcategory: "",
978+
ID: "",
979+
Brief: "incorrect src folder case",
980+
Description: "",
981+
MessageTemplate: "Incorrect src folder case. This will cause the library to not be recognized on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-root-folder",
982+
DisableModes: nil,
983+
EnableModes: []checkmode.Type{checkmode.Default},
984+
InfoModes: nil,
985+
WarningModes: nil,
986+
ErrorModes: []checkmode.Type{checkmode.Default},
987+
CheckFunction: checkfunctions.IncorrectLibrarySrcFolderNameCase,
988+
},
974989
{
975990
ProjectType: projecttype.Library,
976991
Category: "structure",
@@ -1046,6 +1061,21 @@ var configurations = []Type{
10461061
ErrorModes: []checkmode.Type{checkmode.Default},
10471062
CheckFunction: checkfunctions.RecursiveLibraryWithUtilityFolder,
10481063
},
1064+
{
1065+
ProjectType: projecttype.Sketch,
1066+
Category: "structure",
1067+
Subcategory: "",
1068+
ID: "",
1069+
Brief: "incorrect src folder case",
1070+
Description: "",
1071+
MessageTemplate: "Incorrect src folder case. This will cause the source files under it to not be compiled on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/sketch-specification/#src-subfolder",
1072+
DisableModes: nil,
1073+
EnableModes: []checkmode.Type{checkmode.Default},
1074+
InfoModes: nil,
1075+
WarningModes: []checkmode.Type{checkmode.Default},
1076+
ErrorModes: []checkmode.Type{checkmode.Strict},
1077+
CheckFunction: checkfunctions.IncorrectSketchSrcFolderNameCase,
1078+
},
10491079
{
10501080
ProjectType: projecttype.Sketch,
10511081
Category: "structure",

check/checkfunctions/library.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -904,16 +904,8 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output
904904

905905
// LibraryInvalid checks whether the provided path is a valid library.
906906
func LibraryInvalid() (result checkresult.Type, output string) {
907-
directoryListing, err := checkdata.LoadedLibrary().SourceDir.ReadDir()
908-
if err != nil {
909-
panic(err)
910-
}
911-
912-
directoryListing.FilterOutDirs()
913-
for _, potentialHeaderFile := range directoryListing {
914-
if library.HasHeaderFileValidExtension(potentialHeaderFile) {
915-
return checkresult.Pass, ""
916-
}
907+
if library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) {
908+
return checkresult.Pass, ""
917909
}
918910

919911
return checkresult.Fail, ""
@@ -1016,6 +1008,28 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
10161008
return checkresult.Pass, ""
10171009
}
10181010

1011+
// IncorrectLibrarySrcFolderNameCase checks for incorrect case of src subfolder name in recursive format libraries.
1012+
func IncorrectLibrarySrcFolderNameCase() (result checkresult.Type, output string) {
1013+
if library.ContainsMetadataFile(checkdata.ProjectPath()) && library.ContainsHeaderFile(checkdata.ProjectPath()) {
1014+
// Flat layout, so no special treatment of src subfolder.
1015+
return checkresult.NotRun, ""
1016+
}
1017+
1018+
// The library is intended to have the recursive layout.
1019+
directoryListing, err := checkdata.ProjectPath().ReadDir()
1020+
if err != nil {
1021+
panic(err)
1022+
}
1023+
directoryListing.FilterDirs()
1024+
1025+
path, found := containsIncorrectPathBaseCase(directoryListing, "src")
1026+
if found {
1027+
return checkresult.Fail, path.String()
1028+
}
1029+
1030+
return checkresult.Pass, ""
1031+
}
1032+
10191033
// MisspelledExamplesFolderName checks for incorrectly spelled `examples` folder name.
10201034
func MisspelledExamplesFolderName() (result checkresult.Type, output string) {
10211035
directoryListing, err := checkdata.ProjectPath().ReadDir()

check/checkfunctions/library_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ func TestLibraryFolderNameGTMaxLength(t *testing.T) {
310310
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
311311
}
312312

313+
func TestIncorrectLibrarySrcFolderNameCase(t *testing.T) {
314+
testTables := []libraryCheckFunctionTestTable{
315+
{"Flat, not precompiled", "Flat", checkresult.NotRun, ""},
316+
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
317+
{"Correct case", "Recursive", checkresult.Pass, ""},
318+
}
319+
320+
checkLibraryCheckFunction(IncorrectLibrarySrcFolderNameCase, testTables, t)
321+
}
322+
313323
func TestMisspelledExamplesFolderName(t *testing.T) {
314324
testTables := []libraryCheckFunctionTestTable{
315325
{"Correctly spelled", "ExamplesFolder", checkresult.Pass, ""},

check/checkfunctions/sketch.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ import (
2525
"github.com/arduino/arduino-check/project/sketch"
2626
)
2727

28+
// IncorrectSketchSrcFolderNameCase checks for incorrect case of src subfolder name in recursive format libraries.
29+
func IncorrectSketchSrcFolderNameCase() (result checkresult.Type, output string) {
30+
directoryListing, err := checkdata.ProjectPath().ReadDir()
31+
if err != nil {
32+
panic(err)
33+
}
34+
directoryListing.FilterDirs()
35+
36+
path, found := containsIncorrectPathBaseCase(directoryListing, "src")
37+
if found {
38+
return checkresult.Fail, path.String()
39+
}
40+
41+
return checkresult.Pass, ""
42+
}
43+
2844
// ProhibitedCharactersInSketchFileName checks for prohibited characters in the sketch file names.
2945
func ProhibitedCharactersInSketchFileName() (result checkresult.Type, output string) {
3046
directoryListing, _ := checkdata.ProjectPath().ReadDir()

check/checkfunctions/sketch_test.go

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

63+
func TestIncorrectSketchSrcFolderNameCase(t *testing.T) {
64+
testTables := []sketchCheckFunctionTestTable{
65+
{"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""},
66+
{"Correct case", "Valid", checkresult.Pass, ""},
67+
}
68+
69+
checkSketchCheckFunction(IncorrectSketchSrcFolderNameCase, testTables, t)
70+
}
71+
6372
func TestProhibitedCharactersInSketchFileName(t *testing.T) {
6473
testTables := []sketchCheckFunctionTestTable{
6574
{"Has prohibited characters", "ProhibitedCharactersInFileName", checkresult.Fail, "^Prohibited CharactersInFileName.h$"},

check/checkfunctions/testdata/libraries/IncorrectSrcFolderNameCase/SRC/IncorrectSrcFolderNameCase.h

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=IncorrectSrcFolderNameCase
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

check/checkfunctions/testdata/sketches/IncorrectSrcFolderNameCase/SRC/src.cpp

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

0 commit comments

Comments
 (0)