Skip to content

Commit 06764f5

Browse files
authored
Merge pull request #66 from arduino/per1234/redundant-library_properties-check
Add check for redundant library.properties
2 parents aae52e3 + 073cc06 commit 06764f5

File tree

6 files changed

+52
-0
lines changed

6 files changed

+52
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ var configurations = []Type{
116116
ErrorModes: []checkmode.Type{checkmode.All},
117117
CheckFunction: checkfunctions.IncorrectLibraryPropertiesFileNameCase,
118118
},
119+
{
120+
ProjectType: projecttype.Library,
121+
Category: "library.properties",
122+
Subcategory: "general",
123+
ID: "",
124+
Brief: "redundant",
125+
Description: "",
126+
MessageTemplate: "Redundant library.properties file found at {{.}}. Only the file in the root of the library is used. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
127+
DisableModes: nil,
128+
EnableModes: []checkmode.Type{checkmode.All},
129+
InfoModes: nil,
130+
WarningModes: []checkmode.Type{checkmode.Permissive},
131+
ErrorModes: []checkmode.Type{checkmode.Default},
132+
CheckFunction: checkfunctions.RedundantLibraryProperties,
133+
},
119134
{
120135
ProjectType: projecttype.Library,
121136
Category: "library.properties",

check/checkfunctions/library.go

+10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ func IncorrectLibraryPropertiesFileNameCase() (result checkresult.Type, output s
8484
return checkresult.Pass, ""
8585
}
8686

87+
// RedundantLibraryProperties checks for redundant copies of the library.properties file.
88+
func RedundantLibraryProperties() (result checkresult.Type, output string) {
89+
redundantLibraryPropertiesPath := checkdata.ProjectPath().Join("src", "library.properties")
90+
if redundantLibraryPropertiesPath.Exist() {
91+
return checkresult.Fail, redundantLibraryPropertiesPath.String()
92+
}
93+
94+
return checkresult.Pass, ""
95+
}
96+
8797
// LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field.
8898
func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) {
8999
if checkdata.LibraryPropertiesLoadError() != nil {

check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ func TestLibraryPropertiesMissing(t *testing.T) {
9292
checkLibraryCheckFunction(LibraryPropertiesMissing, testTables, t)
9393
}
9494

95+
func TestRedundantLibraryProperties(t *testing.T) {
96+
testTables := []libraryCheckFunctionTestTable{
97+
{"Redundant", "RedundantLibraryProperties", checkresult.Fail, ""},
98+
{"No redundant", "Recursive", checkresult.Pass, ""},
99+
}
100+
101+
checkLibraryCheckFunction(RedundantLibraryProperties, testTables, t)
102+
}
103+
95104
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
96105
testTables := []libraryCheckFunctionTestTable{
97106
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=RedundantLibraryProperties
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

check/checkfunctions/testdata/libraries/RedundantLibraryProperties/src/RedundantLibraryProperties.h

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=RedundantLibraryProperties
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

0 commit comments

Comments
 (0)