Skip to content

Commit 833dae0

Browse files
committed
Add check for incorrect library src subfolder name case
1 parent 0bc964f commit 833dae0

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
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",

Diff for: check/checkfunctions/library.go

+22
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,28 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
10081008
return checkresult.Pass, ""
10091009
}
10101010

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+
10111033
// MisspelledExamplesFolderName checks for incorrectly spelled `examples` folder name.
10121034
func MisspelledExamplesFolderName() (result checkresult.Type, output string) {
10131035
directoryListing, err := checkdata.ProjectPath().ReadDir()

Diff for: check/checkfunctions/library_test.go

+10
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, ""},

Diff for: check/checkfunctions/testdata/libraries/IncorrectSrcFolderNameCase/SRC/IncorrectSrcFolderNameCase.h

Whitespace-only changes.
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

0 commit comments

Comments
 (0)