Skip to content

Commit 5f0c17c

Browse files
authored
Merge pull request #47 from arduino/per1234/depends-schema-checks
Add schema provided checks for library.properties depends field
2 parents 5e3bbff + c947408 commit 5f0c17c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,21 @@ var configurations = []Type{
626626
ErrorModes: []checkmode.Type{checkmode.Default},
627627
CheckFunction: checkfunctions.LibraryPropertiesArchitecturesFieldLTMinLength,
628628
},
629+
{
630+
ProjectType: projecttype.Library,
631+
Category: "library.properties",
632+
Subcategory: "depends field",
633+
ID: "",
634+
Brief: "disallowed characters",
635+
Description: "",
636+
MessageTemplate: "disallowed characters in library.properties depends field {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
637+
DisableModes: nil,
638+
EnableModes: []checkmode.Type{checkmode.All},
639+
InfoModes: nil,
640+
WarningModes: nil,
641+
ErrorModes: []checkmode.Type{checkmode.All},
642+
CheckFunction: checkfunctions.LibraryPropertiesDependsFieldDisallowedCharacters,
643+
},
629644
{
630645
ProjectType: projecttype.Library,
631646
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+18
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,24 @@ func LibraryPropertiesArchitecturesFieldLTMinLength() (result checkresult.Type,
622622
return checkresult.Pass, ""
623623
}
624624

625+
// LibraryPropertiesDependsFieldDisallowedCharacters checks for disallowed characters in the library.properties "depends" field.
626+
func LibraryPropertiesDependsFieldDisallowedCharacters() (result checkresult.Type, output string) {
627+
if checkdata.LibraryPropertiesLoadError() != nil {
628+
return checkresult.NotRun, ""
629+
}
630+
631+
depends, ok := checkdata.LibraryProperties().GetOk("depends")
632+
if !ok {
633+
return checkresult.NotRun, ""
634+
}
635+
636+
if schema.PropertyPatternMismatch("depends", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
637+
return checkresult.Fail, depends
638+
}
639+
640+
return checkresult.Pass, ""
641+
}
642+
625643
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
626644
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
627645
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)