Skip to content

Commit af4cd53

Browse files
authored
Merge pull request #40 from arduino/per1234/sentence-paragraph-schema-checks
Add schema provided checks for library.properties sentence and paragraph fields
2 parents 11a3b80 + 284ff17 commit af4cd53

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+45
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,36 @@ var configurations = []Type{
326326
ErrorModes: []checkmode.Type{checkmode.All},
327327
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength,
328328
},
329+
{
330+
ProjectType: projecttype.Library,
331+
Category: "library.properties",
332+
Subcategory: "sentence field",
333+
ID: "",
334+
Brief: "missing sentence field",
335+
Description: "",
336+
MessageTemplate: "missing required sentence field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
337+
DisableModes: nil,
338+
EnableModes: []checkmode.Type{checkmode.All},
339+
InfoModes: nil,
340+
WarningModes: nil,
341+
ErrorModes: []checkmode.Type{checkmode.All},
342+
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldMissing,
343+
},
344+
{
345+
ProjectType: projecttype.Library,
346+
Category: "library.properties",
347+
Subcategory: "sentence field",
348+
ID: "",
349+
Brief: "sentence < min length",
350+
Description: "",
351+
MessageTemplate: "library.properties sentence value is less than minimum length",
352+
DisableModes: nil,
353+
EnableModes: []checkmode.Type{checkmode.All},
354+
InfoModes: nil,
355+
WarningModes: nil,
356+
ErrorModes: []checkmode.Type{checkmode.All},
357+
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldLTMinLength,
358+
},
329359
{
330360
ProjectType: projecttype.Library,
331361
Category: "library.properties",
@@ -341,6 +371,21 @@ var configurations = []Type{
341371
ErrorModes: nil,
342372
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldSpellCheck,
343373
},
374+
{
375+
ProjectType: projecttype.Library,
376+
Category: "library.properties",
377+
Subcategory: "paragraph field",
378+
ID: "",
379+
Brief: "missing paragraph field",
380+
Description: "",
381+
MessageTemplate: "missing required paragraph field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
382+
DisableModes: nil,
383+
EnableModes: []checkmode.Type{checkmode.All},
384+
InfoModes: nil,
385+
WarningModes: nil,
386+
ErrorModes: []checkmode.Type{checkmode.All},
387+
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldMissing,
388+
},
344389
{
345390
ProjectType: projecttype.Library,
346391
Category: "library.properties",

check/checkfunctions/library.go

+41
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,52 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output
317317
return checkresult.Pass, ""
318318
}
319319

320+
// LibraryPropertiesSentenceFieldMissing checks for missing library.properties "sentence" field.
321+
func LibraryPropertiesSentenceFieldMissing() (result checkresult.Type, output string) {
322+
if checkdata.LibraryPropertiesLoadError() != nil {
323+
return checkresult.NotRun, ""
324+
}
325+
326+
if schema.RequiredPropertyMissing("sentence", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
327+
return checkresult.Fail, ""
328+
}
329+
return checkresult.Pass, ""
330+
}
331+
332+
// LibraryPropertiesSentenceFieldLTMinLength checks if the library.properties "sentence" value is less than the minimum length.
333+
func LibraryPropertiesSentenceFieldLTMinLength() (result checkresult.Type, output string) {
334+
if checkdata.LibraryPropertiesLoadError() != nil {
335+
return checkresult.NotRun, ""
336+
}
337+
338+
if !checkdata.LibraryProperties().ContainsKey("sentence") {
339+
return checkresult.NotRun, ""
340+
}
341+
342+
if schema.PropertyLessThanMinLength("sentence", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
343+
return checkresult.Fail, ""
344+
}
345+
346+
return checkresult.Pass, ""
347+
}
348+
320349
// LibraryPropertiesSentenceFieldSpellCheck checks for commonly misspelled words in the library.properties `sentence` field value.
321350
func LibraryPropertiesSentenceFieldSpellCheck() (result checkresult.Type, output string) {
322351
return spellCheckLibraryPropertiesFieldValue("sentence")
323352
}
324353

354+
// LibraryPropertiesParagraphFieldMissing checks for missing library.properties "paragraph" field.
355+
func LibraryPropertiesParagraphFieldMissing() (result checkresult.Type, output string) {
356+
if checkdata.LibraryPropertiesLoadError() != nil {
357+
return checkresult.NotRun, ""
358+
}
359+
360+
if schema.RequiredPropertyMissing("paragraph", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
361+
return checkresult.Fail, ""
362+
}
363+
return checkresult.Pass, ""
364+
}
365+
325366
// LibraryPropertiesParagraphFieldSpellCheck checks for commonly misspelled words in the library.properties `paragraph` field value.
326367
func LibraryPropertiesParagraphFieldSpellCheck() (result checkresult.Type, output string) {
327368
return spellCheckLibraryPropertiesFieldValue("paragraph")

0 commit comments

Comments
 (0)