Skip to content

Commit aae52e3

Browse files
authored
Merge pull request #64 from arduino/per1234/incorrect-extras-folder-name
Add checks on path base name case
2 parents 4cd688c + a1de9e0 commit aae52e3

File tree

12 files changed

+166
-0
lines changed

12 files changed

+166
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+45
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ var configurations = []Type{
101101
ErrorModes: []checkmode.Type{checkmode.Default},
102102
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
103103
},
104+
{
105+
ProjectType: projecttype.Library,
106+
Category: "library.properties",
107+
Subcategory: "general",
108+
ID: "",
109+
Brief: "incorrect library.properties file name case",
110+
Description: `This causes "1.5" format (AKA "recursive layout") libraries to not be recognized on filename case-sensitive operating systems.`,
111+
MessageTemplate: "Incorrect library.properties file name case: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
112+
DisableModes: nil,
113+
EnableModes: []checkmode.Type{checkmode.All},
114+
InfoModes: nil,
115+
WarningModes: nil,
116+
ErrorModes: []checkmode.Type{checkmode.All},
117+
CheckFunction: checkfunctions.IncorrectLibraryPropertiesFileNameCase,
118+
},
104119
{
105120
ProjectType: projecttype.Library,
106121
Category: "library.properties",
@@ -956,6 +971,21 @@ var configurations = []Type{
956971
ErrorModes: []checkmode.Type{checkmode.Default},
957972
CheckFunction: checkfunctions.MisspelledExamplesFolderName,
958973
},
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+
},
959989
{
960990
ProjectType: projecttype.Library,
961991
Category: "structure",
@@ -971,6 +1001,21 @@ var configurations = []Type{
9711001
ErrorModes: nil,
9721002
CheckFunction: checkfunctions.MisspelledExtrasFolderName,
9731003
},
1004+
{
1005+
ProjectType: projecttype.Library,
1006+
Category: "structure",
1007+
Subcategory: "",
1008+
ID: "",
1009+
Brief: "incorrect extras folder name case",
1010+
Description: "",
1011+
MessageTemplate: "Incorrect extras folder name case: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#extra-documentation",
1012+
DisableModes: nil,
1013+
EnableModes: []checkmode.Type{checkmode.All},
1014+
InfoModes: nil,
1015+
WarningModes: []checkmode.Type{checkmode.Permissive},
1016+
ErrorModes: []checkmode.Type{checkmode.Default},
1017+
CheckFunction: checkfunctions.IncorrectExtrasFolderNameCase,
1018+
},
9741019
{
9751020
ProjectType: projecttype.Sketch,
9761021
Category: "structure",

check/checkfunctions/checkfunctions.go

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package checkfunctions
1818

1919
import (
2020
"regexp"
21+
"strings"
2122

2223
"github.com/arduino/arduino-check/check/checkresult"
2324
"github.com/arduino/go-paths-helper"
@@ -47,3 +48,19 @@ func containsMisspelledPathBaseName(pathList paths.PathList, correctBaseName str
4748

4849
return nil, false
4950
}
51+
52+
func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName string) (*paths.Path, bool) {
53+
for _, path := range pathList {
54+
if path.Base() == correctBaseName {
55+
// There was a case-sensitive match (paths package's Exist() is not always case-sensitive, so can't be used here).
56+
return nil, false
57+
}
58+
59+
if strings.EqualFold(path.Base(), correctBaseName) {
60+
// There was a case-insensitive match.
61+
return path, true
62+
}
63+
}
64+
65+
return nil, false
66+
}

check/checkfunctions/library.go

+48
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ func MisspelledLibraryPropertiesFileName() (result checkresult.Type, output stri
6868
return checkresult.Pass, ""
6969
}
7070

71+
// IncorrectLibraryPropertiesFileNameCase checks for incorrect library.properties file name case.
72+
func IncorrectLibraryPropertiesFileNameCase() (result checkresult.Type, output string) {
73+
directoryListing, err := checkdata.ProjectPath().ReadDir()
74+
if err != nil {
75+
panic(err)
76+
}
77+
directoryListing.FilterOutDirs()
78+
79+
path, found := containsIncorrectPathBaseCase(directoryListing, "library.properties")
80+
if found {
81+
return checkresult.Fail, path.String()
82+
}
83+
84+
return checkresult.Pass, ""
85+
}
86+
7187
// LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field.
7288
func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) {
7389
if checkdata.LibraryPropertiesLoadError() != nil {
@@ -1006,6 +1022,22 @@ func MisspelledExamplesFolderName() (result checkresult.Type, output string) {
10061022
return checkresult.Pass, ""
10071023
}
10081024

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+
10091041
// MisspelledExtrasFolderName checks for incorrectly spelled `extras` folder name.
10101042
func MisspelledExtrasFolderName() (result checkresult.Type, output string) {
10111043
directoryListing, err := checkdata.ProjectPath().ReadDir()
@@ -1041,6 +1073,22 @@ func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult
10411073
return checkresult.Pass, ""
10421074
}
10431075

1076+
// IncorrectExtrasFolderNameCase checks for incorrect `extras` folder name case.
1077+
func IncorrectExtrasFolderNameCase() (result checkresult.Type, output string) {
1078+
directoryListing, err := checkdata.ProjectPath().ReadDir()
1079+
if err != nil {
1080+
panic(err)
1081+
}
1082+
directoryListing.FilterDirs()
1083+
1084+
path, found := containsIncorrectPathBaseCase(directoryListing, "extras")
1085+
if found {
1086+
return checkresult.Fail, path.String()
1087+
}
1088+
1089+
return checkresult.Pass, ""
1090+
}
1091+
10441092
// nameInLibraryManagerIndex returns whether there is a library in Library Manager index using the given name.
10451093
func nameInLibraryManagerIndex(name string) bool {
10461094
libraries := checkdata.LibraryManagerIndex()["libraries"].([]interface{})

check/checkfunctions/library_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
7373
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
7474
}
7575

76+
func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {
77+
testTables := []libraryCheckFunctionTestTable{
78+
{"Incorrect", "IncorrectLibraryPropertiesCase", checkresult.Fail, ""},
79+
{"Correct", "Recursive", checkresult.Pass, ""},
80+
}
81+
82+
checkLibraryCheckFunction(IncorrectLibraryPropertiesFileNameCase, testTables, t)
83+
}
84+
7685
func TestLibraryPropertiesMissing(t *testing.T) {
7786
testTables := []libraryCheckFunctionTestTable{
7887
{"Legacy", "Legacy", checkresult.Fail, ""},
@@ -302,6 +311,16 @@ func TestMisspelledExamplesFolderName(t *testing.T) {
302311
checkLibraryCheckFunction(MisspelledExamplesFolderName, testTables, t)
303312
}
304313

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+
305324
func TestMisspelledExtrasFolderName(t *testing.T) {
306325
testTables := []libraryCheckFunctionTestTable{
307326
{"Correctly spelled", "ExtrasFolder", checkresult.Pass, ""},
@@ -311,3 +330,13 @@ func TestMisspelledExtrasFolderName(t *testing.T) {
311330

312331
checkLibraryCheckFunction(MisspelledExtrasFolderName, testTables, t)
313332
}
333+
334+
func TestIncorrectExtrasFolderNameCase(t *testing.T) {
335+
testTables := []libraryCheckFunctionTestTable{
336+
{"Correct case", "ExtrasFolder", checkresult.Pass, ""},
337+
{"Incorrect case", "IncorrectExtrasFolderCase", checkresult.Fail, ""},
338+
{"No extras folder", "Recursive", checkresult.Pass, ""},
339+
}
340+
341+
checkLibraryCheckFunction(IncorrectExtrasFolderNameCase, testTables, t)
342+
}

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.

check/checkfunctions/testdata/libraries/IncorrectExtrasFolderCase/EXTRAS/.gitkeep

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

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

Whitespace-only changes.

0 commit comments

Comments
 (0)