Skip to content

Commit

Permalink
Merge pull request #44 from arduino/per1234/url-schema-checks
Browse files Browse the repository at this point in the history
Add schema provided checks for library.properties url field
  • Loading branch information
per1234 authored Nov 24, 2020
2 parents a19c329 + 8ee6fab commit cb91a80
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,36 @@ var configurations = []Type{
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldUncategorized,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "url field",
ID: "",
Brief: "missing url field",
Description: "",
MessageTemplate: "missing required url 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.LibraryPropertiesUrlFieldMissing,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "url field",
ID: "",
Brief: "invalid url format",
Description: "",
MessageTemplate: "library.properties url field value {{.}} does not have a valid URL format.",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldInvalid,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Expand Down
30 changes: 30 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,36 @@ func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, out
return checkresult.Pass, ""
}

// LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field.
func LibraryPropertiesUrlFieldMissing() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

if schema.RequiredPropertyMissing("url", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
return checkresult.Fail, ""
}
return checkresult.Pass, ""
}

// LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format.
func LibraryPropertiesUrlFieldInvalid() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

url, ok := checkdata.LibraryProperties().GetOk("url")
if !ok {
return checkresult.NotRun, ""
}

if schema.ValidationErrorMatch("^#/url$", "/format$", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
return checkresult.Fail, url
}

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 {
Expand Down

0 comments on commit cb91a80

Please sign in to comment.