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 b78bb83

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

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
 

‎check/checkconfigurations/checkconfigurations.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,51 @@ var configurations = []Type{
146146
ErrorModes: []checkmode.Type{checkmode.All},
147147
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldMissing,
148148
},
149+
{
150+
ProjectType: projecttype.Library,
151+
Category: "library.properties",
152+
Subcategory: "category field",
153+
ID: "",
154+
Brief: "missing category field",
155+
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
156+
MessageTemplate: "missing category field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
157+
DisableModes: nil,
158+
EnableModes: []checkmode.Type{checkmode.All},
159+
InfoModes: nil,
160+
WarningModes: []checkmode.Type{checkmode.All},
161+
ErrorModes: nil,
162+
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldMissing,
163+
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "category field",
168+
ID: "",
169+
Brief: "invalid category value",
170+
Description: `This can cause a warning and results in the default "Uncategorized" category being used.`,
171+
MessageTemplate: "invalid category field value {{.}} in library.properties. 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.LibraryPropertiesCategoryFieldInvalid,
178+
},
179+
{
180+
ProjectType: projecttype.Library,
181+
Category: "library.properties",
182+
Subcategory: "category field",
183+
ID: "",
184+
Brief: `"Uncategorized" category value`,
185+
Description: "There is no good reason for using this non-specification compliant category value.",
186+
MessageTemplate: `Use of "Uncategorized" category value in library.properties. Please use one of the supported categories listed at https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format`,
187+
DisableModes: nil,
188+
EnableModes: []checkmode.Type{checkmode.All},
189+
InfoModes: nil,
190+
WarningModes: []checkmode.Type{checkmode.All},
191+
ErrorModes: nil,
192+
CheckFunction: checkfunctions.LibraryPropertiesCategoryFieldUncategorized,
193+
},
149194
{
150195
ProjectType: projecttype.Library,
151196
Category: "library.properties",

‎check/checkfunctions/library.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,54 @@ func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output str
110110
return checkresult.Pass, ""
111111
}
112112

113+
// LibraryPropertiesCategoryFieldMissing checks for missing library.properties "category" field.
114+
func LibraryPropertiesCategoryFieldMissing() (result checkresult.Type, output string) {
115+
if checkdata.LibraryPropertiesLoadError() != nil {
116+
return checkresult.NotRun, ""
117+
}
118+
119+
if schema.RequiredPropertyMissing("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
120+
return checkresult.Fail, ""
121+
}
122+
return checkresult.Pass, ""
123+
}
124+
125+
// LibraryPropertiesCategoryFieldInvalid checks for invalid category in the library.properties "category" field.
126+
func LibraryPropertiesCategoryFieldInvalid() (result checkresult.Type, output string) {
127+
if checkdata.LibraryPropertiesLoadError() != nil {
128+
return checkresult.NotRun, ""
129+
}
130+
131+
category, ok := checkdata.LibraryProperties().GetOk("category")
132+
if !ok {
133+
return checkresult.NotRun, ""
134+
}
135+
136+
if schema.PropertyEnumMismatch("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
137+
return checkresult.Fail, category
138+
}
139+
140+
return checkresult.Pass, ""
141+
}
142+
143+
// LibraryPropertiesCategoryFieldUncategorized checks whether the library.properties "category" value is "Uncategorized".
144+
func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, output string) {
145+
if checkdata.LibraryPropertiesLoadError() != nil {
146+
return checkresult.NotRun, ""
147+
}
148+
149+
category, ok := checkdata.LibraryProperties().GetOk("category")
150+
if !ok {
151+
return checkresult.NotRun, ""
152+
}
153+
154+
if category == "Uncategorized" {
155+
return checkresult.Fail, ""
156+
}
157+
158+
return checkresult.Pass, ""
159+
}
160+
113161
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114162
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115163
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.