Skip to content

Commit e43541b

Browse files
committed
Add schema provided checks for library.properties category field
1 parent d7b7db7 commit e43541b

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+45
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,51 @@ var configurations = []Type{
506506
ErrorModes: nil,
507507
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldRepeatsSentence,
508508
},
509+
{
510+
ProjectType: projecttype.Library,
511+
Category: "library.properties",
512+
Subcategory: "category field",
513+
ID: "",
514+
Brief: "missing category field",
515+
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
516+
MessageTemplate: "missing category field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
517+
DisableModes: nil,
518+
EnableModes: []checkmode.Type{checkmode.All},
519+
InfoModes: nil,
520+
WarningModes: []checkmode.Type{checkmode.All},
521+
ErrorModes: nil,
522+
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldMissing,
523+
},
524+
{
525+
ProjectType: projecttype.Library,
526+
Category: "library.properties",
527+
Subcategory: "category field",
528+
ID: "",
529+
Brief: "invalid category value",
530+
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
531+
MessageTemplate: "invalid category field value {{.}} in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
532+
DisableModes: nil,
533+
EnableModes: []checkmode.Type{checkmode.All},
534+
InfoModes: nil,
535+
WarningModes: []checkmode.Type{checkmode.Permissive},
536+
ErrorModes: []checkmode.Type{checkmode.Default},
537+
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldInvalid,
538+
},
539+
{
540+
ProjectType: projecttype.Library,
541+
Category: "library.properties",
542+
Subcategory: "category field",
543+
ID: "",
544+
Brief: `"Uncategorized" category value`,
545+
Description: "There is no good reason for using this non-specification compliant category value.",
546+
MessageTemplate: `Use of "Uncategorized" category value in library.properties. Please use one of the supported categories listed at https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format`,
547+
DisableModes: nil,
548+
EnableModes: []checkmode.Type{checkmode.All},
549+
InfoModes: nil,
550+
WarningModes: []checkmode.Type{checkmode.All},
551+
ErrorModes: nil,
552+
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldUncategorized,
553+
},
509554
{
510555
ProjectType: projecttype.Library,
511556
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+48
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,54 @@ func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type,
490490
return checkresult.Pass, ""
491491
}
492492

493+
// LibraryPropertiesCategoryFieldMissing checks for missing library.properties "category" field.
494+
func LibraryPropertiesCategoryFieldMissing() (result checkresult.Type, output string) {
495+
if checkdata.LibraryPropertiesLoadError() != nil {
496+
return checkresult.NotRun, ""
497+
}
498+
499+
if schema.RequiredPropertyMissing("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
500+
return checkresult.Fail, ""
501+
}
502+
return checkresult.Pass, ""
503+
}
504+
505+
// LibraryPropertiesCategoryFieldInvalid checks for invalid category in the library.properties "category" field.
506+
func LibraryPropertiesCategoryFieldInvalid() (result checkresult.Type, output string) {
507+
if checkdata.LibraryPropertiesLoadError() != nil {
508+
return checkresult.NotRun, ""
509+
}
510+
511+
category, ok := checkdata.LibraryProperties().GetOk("category")
512+
if !ok {
513+
return checkresult.NotRun, ""
514+
}
515+
516+
if schema.PropertyEnumMismatch("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
517+
return checkresult.Fail, category
518+
}
519+
520+
return checkresult.Pass, ""
521+
}
522+
523+
// LibraryPropertiesCategoryFieldUncategorized checks whether the library.properties "category" value is "Uncategorized".
524+
func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, output string) {
525+
if checkdata.LibraryPropertiesLoadError() != nil {
526+
return checkresult.NotRun, ""
527+
}
528+
529+
category, ok := checkdata.LibraryProperties().GetOk("category")
530+
if !ok {
531+
return checkresult.NotRun, ""
532+
}
533+
534+
if category == "Uncategorized" {
535+
return checkresult.Fail, ""
536+
}
537+
538+
return checkresult.Pass, ""
539+
}
540+
493541
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
494542
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
495543
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)