Skip to content

Commit 5f80c01

Browse files
committedNov 24, 2020
Add schema provided checks for library.properties maintainer/email field
1 parent 336fc8f commit 5f80c01

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
 

‎check/checkconfigurations/checkconfigurations.go

Lines changed: 90 additions & 0 deletions
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

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,110 @@ 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+
_, ok := checkdata.LibraryProperties().GetOk("maintainer")
132+
if !ok {
133+
return checkresult.NotRun, ""
134+
}
135+
136+
if schema.PropertyLessThanMinLength("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
137+
return checkresult.Fail, ""
138+
}
139+
140+
return checkresult.Pass, ""
141+
}
142+
143+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "maintainer" value starts with "Arduino".
144+
func LibraryPropertiesMaintainerFieldStartsWithArduino() (result checkresult.Type, output string) {
145+
if checkdata.LibraryPropertiesLoadError() != nil {
146+
return checkresult.NotRun, ""
147+
}
148+
149+
maintainer, ok := checkdata.LibraryProperties().GetOk("maintainer")
150+
if !ok {
151+
return checkresult.NotRun, ""
152+
}
153+
154+
if schema.ValidationErrorMatch("^#/maintainer$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
155+
return checkresult.Fail, maintainer
156+
}
157+
158+
return checkresult.Pass, ""
159+
}
160+
161+
// LibraryPropertiesEmailFieldAsMaintainerAlias checks whether the library.properties "email" field is being used as an alias for the "maintainer" field.
162+
func LibraryPropertiesEmailFieldAsMaintainerAlias() (result checkresult.Type, output string) {
163+
if checkdata.LibraryPropertiesLoadError() != nil {
164+
return checkresult.NotRun, ""
165+
}
166+
167+
_, ok := checkdata.LibraryProperties().GetOk("maintainer")
168+
if !ok {
169+
_, ok = checkdata.LibraryProperties().GetOk("email")
170+
if ok {
171+
return checkresult.Fail, ""
172+
}
173+
}
174+
175+
return checkresult.Pass, ""
176+
}
177+
178+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "email" value is less than the minimum length.
179+
func LibraryPropertiesEmailFieldLTMinLength() (result checkresult.Type, output string) {
180+
if checkdata.LibraryPropertiesLoadError() != nil {
181+
return checkresult.NotRun, ""
182+
}
183+
184+
_, ok := checkdata.LibraryProperties().GetOk("maintainer")
185+
if !ok {
186+
187+
if schema.PropertyLessThanMinLength("email", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
188+
return checkresult.Fail, ""
189+
}
190+
}
191+
192+
return checkresult.Pass, ""
193+
}
194+
195+
// LibraryPropertiesMaintainerFieldStartsWithArduino checks if the library.properties "email" value starts with "Arduino".
196+
func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, output string) {
197+
if checkdata.LibraryPropertiesLoadError() != nil {
198+
return checkresult.NotRun, ""
199+
}
200+
201+
_, ok := checkdata.LibraryProperties().GetOk("maintainer")
202+
if !ok {
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+
214+
return checkresult.Pass, ""
215+
}
216+
113217
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114218
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115219
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)