Skip to content

Commit 8024278

Browse files
committed
Add check for misspelled library examples folder name
1 parent 977048e commit 8024278

File tree

9 files changed

+63
-0
lines changed

9 files changed

+63
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,21 @@ var configurations = []Type{
926926
ErrorModes: []checkmode.Type{checkmode.Default},
927927
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
928928
},
929+
{
930+
ProjectType: projecttype.Library,
931+
Category: "structure",
932+
Subcategory: "",
933+
ID: "",
934+
Brief: "incorrect examples folder name",
935+
Description: "",
936+
MessageTemplate: "Potentially misspelled examples folder name found: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-examples",
937+
DisableModes: nil,
938+
EnableModes: []checkmode.Type{checkmode.All},
939+
InfoModes: nil,
940+
WarningModes: []checkmode.Type{checkmode.Permissive},
941+
ErrorModes: []checkmode.Type{checkmode.Default},
942+
CheckFunction: checkfunctions.MisspelledExamplesFolderName,
943+
},
929944
{
930945
ProjectType: projecttype.Library,
931946
Category: "structure",

Diff for: check/checkfunctions/library.go

+16
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,22 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
981981
return checkresult.Pass, ""
982982
}
983983

984+
// MisspelledExamplesFolderName checks for incorrectly spelled `examples` folder name.
985+
func MisspelledExamplesFolderName() (result checkresult.Type, output string) {
986+
directoryListing, err := checkdata.ProjectPath().ReadDir()
987+
if err != nil {
988+
panic(err)
989+
}
990+
directoryListing.FilterDirs()
991+
992+
path, found := containsMisspelledPathBaseName(directoryListing, "examples", "(?i)^e((x)|(xs)|(s))((am)|(ma))p((le)|(el))s?$")
993+
if found {
994+
return checkresult.Fail, path.String()
995+
}
996+
997+
return checkresult.Pass, ""
998+
}
999+
9841000
// MisspelledExtrasFolderName checks for incorrectly spelled `extras` folder name.
9851001
func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
9861002
directoryListing, err := checkdata.ProjectPath().ReadDir()

Diff for: check/checkfunctions/library_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ func TestLibraryFolderNameGTMaxLength(t *testing.T) {
282282
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
283283
}
284284

285+
func TestMisspelledExamplesFolderName(t *testing.T) {
286+
testTables := []libraryCheckFunctionTestTable{
287+
{"Correctly spelled", "ExamplesFolder", checkresult.Pass, ""},
288+
{"Misspelled", "MisspelledExamplesFolder", checkresult.Fail, ""},
289+
{"No examples folder", "Recursive", checkresult.Pass, ""},
290+
}
291+
292+
checkLibraryCheckFunction(MisspelledExamplesFolderName, testTables, t)
293+
}
294+
285295
func TestMisspelledExtrasFolderName(t *testing.T) {
286296
testTables := []libraryCheckFunctionTestTable{
287297
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ExamplesFolder
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

Diff for: check/checkfunctions/testdata/libraries/ExamplesFolder/src/ExamplesFolder.h

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=MisspelledExamplesFolder
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

Diff for: check/checkfunctions/testdata/libraries/MisspelledExamplesFolder/src/MisspelledExamplesFolder.h

Whitespace-only changes.

0 commit comments

Comments
 (0)