Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cb91a80

Browse files
authoredNov 24, 2020
Merge pull request #44 from arduino/per1234/url-schema-checks
Add schema provided checks for library.properties url field
2 parents a19c329 + 8ee6fab commit cb91a80

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
 

‎check/checkconfigurations/checkconfigurations.go

+30
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,36 @@ var configurations = []Type{
551551
ErrorModes: nil,
552552
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldUncategorized,
553553
},
554+
{
555+
ProjectType: projecttype.Library,
556+
Category: "library.properties",
557+
Subcategory: "url field",
558+
ID: "",
559+
Brief: "missing url field",
560+
Description: "",
561+
MessageTemplate: "missing required url field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
562+
DisableModes: nil,
563+
EnableModes: []checkmode.Type{checkmode.All},
564+
InfoModes: nil,
565+
WarningModes: nil,
566+
ErrorModes: []checkmode.Type{checkmode.All},
567+
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldMissing,
568+
},
569+
{
570+
ProjectType: projecttype.Library,
571+
Category: "library.properties",
572+
Subcategory: "url field",
573+
ID: "",
574+
Brief: "invalid url format",
575+
Description: "",
576+
MessageTemplate: "library.properties url field value {{.}} does not have a valid URL format.",
577+
DisableModes: nil,
578+
EnableModes: []checkmode.Type{checkmode.All},
579+
InfoModes: nil,
580+
WarningModes: []checkmode.Type{checkmode.Permissive},
581+
ErrorModes: []checkmode.Type{checkmode.Default},
582+
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldInvalid,
583+
},
554584
{
555585
ProjectType: projecttype.Library,
556586
Category: "library.properties",

‎check/checkfunctions/library.go

+30
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,36 @@ func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, out
538538
return checkresult.Pass, ""
539539
}
540540

541+
// LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field.
542+
func LibraryPropertiesUrlFieldMissing() (result checkresult.Type, output string) {
543+
if checkdata.LibraryPropertiesLoadError() != nil {
544+
return checkresult.NotRun, ""
545+
}
546+
547+
if schema.RequiredPropertyMissing("url", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
548+
return checkresult.Fail, ""
549+
}
550+
return checkresult.Pass, ""
551+
}
552+
553+
// LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format.
554+
func LibraryPropertiesUrlFieldInvalid() (result checkresult.Type, output string) {
555+
if checkdata.LibraryPropertiesLoadError() != nil {
556+
return checkresult.NotRun, ""
557+
}
558+
559+
url, ok := checkdata.LibraryProperties().GetOk("url")
560+
if !ok {
561+
return checkresult.NotRun, ""
562+
}
563+
564+
if schema.ValidationErrorMatch("^#/url$", "/format$", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
565+
return checkresult.Fail, url
566+
}
567+
568+
return checkresult.Pass, ""
569+
}
570+
541571
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
542572
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
543573
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.