Skip to content

Commit 543fc7d

Browse files
authored
Merge pull request #50 from arduino/per1234/includes-schema-checks
Add schema provided checks for library.properties includes field
2 parents 8bd2f66 + 55ca432 commit 543fc7d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,21 @@ var configurations = []Type{
686686
ErrorModes: []checkmode.Type{checkmode.Default},
687687
CheckFunction: checkfunctions.LibraryPropertiesDotALinkageFieldTrueWithFlatLayout,
688688
},
689+
{
690+
ProjectType: projecttype.Library,
691+
Category: "library.properties",
692+
Subcategory: "includes field",
693+
ID: "",
694+
Brief: "includes blank",
695+
Description: `Caused the "Sketch > Include library" feature of previous IDE versions to add an empty #include directive to the sketch.`,
696+
MessageTemplate: "Empty library.properties includes field. Please either define includes or remove this optional field. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
697+
DisableModes: nil,
698+
EnableModes: []checkmode.Type{checkmode.All},
699+
InfoModes: nil,
700+
WarningModes: []checkmode.Type{checkmode.Permissive},
701+
ErrorModes: []checkmode.Type{checkmode.Default},
702+
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldLTMinLength,
703+
},
689704
{
690705
ProjectType: projecttype.Library,
691706
Category: "library.properties",

check/checkfunctions/library.go

+17
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.T
706706
return checkresult.Pass, ""
707707
}
708708

709+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "includes" value is less than the minimum length.
710+
func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, output string) {
711+
if checkdata.LibraryPropertiesLoadError() != nil {
712+
return checkresult.NotRun, ""
713+
}
714+
715+
if !checkdata.LibraryProperties().ContainsKey("includes") {
716+
return checkresult.NotRun, ""
717+
}
718+
719+
if schema.PropertyLessThanMinLength("includes", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
720+
return checkresult.Fail, ""
721+
}
722+
723+
return checkresult.Pass, ""
724+
}
725+
709726
// LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout checks whether a precompiled library has the required recursive layout type.
710727
func LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout() (result checkresult.Type, output string) {
711728
if checkdata.LoadedLibrary() == nil || checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)