diff --git a/check/checkconfigurations/checkconfigurations.go b/check/checkconfigurations/checkconfigurations.go index 8a40a140..3188fa3a 100644 --- a/check/checkconfigurations/checkconfigurations.go +++ b/check/checkconfigurations/checkconfigurations.go @@ -176,6 +176,36 @@ var configurations = []Type{ ErrorModes: nil, CheckFunction: checkfunctions.LibraryPropertiesVersionFieldNonSemver, }, + { + ProjectType: projecttype.Library, + Category: "library.properties", + Subcategory: "author field", + ID: "", + Brief: "missing author field", + Description: "", + MessageTemplate: "missing required author field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format", + DisableModes: nil, + EnableModes: []checkmode.Type{checkmode.All}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []checkmode.Type{checkmode.All}, + CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldMissing, + }, + { + ProjectType: projecttype.Library, + Category: "library.properties", + Subcategory: "author field", + ID: "", + Brief: "author < min length", + Description: "", + MessageTemplate: "library.properties author value is less than minimum length", + DisableModes: nil, + EnableModes: []checkmode.Type{checkmode.All}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []checkmode.Type{checkmode.All}, + CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength, + }, { ProjectType: projecttype.Library, Category: "library.properties", diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index fb7d3db6..7df753f7 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -146,6 +146,35 @@ func LibraryPropertiesVersionFieldNonSemver() (result checkresult.Type, output s return checkresult.Pass, "" } +// LibraryPropertiesAuthorFieldMissing checks for missing library.properties "author" field. +func LibraryPropertiesAuthorFieldMissing() (result checkresult.Type, output string) { + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "" + } + + if schema.RequiredPropertyMissing("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { + return checkresult.Fail, "" + } + return checkresult.Pass, "" +} + +// LibraryPropertiesAuthorFieldLTMinLength checks if the library.properties "author" value is less than the minimum length. +func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output string) { + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "" + } + + if !checkdata.LibraryProperties().ContainsKey("author") { + return checkresult.NotRun, "" + } + + if schema.PropertyLessThanMinLength("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { + return checkresult.Fail, "" + } + + return checkresult.Pass, "" +} + // LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index. func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) { if checkdata.LibraryPropertiesLoadError() != nil {