Skip to content

Commit 9a6a633

Browse files
committed
Add check for incorrect library.properties architecture case
1 parent fe8b66a commit 9a6a633

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
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",

check/checkfunctions/library.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,72 @@ func LibraryPropertiesArchitecturesFieldSoloAlias() (result checkresult.Type, ou
871871
return checkresult.Pass, ""
872872
}
873873

874+
// LibraryPropertiesArchitecturesFieldValueCase checks for incorrect case of common architectures.
875+
func LibraryPropertiesArchitecturesFieldValueCase() (result checkresult.Type, output string) {
876+
if checkdata.LibraryPropertiesLoadError() != nil {
877+
return checkresult.NotRun, "Couldn't load library.properties"
878+
}
879+
880+
architectures, ok := checkdata.LibraryProperties().GetOk("architectures")
881+
if !ok {
882+
return checkresult.Skip, "Field not present"
883+
}
884+
885+
architecturesList := commaSeparatedToList(architectures)
886+
887+
var commonArchitecturesList = []string{
888+
"apollo3",
889+
"arc32",
890+
"avr",
891+
"esp32",
892+
"esp8266",
893+
"i586",
894+
"i686",
895+
"k210",
896+
"mbed",
897+
"megaavr",
898+
"mraa",
899+
"nRF5",
900+
"nrf52",
901+
"pic32",
902+
"sam",
903+
"samd",
904+
"wiced",
905+
"win10",
906+
}
907+
908+
correctArchitecturePresent := func(correctArchitectureQuery string) bool {
909+
for _, architecture := range architecturesList {
910+
if architecture == correctArchitectureQuery {
911+
return true
912+
}
913+
}
914+
915+
return false
916+
}
917+
918+
miscasedArchitectures := []string{}
919+
for _, architecture := range architecturesList {
920+
for _, commonArchitecture := range commonArchitecturesList {
921+
if architecture == commonArchitecture {
922+
break
923+
}
924+
925+
if strings.EqualFold(architecture, commonArchitecture) && !correctArchitecturePresent(commonArchitecture) {
926+
// The architecture has incorrect case and the correctly cased name is not present in the architectures field.
927+
miscasedArchitectures = append(miscasedArchitectures, architecture)
928+
break
929+
}
930+
}
931+
}
932+
933+
if len(miscasedArchitectures) > 0 {
934+
return checkresult.Fail, strings.Join(miscasedArchitectures, ", ")
935+
}
936+
937+
return checkresult.Pass, ""
938+
}
939+
874940
// LibraryPropertiesDependsFieldDisallowedCharacters checks for disallowed characters in the library.properties "depends" field.
875941
func LibraryPropertiesDependsFieldDisallowedCharacters() (result checkresult.Type, output string) {
876942
if checkdata.LibraryPropertiesLoadError() != nil {

check/checkfunctions/library_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ func TestLibraryPropertiesArchitecturesFieldSoloAlias(t *testing.T) {
316316
checkLibraryCheckFunction(LibraryPropertiesArchitecturesFieldSoloAlias, testTables, t)
317317
}
318318

319+
func TestLibraryPropertiesArchitecturesFieldValueCase(t *testing.T) {
320+
testTables := []libraryCheckFunctionTestTable{
321+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
322+
{"Not defined", "MissingFields", checkresult.Skip, ""},
323+
{"Miscased", "ArchitectureMiscased", checkresult.Fail, ""},
324+
{"Miscased w/ correct case", "ArchitectureMiscasedWithCorrect", checkresult.Pass, ""},
325+
{"Correct case", "Recursive", checkresult.Pass, ""},
326+
}
327+
328+
checkLibraryCheckFunction(LibraryPropertiesArchitecturesFieldValueCase, testTables, t)
329+
}
330+
319331
func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
320332
testTables := []libraryCheckFunctionTestTable{
321333
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ArchitectureMiscased
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, samd, foo

check/checkfunctions/testdata/libraries/ArchitectureMiscased/src/ArchitectureMiscased.h

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

check/checkfunctions/testdata/libraries/ArchitectureMiscasedWithCorrect/src/ArchitectureMiscasedWithCorrect.h

Whitespace-only changes.

0 commit comments

Comments
 (0)