Skip to content

Commit c149520

Browse files
committed
Add schema provided checks for library.properties maintainer/email field
1 parent 336fc8f commit c149520

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+90
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,96 @@ var configurations = []Type{
146146
ErrorModes: []checkmode.Type{checkmode.All},
147147
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldMissing,
148148
},
149+
{
150+
ProjectType: projecttype.Library,
151+
Category: "library.properties",
152+
Subcategory: "maintainer field",
153+
ID: "",
154+
Brief: "missing maintainer field",
155+
Description: "",
156+
MessageTemplate: "missing required maintainer field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
157+
DisableModes: nil,
158+
EnableModes: []checkmode.Type{checkmode.All},
159+
InfoModes: nil,
160+
WarningModes: nil,
161+
ErrorModes: []checkmode.Type{checkmode.All},
162+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldMissing,
163+
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "maintainer field",
168+
ID: "",
169+
Brief: "maintainer < min length",
170+
Description: "",
171+
MessageTemplate: "library.properties maintainer value is less than minimum length",
172+
DisableModes: nil,
173+
EnableModes: []checkmode.Type{checkmode.All},
174+
InfoModes: nil,
175+
WarningModes: nil,
176+
ErrorModes: []checkmode.Type{checkmode.All},
177+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldLTMinLength,
178+
},
179+
{
180+
ProjectType: projecttype.Library,
181+
Category: "library.properties",
182+
Subcategory: "maintainer field",
183+
ID: "",
184+
Brief: `starts with "Arduino"`,
185+
Description: "Case insensitive.",
186+
MessageTemplate: `library.properties maintainer value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
187+
DisableModes: []checkmode.Type{checkmode.Official},
188+
EnableModes: []checkmode.Type{checkmode.Default},
189+
InfoModes: nil,
190+
WarningModes: []checkmode.Type{checkmode.All},
191+
ErrorModes: nil,
192+
CheckFunction: checkfunctions.LibraryPropertiesMaintainerFieldStartsWithArduino,
193+
},
194+
{
195+
ProjectType: projecttype.Library,
196+
Category: "library.properties",
197+
Subcategory: "email field",
198+
ID: "",
199+
Brief: `"email" field used as alias for "maintainer"`,
200+
Description: "This was in an early draft of the beta 1.5 library specification.",
201+
MessageTemplate: `library.properties "email" field used as alias for "maintainer". This is deprecated.`,
202+
DisableModes: nil,
203+
EnableModes: []checkmode.Type{checkmode.All},
204+
InfoModes: nil,
205+
WarningModes: []checkmode.Type{checkmode.Permissive},
206+
ErrorModes: []checkmode.Type{checkmode.Default},
207+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldAsMaintainerAlias,
208+
},
209+
{
210+
ProjectType: projecttype.Library,
211+
Category: "library.properties",
212+
Subcategory: "email field",
213+
ID: "",
214+
Brief: "email < min length",
215+
Description: "",
216+
MessageTemplate: "library.properties email value is less than minimum length",
217+
DisableModes: nil,
218+
EnableModes: []checkmode.Type{checkmode.All},
219+
InfoModes: nil,
220+
WarningModes: nil,
221+
ErrorModes: []checkmode.Type{checkmode.All},
222+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldLTMinLength,
223+
},
224+
{
225+
ProjectType: projecttype.Library,
226+
Category: "library.properties",
227+
Subcategory: "email field",
228+
ID: "",
229+
Brief: `starts with "Arduino"`,
230+
Description: "Case insensitive.",
231+
MessageTemplate: `library.properties email value {{.}} starts with "Arduino". 3rd party libraries are not maintained by Arduino.`,
232+
DisableModes: []checkmode.Type{checkmode.Official},
233+
EnableModes: []checkmode.Type{checkmode.Default},
234+
InfoModes: nil,
235+
WarningModes: []checkmode.Type{checkmode.All},
236+
ErrorModes: nil,
237+
CheckFunction: checkfunctions.LibraryPropertiesEmailFieldStartsWithArduino,
238+
},
149239
{
150240
ProjectType: projecttype.Library,
151241
Category: "library.properties",

check/checkfunctions/library.go

+103
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,109 @@ func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output str
110110
return checkresult.Pass, ""
111111
}
112112

113+
// LibraryPropertiesMaintainerFieldMissing checks for missing library.properties "maintainer" field.
114+
func LibraryPropertiesMaintainerFieldMissing() (result checkresult.Type, output string) {
115+
if checkdata.LibraryPropertiesLoadError() != nil {
116+
return checkresult.NotRun, ""
117+
}
118+
119+
if schema.RequiredPropertyMissing("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
120+
return checkresult.Fail, ""
121+
}
122+
return checkresult.Pass, ""
123+
}
124+
125+
// LibraryPropertiesMaintainerFieldLTMinLength checks if the library.properties "maintainer" value is less than the minimum length.
126+
func LibraryPropertiesMaintainerFieldLTMinLength() (result checkresult.Type, output string) {
127+
if checkdata.LibraryPropertiesLoadError() != nil {
128+
return checkresult.NotRun, ""
129+
}
130+
131+
if !checkdata.LibraryProperties().ContainsKey("maintainer") {
132+
return checkresult.NotRun, ""
133+
}
134+
135+
if schema.PropertyLessThanMinLength("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
136+
return checkresult.Fail, ""
137+
}
138+
139+
return checkresult.Pass, ""
140+
}
141+
142+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "maintainer" value starts with "Arduino".
143+
func LibraryPropertiesMaintainerFieldStartsWithArduino() (result checkresult.Type, output string) {
144+
if checkdata.LibraryPropertiesLoadError() != nil {
145+
return checkresult.NotRun, ""
146+
}
147+
148+
maintainer, ok := checkdata.LibraryProperties().GetOk("maintainer")
149+
if !ok {
150+
return checkresult.NotRun, ""
151+
}
152+
153+
if schema.ValidationErrorMatch("^#/maintainer$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
154+
return checkresult.Fail, maintainer
155+
}
156+
157+
return checkresult.Pass, ""
158+
}
159+
160+
// LibraryPropertiesEmailFieldAsMaintainerAlias checks whether the library.properties "email" field is being used as an alias for the "maintainer" field.
161+
func LibraryPropertiesEmailFieldAsMaintainerAlias() (result checkresult.Type, output string) {
162+
if checkdata.LibraryPropertiesLoadError() != nil {
163+
return checkresult.NotRun, ""
164+
}
165+
166+
if !checkdata.LibraryProperties().ContainsKey("email") {
167+
return checkresult.NotRun, ""
168+
}
169+
170+
if !checkdata.LibraryProperties().ContainsKey("maintainer") {
171+
return checkresult.Fail, ""
172+
}
173+
174+
return checkresult.Pass, ""
175+
}
176+
177+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "email" value is less than the minimum length.
178+
func LibraryPropertiesEmailFieldLTMinLength() (result checkresult.Type, output string) {
179+
if checkdata.LibraryPropertiesLoadError() != nil {
180+
return checkresult.NotRun, ""
181+
}
182+
183+
if checkdata.LibraryProperties().ContainsKey("maintainer") || !checkdata.LibraryProperties().ContainsKey("email") {
184+
return checkresult.NotRun, ""
185+
}
186+
187+
if schema.PropertyLessThanMinLength("email", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
188+
return checkresult.Fail, ""
189+
}
190+
191+
return checkresult.Pass, ""
192+
}
193+
194+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "email" value starts with "Arduino".
195+
func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, output string) {
196+
if checkdata.LibraryPropertiesLoadError() != nil {
197+
return checkresult.NotRun, ""
198+
}
199+
200+
if checkdata.LibraryProperties().ContainsKey("maintainer") {
201+
return checkresult.NotRun, ""
202+
}
203+
204+
email, ok := checkdata.LibraryProperties().GetOk("email")
205+
if !ok {
206+
return checkresult.NotRun, ""
207+
}
208+
209+
if schema.ValidationErrorMatch("^#/email$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
210+
return checkresult.Fail, email
211+
}
212+
213+
return checkresult.Pass, ""
214+
}
215+
113216
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114217
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115218
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)