Skip to content

Commit 2604f4a

Browse files
authored
Merge pull request #41 from arduino/per1234/maintainer-schema-checks
Add schema provided checks for library.properties maintainer/email field
2 parents af4cd53 + 513922e commit 2604f4a

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+90
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,96 @@ var configurations = []Type{
326326
ErrorModes: []checkmode.Type{checkmode.All},
327327
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength,
328328
},
329+
{
330+
ProjectType: projecttype.Library,
331+
Category: "library.properties",
332+
Subcategory: "maintainer field",
333+
ID: "",
334+
Brief: "missing maintainer field",
335+
Description: "",
336+
MessageTemplate: "missing required maintainer field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
337+
DisableModes: nil,
338+
EnableModes: []checkmode.Type{checkmode.All},
339+
InfoModes: nil,
340+
WarningModes: nil,
341+
ErrorModes: []checkmode.Type{checkmode.All},
342+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldMissing,
343+
},
344+
{
345+
ProjectType: projecttype.Library,
346+
Category: "library.properties",
347+
Subcategory: "maintainer field",
348+
ID: "",
349+
Brief: "maintainer < min length",
350+
Description: "",
351+
MessageTemplate: "library.properties maintainer value is less than minimum length",
352+
DisableModes: nil,
353+
EnableModes: []checkmode.Type{checkmode.All},
354+
InfoModes: nil,
355+
WarningModes: nil,
356+
ErrorModes: []checkmode.Type{checkmode.All},
357+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldLTMinLength,
358+
},
359+
{
360+
ProjectType: projecttype.Library,
361+
Category: "library.properties",
362+
Subcategory: "maintainer field",
363+
ID: "",
364+
Brief: `starts with "Arduino"`,
365+
Description: "Case insensitive.",
366+
MessageTemplate: `library.properties maintainer value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
367+
DisableModes: []checkmode.Type{checkmode.Official},
368+
EnableModes: []checkmode.Type{checkmode.Default},
369+
InfoModes: nil,
370+
WarningModes: []checkmode.Type{checkmode.All},
371+
ErrorModes: nil,
372+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldStartsWithArduino,
373+
},
374+
{
375+
ProjectType: projecttype.Library,
376+
Category: "library.properties",
377+
Subcategory: "email field",
378+
ID: "",
379+
Brief: `"email" field used as alias for "maintainer"`,
380+
Description: "This was in an early draft of the beta 1.5 library specification.",
381+
MessageTemplate: `library.properties "email" field used as alias for "maintainer". This is deprecated.`,
382+
DisableModes: nil,
383+
EnableModes: []checkmode.Type{checkmode.All},
384+
InfoModes: nil,
385+
WarningModes: []checkmode.Type{checkmode.Permissive},
386+
ErrorModes: []checkmode.Type{checkmode.Default},
387+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldAsMaintainerAlias,
388+
},
389+
{
390+
ProjectType: projecttype.Library,
391+
Category: "library.properties",
392+
Subcategory: "email field",
393+
ID: "",
394+
Brief: "email < min length",
395+
Description: "",
396+
MessageTemplate: "library.properties email value is less than minimum length",
397+
DisableModes: nil,
398+
EnableModes: []checkmode.Type{checkmode.All},
399+
InfoModes: nil,
400+
WarningModes: nil,
401+
ErrorModes: []checkmode.Type{checkmode.All},
402+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldLTMinLength,
403+
},
404+
{
405+
ProjectType: projecttype.Library,
406+
Category: "library.properties",
407+
Subcategory: "email field",
408+
ID: "",
409+
Brief: `starts with "Arduino"`,
410+
Description: "Case insensitive.",
411+
MessageTemplate: `library.properties email value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
412+
DisableModes: []checkmode.Type{checkmode.Official},
413+
EnableModes: []checkmode.Type{checkmode.Default},
414+
InfoModes: nil,
415+
WarningModes: []checkmode.Type{checkmode.All},
416+
ErrorModes: nil,
417+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldStartsWithArduino,
418+
},
329419
{
330420
ProjectType: projecttype.Library,
331421
Category: "library.properties",

check/checkfunctions/library.go

+103
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,109 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output
317317
return checkresult.Pass, ""
318318
}
319319

