Skip to content

Add schema provided checks for library.properties maintainer/email field #41

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
90 changes: 90 additions & 0 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
@@ -326,6 +326,96 @@ var configurations = []Type{
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesAuthorFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "maintainer field",
ID: "",
Brief: "missing maintainer field",
Description: "",
MessageTemplate: "missing required maintainer 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.LibraryPropertiesMaintainerFieldMissing,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "maintainer field",
ID: "",
Brief: "maintainer < min length",
Description: "",
MessageTemplate: "library.properties maintainer value is less than minimum length",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: nil,
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "maintainer field",
ID: "",
Brief: `starts with "Arduino"`,
Description: "Case insensitive.",
MessageTemplate: `library.properties maintainer value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
DisableModes: []checkmode.Type{checkmode.Official},
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldStartsWithArduino,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "email field",
ID: "",
Brief: `"email" field used as alias for "maintainer"`,
Description: "This was in an early draft of the beta 1.5 library specification.",
MessageTemplate: `library.properties "email" field used as alias for "maintainer". This is deprecated.`,
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldAsMaintainerAlias,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "email field",
ID: "",
Brief: "email < min length",
Description: "",
MessageTemplate: "library.properties email value is less than minimum length",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: nil,
ErrorModes: []checkmode.Type{checkmode.All},
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "email field",
ID: "",
Brief: `starts with "Arduino"`,
Description: "Case insensitive.",
MessageTemplate: `library.properties email value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
DisableModes: []checkmode.Type{checkmode.Official},
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldStartsWithArduino,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
103 changes: 103 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
@@ -317,6 +317,109 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output
return checkresult.Pass, ""
}

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

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

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

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

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

return checkresult.Pass, ""
}

// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "maintainer" value starts with "Arduino".
func LibraryPropertiesMaintainerFieldStartsWithArduino() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

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

if schema.ValidationErrorMatch("^#/maintainer$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
return checkresult.Fail, maintainer
}

return checkresult.Pass, ""
}

// LibraryPropertiesEmailFieldAsMaintainerAlias checks whether the library.properties "email" field is being used as an alias for the "maintainer" field.
func LibraryPropertiesEmailFieldAsMaintainerAlias() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

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

if !checkdata.LibraryProperties().ContainsKey("maintainer") {
return checkresult.Fail, ""
}

return checkresult.Pass, ""
}

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

if checkdata.LibraryProperties().ContainsKey("maintainer") || !checkdata.LibraryProperties().ContainsKey("email") {
return checkresult.NotRun, ""
}

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

return checkresult.Pass, ""
}

// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "email" value starts with "Arduino".
func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

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

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

if schema.ValidationErrorMatch("^#/email$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
return checkresult.Fail, email
}

return checkresult.Pass, ""
}

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