Skip to content

Commit e98b7d3

Browse files
committed
Add rule for 3rd party library.properties maintainer using "Arduino"
3rd party libraries are not maintained by Arduino. Even when 3rd party libraries are based on official libraries, it is best practice for the library.properties `maintainer` field to be updated to reflect the true maintainer of the project. There is already rule LP027 to promote accuracy in documenting maintainership by prohibiting maintainer values that start with "Arduino". However, this might not cover all inaccurate maintainer declarations. For this reason, a new rule (LP057) is added here to prohibit maintainer values in 3rd party libraries from containing the term "Arduino" anywhere (case insensitive). Violations of this rule only result in an error when in "strict" compliance mode.
1 parent cb7776a commit e98b7d3

File tree

8 files changed

+76
-12
lines changed

8 files changed

+76
-12
lines changed

etc/schemas/arduino-library-properties-definitions-schema.json

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"not": {
1111
"pattern": "^[aA][rR][dD][uU][iI][nN][oO].*$"
1212
}
13+
},
14+
"notContainsArduino": {
15+
"not": {
16+
"pattern": "^.+[aA][rR][dD][uU][iI][nN][oO].*$"
17+
}
1318
}
1419
}
1520
},
@@ -77,11 +82,6 @@
7782
"pattern": "^.* .*$"
7883
}
7984
},
80-
"notContainsArduino": {
81-
"not": {
82-
"pattern": "^.+[aA][rR][dD][uU][iI][nN][oO].*$"
83-
}
84-
},
8585
"notContainsSuperfluousTerms": {
8686
"not": {
8787
"pattern": "^.*[lL][iI][bB][rR][aA][rR][yY].*$"
@@ -101,7 +101,7 @@
101101
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsSpaces"
102102
},
103103
{
104-
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsArduino"
104+
"$ref": "#/definitions/general/patternObjects/notContainsArduino"
105105
},
106106
{
107107
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsSuperfluousTerms"
@@ -238,6 +238,9 @@
238238
"allOf": [
239239
{
240240
"$ref": "#/definitions/propertiesObjects/maintainer/specification/object"
241+
},
242+
{
243+
"$ref": "#/definitions/general/patternObjects/notContainsArduino"
241244
}
242245
]
243246
}

internal/project/library/libraryproperties/librarypropertiesschemas_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,11 @@ func TestPropertiesVersionPattern(t *testing.T) {
291291
func TestPropertiesMaintainerPattern(t *testing.T) {
292292
testTables := []propertyValueTestTable{
293293
{"Starts with arduino", "arduinofoo", compliancelevel.Permissive, assert.False},
294+
{"Contains arduino", "fooarduinobar", compliancelevel.Permissive, assert.False},
294295
{"Starts with arduino", "arduinofoo", compliancelevel.Specification, assert.True},
296+
{"Contains arduino", "fooarduinobar", compliancelevel.Specification, assert.False},
295297
{"Starts with arduino", "arduinofoo", compliancelevel.Strict, assert.True},
298+
{"Contains arduino", "fooarduinobar", compliancelevel.Strict, assert.True},
296299
}
297300

298301
checkPropertyPatternMismatch("maintainer", testTables, t)

internal/rule/ruleconfiguration/ruleconfiguration.go

+16
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,22 @@ var configurations = []Type{
681681
ErrorModes: []rulemode.Type{rulemode.Strict},
682682
RuleFunction: rulefunction.LibraryPropertiesMaintainerFieldStartsWithArduino,
683683
},
684+
{
685+
ProjectType: projecttype.Library,
686+
SuperprojectType: projecttype.All,
687+
Category: "library.properties",
688+
Subcategory: "maintainer field",
689+
ID: "LP057",
690+
Brief: `maintainer contains "Arduino"`,
691+
Description: "Case insensitive.",
692+
MessageTemplate: `library.properties maintainer value {{.}} contains "Arduino". 3rd party libraries are not maintained by Arduino.`,
693+
DisableModes: []rulemode.Type{rulemode.Official},
694+
EnableModes: []rulemode.Type{rulemode.Default},
695+
InfoModes: nil,
696+
WarningModes: []rulemode.Type{rulemode.Default},
697+
ErrorModes: []rulemode.Type{rulemode.Strict},
698+
RuleFunction: rulefunction.LibraryPropertiesMaintainerFieldContainsArduino,
699+
},
684700
{
685701
ProjectType: projecttype.Library,
686702
SuperprojectType: projecttype.All,

internal/rule/rulefunction/library.go

+18
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,24 @@ func LibraryPropertiesMaintainerFieldStartsWithArduino() (result ruleresult.Type
744744
return ruleresult.Pass, ""
745745
}
746746

747+
// LibraryPropertiesMaintainerFieldContainsArduino checks if the library.properties "maintainer" value contains "Arduino".
748+
func LibraryPropertiesMaintainerFieldContainsArduino() (result ruleresult.Type, output string) {
749+
if projectdata.LibraryPropertiesLoadError() != nil {
750+
return ruleresult.NotRun, "Couldn't load library.properties"
751+
}
752+
753+
maintainer, ok := projectdata.LibraryProperties().GetOk("maintainer")
754+
if !ok {
755+
return ruleresult.NotRun, "Field not present"
756+
}
757+
758+
if schema.ValidationErrorMatch("^#/maintainer$", "/patternObjects/notContainsArduino", "", "", projectdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Strict]) {
759+
return ruleresult.Fail, maintainer
760+
}
761+
762+
return ruleresult.Pass, ""
763+
}
764+
747765
// LibraryPropertiesEmailFieldAsMaintainerAlias checks whether the library.properties "email" field is being used as an alias for the "maintainer" field.
748766
func LibraryPropertiesEmailFieldAsMaintainerAlias() (result ruleresult.Type, output string) {
749767
if projectdata.LibraryPropertiesLoadError() != nil {

internal/rule/rulefunction/library_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,17 @@ func TestLibraryPropertiesMaintainerFieldStartsWithArduino(t *testing.T) {
568568
checkLibraryRuleFunction(LibraryPropertiesMaintainerFieldStartsWithArduino, testTables, t)
569569
}
570570

571+
func TestLibraryPropertiesMaintainerFieldContainsArduino(t *testing.T) {
572+
testTables := []libraryRuleFunctionTestTable{
573+
{"Invalid", "InvalidLibraryProperties", ruleresult.NotRun, ""},
574+
{"Legacy", "Legacy", ruleresult.NotRun, ""},
575+
{"Maintainer field contains Arduino", "MaintainerContainsArduino", ruleresult.Fail, ""},
576+
{"Valid", "Recursive", ruleresult.Pass, ""},
577+
}
578+
579+
checkLibraryRuleFunction(LibraryPropertiesMaintainerFieldContainsArduino, testTables, t)
580+
}
581+
571582
func TestLibraryPropertiesEmailFieldAsMaintainerAlias(t *testing.T) {
572583
testTables := []libraryRuleFunctionTestTable{
573584
{"Unable to load", "InvalidLibraryProperties", ruleresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=MaintainerContainsArduino
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian "Arduino Wizard" 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
10+
includes=Recursive.h

internal/rule/rulefunction/testdata/libraries/MaintainerContainsArduino/src/MaintainerContainsArduino.h

Whitespace-only changes.

internal/rule/schema/schemadata/bindata.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
14291429
"not": {
14301430
"pattern": "^[aA][rR][dD][uU][iI][nN][oO].*$"
14311431
}
1432+
},
1433+
"notContainsArduino": {
1434+
"not": {
1435+
"pattern": "^.+[aA][rR][dD][uU][iI][nN][oO].*$"
1436+
}
14321437
}
14331438
}
14341439
},
@@ -1496,11 +1501,6 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
14961501
"pattern": "^.* .*$"
14971502
}
14981503
},
1499-
"notContainsArduino": {
1500-
"not": {
1501-
"pattern": "^.+[aA][rR][dD][uU][iI][nN][oO].*$"
1502-
}
1503-
},
15041504
"notContainsSuperfluousTerms": {
15051505
"not": {
15061506
"pattern": "^.*[lL][iI][bB][rR][aA][rR][yY].*$"
@@ -1520,7 +1520,7 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
15201520
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsSpaces"
15211521
},
15221522
{
1523-
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsArduino"
1523+
"$ref": "#/definitions/general/patternObjects/notContainsArduino"
15241524
},
15251525
{
15261526
"$ref": "#/definitions/propertiesObjects/name/strict/definitions/patternObjects/notContainsSuperfluousTerms"
@@ -1657,6 +1657,9 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
16571657
"allOf": [
16581658
{
16591659
"$ref": "#/definitions/propertiesObjects/maintainer/specification/object"
1660+
},
1661+
{
1662+
"$ref": "#/definitions/general/patternObjects/notContainsArduino"
16601663
}
16611664
]
16621665
}

0 commit comments

Comments
 (0)