Skip to content

Commit 92905dd

Browse files
committed
Add check for incorrect library.properties architecture case
1 parent 34d81b4 commit 92905dd

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,21 @@ var configurations = []Type{
731731
ErrorModes: []checkmode.Type{checkmode.Strict},
732732
CheckFunction: checkfunctions.LibraryPropertiesArchitecturesFieldSoloAlias,
733733
},
734+
{
735+
ProjectType: projecttype.Library,
736+
Category: "library.properties",
737+
Subcategory: "architectures field",
738+
ID: "",
739+
Brief: "miscased architecture",
740+
Description: "",
741+
MessageTemplate: "Incorrect case of library.properties architectures field item(s): {{.}}. Architectures are case sensitive. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
742+
DisableModes: nil,
743+
EnableModes: []checkmode.Type{checkmode.Default},
744+
InfoModes: nil,
745+
WarningModes: []checkmode.Type{checkmode.Default},
746+
ErrorModes: []checkmode.Type{checkmode.Strict},
747+
CheckFunction: checkfunctions.LibraryPropertiesArchitecturesFieldValueCase,
748+
},
734749
{
735750
ProjectType: projecttype.Library,
736751
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+66
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,72 @@ func LibraryPropertiesArchitecturesFieldSoloAlias() (result checkresult.Type, ou
897897
return checkresult.Pass, ""
898898
}
899899

900+
// LibraryPropertiesArchitecturesFieldValueCase checks for incorrect case of common architectures.
901+
func LibraryPropertiesArchitecturesFieldValueCase() (result checkresult.Type, output string) {
902+
if checkdata.LibraryPropertiesLoadError() != nil {
903+
return checkresult.NotRun, "Couldn't load library.properties"
904+
}
905+
906+
architectures, ok := checkdata.LibraryProperties().GetOk("architectures")
907+
if !ok {
908+
return checkresult.Skip, "Field not present"
909+
}
910+
911+
architecturesList := commaSeparatedToList(architectures)
912+
913+
var commonArchitecturesList = []string{
914+
"apollo3",
915+
"arc32",
916+
"avr",
917+
"esp32",
918+
"esp8266",
919+
"i586",
920+
"i686",
921+
"k210",
922+
"mbed",
923+
"megaavr",
924+
"mraa",
925+
"nRF5",
926+
"nrf52",
927+
"pic32",
928+
"sam",
929+
"samd",
930+
"wiced",
931+
"win10",
932+
}
933+
934+
correctArchitecturePresent := func(correctArchitectureQuery string) bool {
935+
for _, architecture := range architecturesList {
936+
if architecture == correctArchitectureQuery {
937+
return true
938+
}
939+
}
940+
941+
return false
942+
}
943+
944+
miscasedArchitectures := []string{}
945+
for _, architecture := range architecturesList {
946+
for _, commonArchitecture := range commonArchitecturesList {
947+
if architecture == commonArchitecture {
948+
break
949+
}
950+
951+
if strings.EqualFold(architecture, commonArchitecture) && !correctArchitecturePresent(commonArchitecture) {
952+
// The architecture has incorrect case and the correctly cased name is not present in the architectures field.
953+
miscasedArchitectures = append(miscasedArchitectures, architecture)
954+
break
955+
}
956+
}
957+
}
958+
959+
if len(miscasedArchitectures) > 0 {
960+
return checkresult.Fail, strings.Join(miscasedArchitectures, ", ")
961+
}
962+
963+
return checkresult.Pass, ""
964+
}
965+
900966
// LibraryPropertiesDependsFieldDisallowedCharacters checks for disallowed characters in the library.properties "depends" field.
901967
func LibraryPropertiesDependsFieldDisallowedCharacters() (result checkresult.Type, output string) {
902968
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,18 @@ func TestLibraryPropertiesArchitecturesFieldSoloAlias(t *testing.T) {
337337
checkLibraryCheckFunction(LibraryPropertiesArchitecturesFieldSoloAlias, testTables, t)
338338
}
339339

340+
func TestLibraryPropertiesArchitecturesFieldValueCase(t *testing.T) {
341+
testTables := []libraryCheckFunctionTestTable{
342+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
343+
{"Not defined", "MissingFields", checkresult.Skip, ""},
344+
{"Miscased", "ArchitectureMiscased", checkresult.Fail, ""},
345+
{"Miscased w/ correct case", "ArchitectureMiscasedWithCorrect", checkresult.Pass, ""},
346+
{"Correct case", "Recursive", checkresult.Pass, ""},
347+
}
348+
349+
checkLibraryCheckFunction(LibraryPropertiesArchitecturesFieldValueCase, testTables, t)
350+
}
351+
340352
func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
341353
testTables := []libraryCheckFunctionTestTable{
342354
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ArchitectureMiscased
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, samd, foo

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

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

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

Whitespace-only changes.

0 commit comments

Comments
 (0)