Skip to content

Add schema provided checks for library.properties sentence and paragraph fields #40

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
Show file tree
Hide file tree
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
Expand Up @@ -326,6 +326,36 @@ var configurations = []Type{
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "sentence field",
ID: "",
Brief: "missing sentence field",
Description: "",
MessageTemplate: "missing required sentence 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: nil,
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldMissing,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "sentence field",
ID: "",
Brief: "sentence < min length",
Description: "",
MessageTemplate: "library.properties sentence value is less than minimum length",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: nil,
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Expand All @@ -341,6 +371,21 @@ var configurations = []Type{
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesSentenceFieldSpellCheck,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "paragraph field",
ID: "",
Brief: "missing paragraph field",
Description: "",
MessageTemplate: "missing required paragraph 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: nil,
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldMissing,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Expand Down
41 changes: 41 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,52 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output
return checkresult.Pass, ""
}

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

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

// LibraryPropertiesSentenceFieldLTMinLength checks if the library.properties "sentence" value is less than the minimum length.
func LibraryPropertiesSentenceFieldLTMinLength() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

if !checkdata.LibraryProperties().ContainsKey("sentence") {
return checkresult.NotRun, ""
}

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

return checkresult.Pass, ""
}

// LibraryPropertiesSentenceFieldSpellCheck checks for commonly misspelled words in the library.properties `sentence` field value.
func LibraryPropertiesSentenceFieldSpellCheck() (result checkresult.Type, output string) {
return spellCheckLibraryPropertiesFieldValue("sentence")
}

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

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

// LibraryPropertiesParagraphFieldSpellCheck checks for commonly misspelled words in the library.properties `paragraph` field value.
func LibraryPropertiesParagraphFieldSpellCheck() (result checkresult.Type, output string) {
return spellCheckLibraryPropertiesFieldValue("paragraph")
Expand Down