Skip to content

Commit a4abdb8

Browse files
committed
Add check for official library name prefix
Because it only applies to official libraries, this check is not provided by the library.properties JSON schemas.
1 parent 887cfc2 commit a4abdb8

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ var configurations = []Type{
176176
ErrorModes: []checkmode.Type{checkmode.Default},
177177
CheckFunction: checkfunctions.LibraryPropertiesNameFieldStartsWithArduino,
178178
},
179+
{
180+
ProjectType: projecttype.Library,
181+
Category: "library.properties",
182+
Subcategory: "name field",
183+
ID: "",
184+
Brief: "missing official prefix",
185+
Description: "",
186+
MessageTemplate: `Library name {{.}} is missing the "Arduino_" prefix. All new official library names must use this prefix.`,
187+
DisableModes: []checkmode.Type{checkmode.Default},
188+
EnableModes: []checkmode.Type{checkmode.Official},
189+
InfoModes: nil,
190+
WarningModes: nil,
191+
ErrorModes: []checkmode.Type{checkmode.Official},
192+
CheckFunction: checkfunctions.LibraryPropertiesNameFieldMissingOfficialPrefix,
193+
},
179194
{
180195
ProjectType: projecttype.Library,
181196
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+17
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ func LibraryPropertiesNameFieldStartsWithArduino() (result checkresult.Type, out
151151
return checkresult.Pass, ""
152152
}
153153

154+
// LibraryPropertiesNameFieldMissingOfficialPrefix checks whether the library.properties `name` value uses the prefix required of all new official Arduino libraries.
155+
func LibraryPropertiesNameFieldMissingOfficialPrefix() (result checkresult.Type, output string) {
156+
if checkdata.LibraryPropertiesLoadError() != nil {
157+
return checkresult.NotRun, ""
158+
}
159+
160+
name, ok := checkdata.LibraryProperties().GetOk("name")
161+
if !ok {
162+
return checkresult.NotRun, ""
163+
}
164+
165+
if strings.HasPrefix(name, "Arduino_") {
166+
return checkresult.Pass, ""
167+
}
168+
return checkresult.Fail, name
169+
}
170+
154171
// LibraryPropertiesNameFieldContainsArduino checks if the library.properties "name" value contains "Arduino".
155172
func LibraryPropertiesNameFieldContainsArduino() (result checkresult.Type, output string) {
156173
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ func checkCheckFunction(checkFunction Type, testTables []checkFunctionTestTable,
6262
}
6363
}
6464

65+
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
66+
testTables := []checkFunctionTestTable{
67+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
68+
{"Not defined", "MissingFields", checkresult.NotRun, ""},
69+
{"Correct prefix", "Arduino_Official", checkresult.Pass, ""},
70+
{"Incorrect prefix", "Recursive", checkresult.Fail, "^Recursive$"},
71+
}
72+
73+
checkCheckFunction(LibraryPropertiesNameFieldMissingOfficialPrefix, testTables, t)
74+
}
75+
6576
func TestLibraryPropertiesNameFieldDuplicate(t *testing.T) {
6677
testTables := []checkFunctionTestTable{
6778
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Arduino_Official
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr

Diff for: check/checkfunctions/testdata/libraries/Arduino_Official/src/Arduino_Official.h

Whitespace-only changes.

0 commit comments

Comments
 (0)