Skip to content

Commit d31d68f

Browse files
committed
Add schema provided checks for library.properties precompiled field
1 parent 336fc8f commit d31d68f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ var configurations = []Type{
161161
ErrorModes: nil,
162162
CheckFunction: checkfunctions.LibraryPropertiesDependsFieldNotInIndex,
163163
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "precompiled field",
168+
ID: "",
169+
Brief: "invalid value",
170+
Description: "",
171+
MessageTemplate: "invalid precompiled field value {{.}} in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
172+
DisableModes: nil,
173+
EnableModes: []checkmode.Type{checkmode.All},
174+
InfoModes: nil,
175+
WarningModes: []checkmode.Type{checkmode.Permissive},
176+
ErrorModes: []checkmode.Type{checkmode.Default},
177+
CheckFunction: checkfunctions.LibraryPropertiesPrecompiledFieldInvalid,
178+
},
164179
{
165180
ProjectType: projecttype.Sketch,
166181
Category: "structure",

check/checkfunctions/library.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output
140140
return checkresult.Pass, ""
141141
}
142142

143+
// LibraryPropertiesPrecompiledFieldInvalid checks for invalid value in the library.properties "precompiled" field.
144+
func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output string) {
145+
if checkdata.LibraryPropertiesLoadError() != nil {
146+
return checkresult.NotRun, ""
147+
}
148+
149+
precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled")
150+
if !ok {
151+
return checkresult.NotRun, ""
152+
}
153+
154+
if schema.PropertyEnumMismatch("precompiled", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
155+
return checkresult.Fail, precompiled
156+
}
157+
158+
return checkresult.Pass, ""
159+
}
160+
143161
// nameInLibraryManagerIndex returns whether there is a library in Library Manager index using the given name.
144162
func nameInLibraryManagerIndex(name string) bool {
145163
libraries := checkdata.LibraryManagerIndex()["libraries"].([]interface{})

0 commit comments

Comments
 (0)