Skip to content

Commit 9a81479

Browse files
committed
Add check for misspelled library extras folder name
1 parent aadcdfa commit 9a81479

File tree

10 files changed

+75
-0
lines changed

10 files changed

+75
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,21 @@ var configurations = []Type{
911911
ErrorModes: []checkmode.Type{checkmode.Default},
912912
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
913913
},
914+
{
915+
ProjectType: projecttype.Library,
916+
Category: "structure",
917+
Subcategory: "",
918+
ID: "",
919+
Brief: "incorrect extras folder name",
920+
Description: "",
921+
MessageTemplate: "Potentially misspelled extras folder name found: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#extra-documentation",
922+
DisableModes: nil,
923+
EnableModes: []checkmode.Type{checkmode.All},
924+
InfoModes: nil,
925+
WarningModes: []checkmode.Type{checkmode.All},
926+
ErrorModes: nil,
927+
CheckFunction: checkfunctions.MisspelledExtrasFolderName,
928+
},
914929
{
915930
ProjectType: projecttype.Sketch,
916931
Category: "structure",

Diff for: check/checkfunctions/checkfunctions.go

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"regexp"
2121

2222
"github.com/arduino/arduino-check/check/checkresult"
23+
"github.com/arduino/go-paths-helper"
2324
)
2425

2526
// Type is the function signature for the check functions.
@@ -31,3 +32,18 @@ func validProjectPathBaseName(name string) bool {
3132
baseNameRegexp := regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
3233
return baseNameRegexp.MatchString(name)
3334
}
35+
36+
func containsMisspelledPathBaseName(pathList paths.PathList, correctBaseName string, misspellingQuery string) (*paths.Path, bool) {
37+
misspellingRegexp := regexp.MustCompile(misspellingQuery)
38+
for _, path := range pathList {
39+
if path.Base() == correctBaseName {
40+
return nil, false
41+
}
42+
43+
if misspellingRegexp.MatchString(path.Base()) {
44+
return path, true
45+
}
46+
}
47+
48+
return nil, false
49+
}

Diff for: check/checkfunctions/library.go

+16
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,22 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
965965
return checkresult.Pass, ""
966966
}
967967

968+
// MisspelledExtrasFolderName checks for incorrectly spelled `extras` folder name.
969+
func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
970+
directoryListing, err := checkdata.ProjectPath().ReadDir()
971+
if err != nil {
972+
panic(err)
973+
}
974+
directoryListing.FilterDirs()
975+
976+
path, found := containsMisspelledPathBaseName(directoryListing, "extras", "(?i)^extra$")
977+
if found {
978+
return checkresult.Fail, path.String()
979+
}
980+
981+
return checkresult.Pass, ""
982+
}
983+
968984
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
969985
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
970986
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,13 @@ func TestLibraryFolderNameGTMaxLength(t *testing.T) {
272272

273273
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
274274
}
275+
276+
func TestMisspelledExtrasFolderName(t *testing.T) {
277+
testTables := []libraryCheckFunctionTestTable{
278+
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
279+
{"Misspelled", "MisspelledExtrasFolder", checkresult.Fail, ""},
280+
{"No extras folder", "Recursive", checkresult.Pass, ""},
281+
}
282+
283+
checkLibraryCheckFunction(MisspelledExtrasFolderName, testTables, t)
284+
}

Diff for: check/checkfunctions/testdata/libraries/ExtrasFolder/extras/.gitkeep

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

Whitespace-only changes.

Diff for: check/checkfunctions/testdata/libraries/MisspelledExtrasFolder/extra/.gitkeep

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

Whitespace-only changes.

0 commit comments

Comments
 (0)