Skip to content

Commit 4cd688c

Browse files
authored
Merge pull request #65 from arduino/per1234/legacy-library-check
Add check for legacy library
2 parents 7bd821e + a29e5a2 commit 4cd688c

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ func Configurations() []Type {
5656

5757
// configurations is an array of structs that define the configuration of each check.
5858
var configurations = []Type{
59+
{
60+
ProjectType: projecttype.Library,
61+
Category: "library.properties",
62+
Subcategory: "general",
63+
ID: "LP001",
64+
Brief: "missing",
65+
Description: `Although not required for 1.0 format libraries (AKA "legacy") not in Library Manager, metadata is useful, so it is recommended.`,
66+
MessageTemplate: "Library has no library.properties metadata file. This file provides useful information and is required for admission to the Library Manager index. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
67+
DisableModes: nil,
68+
EnableModes: []checkmode.Type{checkmode.All},
69+
InfoModes: nil,
70+
WarningModes: []checkmode.Type{checkmode.Default},
71+
ErrorModes: []checkmode.Type{checkmode.LibraryManagerSubmission, checkmode.LibraryManagerIndexed},
72+
CheckFunction: checkfunctions.LibraryPropertiesMissing,
73+
},
5974
{
6075
ProjectType: projecttype.Library,
6176
Category: "library.properties",

check/checkfunctions/library.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func LibraryPropertiesFormat() (result checkresult.Type, output string) {
4343
return checkresult.Pass, ""
4444
}
4545

46+
// LibraryPropertiesMissing checks for presence of library.properties.
47+
func LibraryPropertiesMissing() (result checkresult.Type, output string) {
48+
if checkdata.LoadedLibrary().IsLegacy {
49+
return checkresult.Fail, ""
50+
}
51+
52+
return checkresult.Pass, ""
53+
}
54+
4655
// MisspelledLibraryPropertiesFileName checks for incorrectly spelled library.properties file name.
4756
func MisspelledLibraryPropertiesFileName() (result checkresult.Type, output string) {
4857
directoryListing, err := checkdata.ProjectPath().ReadDir()

check/checkfunctions/library_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
7373
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
7474
}
7575

76+
func TestLibraryPropertiesMissing(t *testing.T) {
77+
testTables := []libraryCheckFunctionTestTable{
78+
{"Legacy", "Legacy", checkresult.Fail, ""},
79+
{"Flat non-legacy", "Flat", checkresult.Pass, ""},
80+
{"Recursive", "Recursive", checkresult.Pass, ""},
81+
}
82+
83+
checkLibraryCheckFunction(LibraryPropertiesMissing, testTables, t)
84+
}
85+
7686
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
7787
testTables := []libraryCheckFunctionTestTable{
7888
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
@@ -197,7 +207,7 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
197207
{"Flat layout", "PrecompiledFlat", checkresult.Fail, "^true$"},
198208
{"Recursive layout", "Precompiled", checkresult.Pass, ""},
199209
{"Recursive, not precompiled", "NotPrecompiled", checkresult.NotRun, ""},
200-
{"Flat, not precompiled", "NotPrecompiledFlat", checkresult.NotRun, ""},
210+
{"Flat, not precompiled", "Flat", checkresult.NotRun, ""},
201211
}
202212

203213
checkLibraryCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)

check/checkfunctions/testdata/libraries/NotPrecompiledFlat/library.properties renamed to check/checkfunctions/testdata/libraries/Flat/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name=NotPrecompiledFlat
1+
name=Flat
22
version=1.0.0
33
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
44
maintainer=Cristian Maglie <[email protected]>

check/checkfunctions/testdata/libraries/Legacy/Legacy.h

Whitespace-only changes.

0 commit comments

Comments
 (0)