Skip to content

Commit 47ad597

Browse files
authored
Merge pull request #51 from arduino/per1234/precompiled-schema-checks
Add schema provided checks for library.properties precompiled field
2 parents 543fc7d + 2911dbf commit 47ad597

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,21 @@ var configurations = []Type{
701701
ErrorModes: []checkmode.Type{checkmode.Default},
702702
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldLTMinLength,
703703
},
704+
{
705+
ProjectType: projecttype.Library,
706+
Category: "library.properties",
707+
Subcategory: "precompiled field",
708+
ID: "",
709+
Brief: "invalid value",
710+
Description: "",
711+
MessageTemplate: "invalid precompiled field value {{.}} in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
712+
DisableModes: nil,
713+
EnableModes: []checkmode.Type{checkmode.All},
714+
InfoModes: nil,
715+
WarningModes: []checkmode.Type{checkmode.Permissive},
716+
ErrorModes: []checkmode.Type{checkmode.Default},
717+
CheckFunction: checkfunctions.LibraryPropertiesPrecompiledFieldInvalid,
718+
},
704719
{
705720
ProjectType: projecttype.Library,
706721
Category: "library.properties",

check/checkfunctions/library.go

+18
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,24 @@ func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, outpu
723723
return checkresult.Pass, ""
724724
}
725725

726+
// LibraryPropertiesPrecompiledFieldInvalid checks for invalid value in the library.properties "precompiled" field.
727+
func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output string) {
728+
if checkdata.LibraryPropertiesLoadError() != nil {
729+
return checkresult.NotRun, ""
730+
}
731+
732+
precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled")
733+
if !ok {
734+
return checkresult.NotRun, ""
735+
}
736+
737+
if schema.PropertyEnumMismatch("precompiled", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
738+
return checkresult.Fail, precompiled
739+
}
740+
741+
return checkresult.Pass, ""
742+
}
743+
726744
// LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout checks whether a precompiled library has the required recursive layout type.
727745
func LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout() (result checkresult.Type, output string) {
728746
if checkdata.LoadedLibrary() == nil || checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)