@@ -846,6 +846,123 @@ func LibraryPropertiesArchitecturesFieldLTMinLength() (result checkresult.Type,
846846 return checkresult .Pass , ""
847847}
848848
849+ // LibraryPropertiesArchitecturesFieldAlias checks whether an alias architecture name is present, but not its true Arduino architecture name.
850+ func LibraryPropertiesArchitecturesFieldSoloAlias () (result checkresult.Type , output string ) {
851+ if checkdata .LibraryPropertiesLoadError () != nil {
852+ return checkresult .NotRun , "Couldn't load library.properties"
853+ }
854+
855+ architectures , ok := checkdata .LibraryProperties ().GetOk ("architectures" )
856+ if ! ok {
857+ return checkresult .Skip , "Field not present"
858+ }
859+
860+ architecturesList := commaSeparatedToList (strings .ToLower (architectures ))
861+
862+ // Must be all lowercase (there is a separate check for incorrect architecture case).
863+ var aliases = map [string ][]string {
864+ "atmelavr" : {"avr" },
865+ "atmelmegaavr" : {"megaavr" },
866+ "atmelsam" : {"sam" , "samd" },
867+ "espressif32" : {"esp32" },
868+ "espressif8266" : {"esp8266" },
869+ "intel_arc32" : {"arc32" },
870+ "nordicnrf52" : {"nRF5" , "nrf52" , "mbed" },
871+ }
872+
873+ trueArchitecturePresent := func (trueArchitecturesQuery []string ) bool {
874+ for _ , trueArchitectureQuery := range trueArchitecturesQuery {
875+ for _ , architecture := range architecturesList {
876+ if architecture == trueArchitectureQuery {
877+ return true
878+ }
879+ }
880+ }
881+
882+ return false
883+ }
884+
885+ soloAliases := []string {}
886+ for _ , architecture := range architecturesList {
887+ trueEquivalents , isAlias := aliases [architecture ]
888+ if isAlias && ! trueArchitecturePresent (trueEquivalents ) {
889+ soloAliases = append (soloAliases , architecture )
890+ }
891+ }
892+
893+ if len (soloAliases ) > 0 {
894+ return checkresult .Fail , strings .Join (soloAliases , ", " )
895+ }
896+
897+ return checkresult .Pass , ""
898+ }
899+
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+
849966// LibraryPropertiesDependsFieldDisallowedCharacters checks for disallowed characters in the library.properties "depends" field.
850967func LibraryPropertiesDependsFieldDisallowedCharacters () (result checkresult.Type , output string ) {
851968 if checkdata .LibraryPropertiesLoadError () != nil {
@@ -875,11 +992,10 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output
875992 return checkresult .Skip , "Field not present"
876993 }
877994
878- dependencies := strings . Split (depends , "," )
995+ dependencies := commaSeparatedToList (depends )
879996
880997 dependenciesNotInIndex := []string {}
881998 for _ , dependency := range dependencies {
882- dependency = strings .TrimSpace (dependency )
883999 if dependency == "" {
8841000 continue
8851001 }
@@ -959,10 +1075,9 @@ func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, outp
9591075 return checkresult .Skip , "Field not present"
9601076 }
9611077
962- includesList := strings . Split (includes , "," )
1078+ includesList := commaSeparatedToList (includes )
9631079
9641080 findInclude := func (include string ) bool {
965- include = strings .TrimSpace (include )
9661081 if include == "" {
9671082 return true
9681083 }
@@ -1357,3 +1472,13 @@ func nameInLibraryManagerIndex(name string) bool {
13571472
13581473 return false
13591474}
1475+
1476+ // commaSeparatedToList returns the list equivalent of a comma-separated string.
1477+ func commaSeparatedToList (commaSeparated string ) []string {
1478+ list := []string {}
1479+ for _ , item := range strings .Split (commaSeparated , "," ) {
1480+ list = append (list , strings .TrimSpace (item ))
1481+ }
1482+
1483+ return list
1484+ }
0 commit comments