Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 64f04ef

Browse files
committedNov 24, 2020
Add schema provided checks for library.properties includes field
1 parent 336fc8f commit 64f04ef

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-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: "includes field",
168+
ID: "",
169+
Brief: "includes blank",
170+
Description: `Caused the "Sketch > Include library" feature of previous IDE versions to add an empty #include directive to the sketch.`,
171+
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",
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.LibraryPropertiesIncludesFieldLTMinLength,
178+
},
164179
{
165180
ProjectType: projecttype.Sketch,
166181
Category: "structure",

‎check/checkfunctions/library.go

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

143+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "includes" value is less than the minimum length.
144+
func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, output string) {
145+
if checkdata.LibraryPropertiesLoadError() != nil {
146+
return checkresult.NotRun, ""
147+
}
148+
149+
if !checkdata.LibraryProperties().ContainsKey("includes") {
150+
return checkresult.NotRun, ""
151+
}
152+
153+
if schema.PropertyLessThanMinLength("includes", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
154+
return checkresult.Fail, ""
155+
}
156+
157+
return checkresult.Pass, ""
158+
}
159+
143160
// nameInLibraryManagerIndex returns whether there is a library in Library Manager index using the given name.
144161
func nameInLibraryManagerIndex(name string) bool {
145162
libraries := checkdata.LibraryManagerIndex()["libraries"].([]interface{})

0 commit comments

Comments
 (0)
Please sign in to comment.