Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7bd821e

Browse files
authored
Merge pull request #67 from arduino/per1234/misspelled-path-checks
Add checks for common misspellings of path base names
2 parents aadcdfa + 8024278 commit 7bd821e

File tree

19 files changed

+188
-0
lines changed

19 files changed

+188
-0
lines changed

‎check/checkconfigurations/checkconfigurations.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ var configurations = []Type{
7171
ErrorModes: []checkmode.Type{checkmode.All},
7272
CheckFunction: checkfunctions.LibraryPropertiesFormat,
7373
},
74+
{
75+
ProjectType: projecttype.Library,
76+
Category: "library.properties",
77+
Subcategory: "general",
78+
ID: "",
79+
Brief: "incorrect library.properties file name",
80+
Description: "",
81+
MessageTemplate: "Incorrectly spelled library.properties file name found: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
82+
DisableModes: nil,
83+
EnableModes: []checkmode.Type{checkmode.All},
84+
InfoModes: nil,
85+
WarningModes: []checkmode.Type{checkmode.Permissive},
86+
ErrorModes: []checkmode.Type{checkmode.Default},
87+
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
88+
},
7489
{
7590
ProjectType: projecttype.Library,
7691
Category: "library.properties",
@@ -911,6 +926,36 @@ var configurations = []Type{
911926
ErrorModes: []checkmode.Type{checkmode.Default},
912927
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
913928
},
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+
},
944+
{
945+
ProjectType: projecttype.Library,
946+
Category: "structure",
947+
Subcategory: "",
948+
ID: "",
949+
Brief: "incorrect extras folder name",
950+
Description: "",
951+
MessageTemplate: "Potentially misspelled extras folder name found: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#extra-documentation",
952+
DisableModes: nil,
953+
EnableModes: []checkmode.Type{checkmode.All},
954+
InfoModes: nil,
955+
WarningModes: []checkmode.Type{checkmode.All},
956+
ErrorModes: nil,
957+
CheckFunction: checkfunctions.MisspelledExtrasFolderName,
958+
},
914959
{
915960
ProjectType: projecttype.Sketch,
916961
Category: "structure",

‎check/checkfunctions/checkfunctions.go‎

Lines changed: 16 additions & 0 deletions
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+
}

‎check/checkfunctions/library.go‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ func LibraryPropertiesFormat() (result checkresult.Type, output string) {
4343
return checkresult.Pass, ""
4444
}
4545

46+
// MisspelledLibraryPropertiesFileName checks for incorrectly spelled library.properties file name.
47+
func MisspelledLibraryPropertiesFileName() (result checkresult.Type, output string) {
48+
directoryListing, err := checkdata.ProjectPath().ReadDir()
49+
if err != nil {
50+
panic(err)
51+
}
52+
directoryListing.FilterOutDirs()
53+
54+
path, found := containsMisspelledPathBaseName(directoryListing, "library.properties", "(?i)^librar(y)|(ie)s?[.-_]?propert(y)|(ie)s?$")
55+
if found {
56+
return checkresult.Fail, path.String()
57+
}
58+
59+
return checkresult.Pass, ""
60+
}
61+
4662
// LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field.
4763
func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) {
4864
if checkdata.LibraryPropertiesLoadError() != nil {
@@ -965,6 +981,38 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
965981
return checkresult.Pass, ""
966982
}
967983

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+
1000+
// MisspelledExtrasFolderName checks for incorrectly spelled `extras` folder name.
1001+
func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
1002+
directoryListing, err := checkdata.ProjectPath().ReadDir()
1003+
if err != nil {
1004+
panic(err)
1005+
}
1006+
directoryListing.FilterDirs()
1007+
1008+
path, found := containsMisspelledPathBaseName(directoryListing, "extras", "(?i)^extra$")
1009+
if found {
1010+
return checkresult.Fail, path.String()
1011+
}
1012+
1013+
return checkresult.Pass, ""
1014+
}
1015+
9681016
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
9691017
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
9701018
if checkdata.LibraryPropertiesLoadError() != nil {

‎check/checkfunctions/library_test.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ func checkLibraryCheckFunction(checkFunction Type, testTables []libraryCheckFunc
6464
}
6565
}
6666

67+
func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
68+
testTables := []libraryCheckFunctionTestTable{
69+
{"Incorrect", "MisspelledLibraryProperties", checkresult.Fail, ""},
70+
{"Correct", "Recursive", checkresult.Pass, ""},
71+
}
72+
73+
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
74+
}
75+
6776
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
6877
testTables := []libraryCheckFunctionTestTable{
6978
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
@@ -272,3 +281,23 @@ func TestLibraryFolderNameGTMaxLength(t *testing.T) {
272281

273282
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
274283
}
284+
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+
295+
func TestMisspelledExtrasFolderName(t *testing.T) {
296+
testTables := []libraryCheckFunctionTestTable{
297+
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
298+
{"Misspelled", "MisspelledExtrasFolder", checkresult.Fail, ""},
299+
{"No extras folder", "Recursive", checkresult.Pass, ""},
300+
}
301+
302+
checkLibraryCheckFunction(MisspelledExtrasFolderName, testTables, t)
303+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ExamplesFolder
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian Maglie <c.maglie@example.com>
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/ExamplesFolder/src/ExamplesFolder.h‎

Whitespace-only changes.

‎check/checkfunctions/testdata/libraries/ExtrasFolder/extras/.gitkeep‎

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ExtrasFolder
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian Maglie <c.maglie@example.com>
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/ExtrasFolder/src/ExtrasFolder.h‎

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /