Skip to content

Add schema provided checks for library.properties category field #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
@@ -506,6 +506,51 @@ var configurations = []Type{
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldRepeatsSentence,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "category field",
ID: "",
Brief: "missing category field",
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
MessageTemplate: "missing category 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: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldMissing,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "category field",
ID: "",
Brief: "invalid category value",
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
MessageTemplate: "invalid category field value {{.}} 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: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldInvalid,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "category field",
ID: "",
Brief: `"Uncategorized" category value`,
Description: "There is no good reason for using this non-specification compliant category value.",
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`,
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldUncategorized,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
48 changes: 48 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
@@ -490,6 +490,54 @@ func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type,
return checkresult.Pass, ""
}

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

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

// LibraryPropertiesCategoryFieldInvalid checks for invalid category in the library.properties "category" field.
func LibraryPropertiesCategoryFieldInvalid() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

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

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

return checkresult.Pass, ""
}

// LibraryPropertiesCategoryFieldUncategorized checks whether the library.properties "category" value is "Uncategorized".
func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

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

if category == "Uncategorized" {
return checkresult.Fail, ""
}

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 {