320+
// LibraryPropertiesMaintainerFieldMissing checks for missing library.properties "maintainer" field.
321+
func LibraryPropertiesMaintainerFieldMissing() (result checkresult.Type, output string) {
322+
if checkdata.LibraryPropertiesLoadError() != nil {
323+
return checkresult.NotRun, ""
324+
}
325+
326+
if schema.RequiredPropertyMissing("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
327+
return checkresult.Fail, ""
328+
}
329+
return checkresult.Pass, ""
330+
}
331+
332+
// LibraryPropertiesMaintainerFieldLTMinLength checks if the library.properties "maintainer" value is less than the minimum length.
333+
func LibraryPropertiesMaintainerFieldLTMinLength() (result checkresult.Type, output string) {
334+
if checkdata.LibraryPropertiesLoadError() != nil {
335+
return checkresult.NotRun, ""
336+
}
337+
338+
if !checkdata.LibraryProperties().ContainsKey("maintainer") {
339+
return checkresult.NotRun, ""
340+
}
341+
342+
if schema.PropertyLessThanMinLength("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
343+
return checkresult.Fail, ""
344+
}
345+
346+
return checkresult.Pass, ""
347+
}
348+
349+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "maintainer" value starts with "Arduino".
350+
func LibraryPropertiesMaintainerFieldStartsWithArduino() (result checkresult.Type, output string) {
351+
if checkdata.LibraryPropertiesLoadError() != nil {
352+
return checkresult.NotRun, ""
353+
}
354+
355+
maintainer, ok := checkdata.LibraryProperties().GetOk("maintainer")
356+
if !ok {
357+
return checkresult.NotRun, ""
358+
}
359+
360+
if schema.ValidationErrorMatch("^#/maintainer$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
361+
return checkresult.Fail, maintainer
362+
}
363+
364+
return checkresult.Pass, ""
365+
}
366+
367+
// LibraryPropertiesEmailFieldAsMaintainerAlias checks whether the library.properties "email" field is being used as an alias for the "maintainer" field.
368+
func LibraryPropertiesEmailFieldAsMaintainerAlias() (result checkresult.Type, output string) {
369+
if checkdata.LibraryPropertiesLoadError() != nil {
370+
return checkresult.NotRun, ""
371+
}
372+
373+
if !checkdata.LibraryProperties().ContainsKey("email") {
374+
return checkresult.NotRun, ""
375+
}
376+
377+
if !checkdata.LibraryProperties().ContainsKey("maintainer") {
378+
return checkresult.Fail, ""
379+
}
380+
381+
return checkresult.Pass, ""
382+
}
383+
384+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "email" value is less than the minimum length.
385+
func LibraryPropertiesEmailFieldLTMinLength() (result checkresult.Type, output string) {
386+
if checkdata.LibraryPropertiesLoadError() != nil {
387+
return checkresult.NotRun, ""
388+
}
389+
390+
if checkdata.LibraryProperties().ContainsKey("maintainer") || !checkdata.LibraryProperties().ContainsKey("email") {
391+
return checkresult.NotRun, ""
392+
}
393+
394+
if schema.PropertyLessThanMinLength("email", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
395+
return checkresult.Fail, ""
396+
}
397+
398+
return checkresult.Pass, ""
399+
}
400+
401+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "email" value starts with "Arduino".
402+
func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, output string) {
403+
if checkdata.LibraryPropertiesLoadError() != nil {
404+
return checkresult.NotRun, ""
405+
}
406+
407+
if checkdata.LibraryProperties().ContainsKey("maintainer") {
408+
return checkresult.NotRun, ""
409+
}
410+
411+
email, ok := checkdata.LibraryProperties().GetOk("email")
412+
if !ok {
413+
return checkresult.NotRun, ""
414+
}
415+
416+
if schema.ValidationErrorMatch("^#/email$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
417+
return checkresult.Fail, email
418+
}
419+
420+
return checkresult.Pass, ""
421+
}
422+
320423
// LibraryPropertiesSentenceFieldMissing checks for missing library.properties "sentence" field.
321424
func LibraryPropertiesSentenceFieldMissing() (result checkresult.Type, output string) {
322425
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)