Skip to content

Commit 0101aa0

Browse files
authored
Merge pull request #39 from arduino/per1234/author-schema-checks
Add schema provided checks for library.properties author field
2 parents 8d7a6f7 + 60f5372 commit 0101aa0

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+30
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,36 @@ var configurations = []Type{
176176
ErrorModes: nil,
177177
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldNonSemver,
178178
},
179+
{
180+
ProjectType: projecttype.Library,
181+
Category: "library.properties",
182+
Subcategory: "author field",
183+
ID: "",
184+
Brief: "missing author field",
185+
Description: "",
186+
MessageTemplate: "missing required author field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
187+
DisableModes: nil,
188+
EnableModes: []checkmode.Type{checkmode.All},
189+
InfoModes: nil,
190+
WarningModes: nil,
191+
ErrorModes: []checkmode.Type{checkmode.All},
192+
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldMissing,
193+
},
194+
{
195+
ProjectType: projecttype.Library,
196+
Category: "library.properties",
197+
Subcategory: "author field",
198+
ID: "",
199+
Brief: "author < min length",
200+
Description: "",
201+
MessageTemplate: "library.properties author value is less than minimum length",
202+
DisableModes: nil,
203+
EnableModes: []checkmode.Type{checkmode.All},
204+
InfoModes: nil,
205+
WarningModes: nil,
206+
ErrorModes: []checkmode.Type{checkmode.All},
207+
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength,
208+
},
179209
{
180210
ProjectType: projecttype.Library,
181211
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+29
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,35 @@ func LibraryPropertiesVersionFieldNonSemver() (result checkresult.Type, output s
146146
return checkresult.Pass, ""
147147
}
148148

149+
// LibraryPropertiesAuthorFieldMissing checks for missing library.properties "author" field.
150+
func LibraryPropertiesAuthorFieldMissing() (result checkresult.Type, output string) {
151+
if checkdata.LibraryPropertiesLoadError() != nil {
152+
return checkresult.NotRun, ""
153+
}
154+
155+
if schema.RequiredPropertyMissing("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
156+
return checkresult.Fail, ""
157+
}
158+
return checkresult.Pass, ""
159+
}
160+
161+
// LibraryPropertiesAuthorFieldLTMinLength checks if the library.properties "author" value is less than the minimum length.
162+
func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output string) {
163+
if checkdata.LibraryPropertiesLoadError() != nil {
164+
return checkresult.NotRun, ""
165+
}
166+
167+
if !checkdata.LibraryProperties().ContainsKey("author") {
168+
return checkresult.NotRun, ""
169+
}
170+
171+
if schema.PropertyLessThanMinLength("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
172+
return checkresult.Fail, ""
173+
}
174+
175+
return checkresult.Pass, ""
176+
}
177+
149178
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
150179
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
151180
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)