From 2911dbf32b353f3ad3746235a4492e9556871295 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 23 Nov 2020 22:08:50 -0800 Subject: [PATCH] Add schema provided checks for library.properties precompiled field --- .../checkconfigurations/checkconfigurations.go | 15 +++++++++++++++ check/checkfunctions/library.go | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/check/checkconfigurations/checkconfigurations.go b/check/checkconfigurations/checkconfigurations.go index eaaabac9..360838ae 100644 --- a/check/checkconfigurations/checkconfigurations.go +++ b/check/checkconfigurations/checkconfigurations.go @@ -701,6 +701,21 @@ var configurations = []Type{ ErrorModes: []checkmode.Type{checkmode.Default}, CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldLTMinLength, }, + { + ProjectType: projecttype.Library, + Category: "library.properties", + Subcategory: "precompiled field", + ID: "", + Brief: "invalid value", + Description: "", + MessageTemplate: "invalid precompiled field value {{.}} 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: []checkmode.Type{checkmode.Permissive}, + ErrorModes: []checkmode.Type{checkmode.Default}, + CheckFunction: checkfunctions.LibraryPropertiesPrecompiledFieldInvalid, + }, { ProjectType: projecttype.Library, Category: "library.properties", diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 6990401f..6cbc148d 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -723,6 +723,24 @@ func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, outpu return checkresult.Pass, "" } +// LibraryPropertiesPrecompiledFieldInvalid checks for invalid value in the library.properties "precompiled" field. +func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output string) { + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "" + } + + precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled") + if !ok { + return checkresult.NotRun, "" + } + + if schema.PropertyEnumMismatch("precompiled", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { + return checkresult.Fail, precompiled + } + + return checkresult.Pass, "" +} + // LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout checks whether a precompiled library has the required recursive layout type. func LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout() (result checkresult.Type, output string) { if checkdata.LoadedLibrary() == nil || checkdata.LibraryPropertiesLoadError() != nil {