Skip to content

Commit c5d176e

Browse files
committed
Add schema provided checks for library.properties url field
1 parent 336fc8f commit c5d176e

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
@@ -146,6 +146,36 @@ var configurations = []Type{
146146
ErrorModes: []checkmode.Type{checkmode.All},
147147
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldMissing,
148148
},
149+
{
150+
ProjectType: projecttype.Library,
151+
Category: "library.properties",
152+
Subcategory: "url field",
153+
ID: "",
154+
Brief: "missing url field",
155+
Description: "",
156+
MessageTemplate: "missing required url field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
157+
DisableModes: nil,
158+
EnableModes: []checkmode.Type{checkmode.All},
159+
InfoModes: nil,
160+
WarningModes: nil,
161+
ErrorModes: []checkmode.Type{checkmode.All},
162+
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldMissing,
163+
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "url field",
168+
ID: "",
169+
Brief: "invalid url format",
170+
Description: "",
171+
MessageTemplate: "library.properties url field value {{.}} does not have a valid URL format.",
172+
DisableModes: nil,
173+
EnableModes: []checkmode.Type{checkmode.All},
174+
InfoModes: nil,
175+
WarningModes: []checkmode.Type{checkmode.Permissive},
176+
ErrorModes: []checkmode.Type{checkmode.Default},
177+
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldInvalid,
178+
},
149179
{
150180
ProjectType: projecttype.Library,
151181
Category: "library.properties",

check/checkfunctions/library.go

+30
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,36 @@ func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output str
110110
return checkresult.Pass, ""
111111
}
112112

113+
// LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field.
114+
func LibraryPropertiesUrlFieldMissing() (result checkresult.Type, output string) {
115+
if checkdata.LibraryPropertiesLoadError() != nil {
116+
return checkresult.NotRun, ""
117+
}
118+
119+
if schema.RequiredPropertyMissing("url", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
120+
return checkresult.Fail, ""
121+
}
122+
return checkresult.Pass, ""
123+
}
124+
125+
// LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format.
126+
func LibraryPropertiesUrlFieldInvalid() (result checkresult.Type, output string) {
127+
if checkdata.LibraryPropertiesLoadError() != nil {
128+
return checkresult.NotRun, ""
129+
}
130+
131+
url, ok := checkdata.LibraryProperties().GetOk("url")
132+
if !ok {
133+
return checkresult.NotRun, ""
134+
}
135+
136+
if schema.ValidationErrorMatch("^#/url$", "/format$", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
137+
return checkresult.Fail, url
138+
}
139+
140+
return checkresult.Pass, ""
141+
}
142+
113143
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114144
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115145
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)