@@ -23,6 +23,7 @@ import (
23
23
"github.com/arduino/arduino-lint/internal/rule/ruleresult"
24
24
"github.com/arduino/arduino-lint/internal/rule/schema"
25
25
"github.com/arduino/arduino-lint/internal/rule/schema/compliancelevel"
26
+ "github.com/arduino/go-properties-orderedmap"
26
27
"github.com/sirupsen/logrus"
27
28
)
28
29
@@ -104,7 +105,7 @@ func BoardsTxtBoardIDBuildBoardMissing() (result ruleresult.Type, output string)
104
105
return ruleresult .Skip , "boards.txt has no boards"
105
106
}
106
107
107
- nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtBoardIds (), "build.board" )
108
+ nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtBoardIds (), "build.board" , false )
108
109
109
110
if len (nonCompliantBoardIDs ) > 0 {
110
111
return ruleresult .Fail , strings .Join (nonCompliantBoardIDs , ", " )
@@ -142,7 +143,7 @@ func BoardsTxtBoardIDBuildCoreMissing() (result ruleresult.Type, output string)
142
143
return ruleresult .Skip , "boards.txt has no visible boards"
143
144
}
144
145
145
- nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "build.core" )
146
+ nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "build.core" , false )
146
147
147
148
if len (nonCompliantBoardIDs ) > 0 {
148
149
return ruleresult .Fail , strings .Join (nonCompliantBoardIDs , ", " )
@@ -285,7 +286,7 @@ func BoardsTxtBoardIDUploadToolMissing() (result ruleresult.Type, output string)
285
286
return ruleresult .Skip , "boards.txt has no visible boards"
286
287
}
287
288
288
- nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.tool" )
289
+ nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.tool" , false )
289
290
290
291
if len (nonCompliantBoardIDs ) > 0 {
291
292
return ruleresult .Fail , strings .Join (nonCompliantBoardIDs , ", " )
@@ -323,7 +324,7 @@ func BoardsTxtBoardIDUploadMaximumSizeMissing() (result ruleresult.Type, output
323
324
return ruleresult .Skip , "boards.txt has no visible boards"
324
325
}
325
326
326
- nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.maximum_size" )
327
+ nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.maximum_size" , false )
327
328
328
329
if len (nonCompliantBoardIDs ) > 0 {
329
330
return ruleresult .Fail , strings .Join (nonCompliantBoardIDs , ", " )
@@ -361,7 +362,7 @@ func BoardsTxtBoardIDUploadMaximumDataSizeMissing() (result ruleresult.Type, out
361
362
return ruleresult .Skip , "boards.txt has no visible boards"
362
363
}
363
364
364
- nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.maximum_data_size" )
365
+ nonCompliantBoardIDs := boardIDMissingRequiredProperty (projectdata .BoardsTxtVisibleBoardIds (), "upload.maximum_data_size" , false )
365
366
366
367
if len (nonCompliantBoardIDs ) > 0 {
367
368
return ruleresult .Fail , strings .Join (nonCompliantBoardIDs , ", " )
@@ -1691,7 +1692,7 @@ func PlatformTxtPluggableDiscoveryRequiredInvalid() (result ruleresult.Type, out
1691
1692
return ruleresult .NotRun , "Couldn't load platform.txt"
1692
1693
}
1693
1694
1694
- if ! projectdata . PlatformTxt (). ContainsKey ( "pluggable_discovery.required" ) && projectdata .PlatformTxt (). SubTree ( "pluggable_discovery.required" ). Size () == 0 {
1695
+ if ! containsKeyOrParent ( projectdata .PlatformTxt (), "pluggable_discovery.required" ) {
1695
1696
return ruleresult .Skip , "Property not present"
1696
1697
}
1697
1698
@@ -1970,12 +1971,20 @@ Unlike iDMissingRequiredProperty(), this function does a direct check on the pro
1970
1971
This is necessary because JSON schema does not have the capability to account for the custom board options system.
1971
1972
This function should not be used in cases where the JSON schema does cover a required property.
1972
1973
*/
1973
- func boardIDMissingRequiredProperty (boardIDs []string , propertyName string ) []string {
1974
+ func boardIDMissingRequiredProperty (boardIDs []string , propertyName string , parentOK bool ) []string {
1975
+ containsKey := func (key string ) bool {
1976
+ if parentOK {
1977
+ return containsKeyOrParent (projectdata .BoardsTxt (), key )
1978
+ }
1979
+
1980
+ return projectdata .BoardsTxt ().ContainsKey (key )
1981
+ }
1982
+
1974
1983
nonCompliantBoardIDs := []string {}
1975
1984
for _ , boardID := range boardIDs {
1976
1985
logrus .Tracef ("Board ID: %s" , boardID )
1977
1986
boardIDHasProperty := func (boardID string , propertyName string ) bool {
1978
- if projectdata . BoardsTxt (). ContainsKey (boardID + "." + propertyName ) {
1987
+ if containsKey (boardID + "." + propertyName ) {
1979
1988
logrus .Trace ("Property defined at top level\n " )
1980
1989
return true // The board has a first level definition of the property. No need to check custom board options.
1981
1990
@@ -1992,7 +2001,7 @@ func boardIDMissingRequiredProperty(boardIDs []string, propertyName string) []st
1992
2001
boardOptionProperties := boardMenuProperties .SubTree (boardMenuID )
1993
2002
boardOptionIDs := boardOptionProperties .FirstLevelKeys ()
1994
2003
for _ , boardOptionID := range boardOptionIDs {
1995
- if ! boardOptionProperties . ContainsKey (boardOptionID + "." + propertyName ) {
2004
+ if ! containsKey (boardOptionID + "." + propertyName ) {
1996
2005
logrus .Tracef ("Option ID %s doesn't provide property\n " , boardOptionID )
1997
2006
menuProvidesProperty = false // Every option associated with the menuID must define the property.
1998
2007
break
@@ -2067,6 +2076,12 @@ func toolNameMissingRequiredProperty(propertyNameQuery string, complianceLevel c
2067
2076
return nonCompliantTools
2068
2077
}
2069
2078
2079
+ // containsKeyOrParent returns whether the given properties contain a key of the given name, or whether the given key is
2080
+ // a first level of a key in the properties.
2081
+ func containsKeyOrParent (propertiesMap * properties.Map , key string ) bool {
2082
+ return propertiesMap .ContainsKey (key ) || propertiesMap .SubTree (key ).Size () > 0
2083
+ }
2084
+
2070
2085
// iDMissingRequiredProperty returns the list of first level keys missing the given required property.
2071
2086
func iDMissingRequiredProperty (iDs []string , propertyNameQuery string , validationResult schema.ValidationResult ) []string {
2072
2087
nonCompliantIDs := []string {}
0 commit comments