Skip to content

Commit c435fea

Browse files
committed
Add check for incorrect library examples folder name case
1 parent ba874d0 commit c435fea

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

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.MisspelledExamplesFolderName,
973973
},
974+
{
975+
ProjectType: projecttype.Library,
976+
Category: "structure",
977+
Subcategory: "",
978+
ID: "",
979+
Brief: "incorrect examples folder name case",
980+
Description: "",
981+
MessageTemplate: "Incorrect examples folder name case: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-examples",
982+
DisableModes: nil,
983+
EnableModes: []checkmode.Type{checkmode.All},
984+
InfoModes: nil,
985+
WarningModes: []checkmode.Type{checkmode.Permissive},
986+
ErrorModes: []checkmode.Type{checkmode.Default},
987+
CheckFunction: checkfunctions.IncorrectExamplesFolderNameCase,
988+
},
974989
{
975990
ProjectType: projecttype.Library,
976991
Category: "structure",

check/checkfunctions/library.go

+16
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,22 @@ func MisspelledExamplesFolderName() (result checkresult.Type, output string) {
10221022
return checkresult.Pass, ""
10231023
}
10241024

1025+
// IncorrectExamplesFolderNameCase checks for incorrect `examples` folder name case.
1026+
func IncorrectExamplesFolderNameCase() (result checkresult.Type, output string) {
1027+
directoryListing, err := checkdata.ProjectPath().ReadDir()
1028+
if err != nil {
1029+
panic(err)
1030+
}
1031+
directoryListing.FilterDirs()
1032+
1033+
path, found := containsIncorrectPathBaseCase(directoryListing, "examples")
1034+
if found {
1035+
return checkresult.Fail, path.String()
1036+
}
1037+
1038+
return checkresult.Pass, ""
1039+
}
1040+
10251041
// MisspelledExtrasFolderName checks for incorrectly spelled `extras` folder name.
10261042
func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
10271043
directoryListing, err := checkdata.ProjectPath().ReadDir()

check/checkfunctions/library_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ func TestMisspelledExamplesFolderName(t *testing.T) {
311311
checkLibraryCheckFunction(MisspelledExamplesFolderName, testTables, t)
312312
}
313313

314+
func TestIncorrectExamplesFolderNameCase(t *testing.T) {
315+
testTables := []libraryCheckFunctionTestTable{
316+
{"Correct case", "ExamplesFolder", checkresult.Pass, ""},
317+
{"Incorrect case", "IncorrectExamplesFolderCase", checkresult.Fail, ""},
318+
{"No examples folder", "Recursive", checkresult.Pass, ""},
319+
}
320+
321+
checkLibraryCheckFunction(IncorrectExamplesFolderNameCase, testTables, t)
322+
}
323+
314324
func TestMisspelledExtrasFolderName(t *testing.T) {
315325
testTables := []libraryCheckFunctionTestTable{
316326
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},

check/checkfunctions/testdata/libraries/IncorrectExamplesFolderCase/Examples/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=IncorrectExamplesFolderCase
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

check/checkfunctions/testdata/libraries/IncorrectExamplesFolderCase/src/IncorrectExamplesFolderCase.h

Whitespace-only changes.

0 commit comments

Comments
 (0)