Skip to content

Commit ba874d0

Browse files
committed
Add check for incorrect library.properties file name case
1 parent 4cd688c commit ba874d0

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ var configurations = []Type{
101101
ErrorModes: []checkmode.Type{checkmode.Default},
102102
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
103103
},
104+
{
105+
ProjectType: projecttype.Library,
106+
Category: "library.properties",
107+
Subcategory: "general",
108+
ID: "",
109+
Brief: "incorrect library.properties file name case",
110+
Description: `This causes "1.5" format (AKA "recursive layout") libraries to not be recognized on filename case-sensitive operating systems.`,
111+
MessageTemplate: "Incorrect library.properties file name case: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
112+
DisableModes: nil,
113+
EnableModes: []checkmode.Type{checkmode.All},
114+
InfoModes: nil,
115+
WarningModes: nil,
116+
ErrorModes: []checkmode.Type{checkmode.All},
117+
CheckFunction: checkfunctions.IncorrectLibraryPropertiesFileNameCase,
118+
},
104119
{
105120
ProjectType: projecttype.Library,
106121
Category: "library.properties",

check/checkfunctions/checkfunctions.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package checkfunctions
1818

1919
import (
2020
"regexp"
21+
"strings"
2122

2223
"github.com/arduino/arduino-check/check/checkresult"
2324
"github.com/arduino/go-paths-helper"
@@ -47,3 +48,19 @@ func containsMisspelledPathBaseName(pathList paths.PathList, correctBaseName str
4748

4849
return nil, false
4950
}
51+
52+
func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName string) (*paths.Path, bool) {
53+
for _, path := range pathList {
54+
if path.Base() == correctBaseName {
55+
// There was a case-sensitive match (paths package's Exist() is not always case-sensitive, so can't be used here).
56+
return nil, false
57+
}
58+
59+
if strings.EqualFold(path.Base(), correctBaseName) {
60+
// There was a case-insensitive match.
61+
return path, true
62+
}
63+
}
64+
65+
return nil, false
66+
}

check/checkfunctions/library.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ func MisspelledLibraryPropertiesFileName() (result checkresult.Type, output stri
6868
return checkresult.Pass, ""
6969
}
7070

71+
// IncorrectLibraryPropertiesFileNameCase checks for incorrect library.properties file name case.
72+
func IncorrectLibraryPropertiesFileNameCase() (result checkresult.Type, output string) {
73+
directoryListing, err := checkdata.ProjectPath().ReadDir()
74+
if err != nil {
75+
panic(err)
76+
}
77+
directoryListing.FilterOutDirs()
78+
79+
path, found := containsIncorrectPathBaseCase(directoryListing, "library.properties")
80+
if found {
81+
return checkresult.Fail, path.String()
82+
}
83+
84+
return checkresult.Pass, ""
85+
}
86+
7187
// LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field.
7288
func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) {
7389
if checkdata.LibraryPropertiesLoadError() != nil {

check/checkfunctions/library_test.go

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

76+
func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) {
77+
testTables := []libraryCheckFunctionTestTable{
78+
{"Incorrect", "IncorrectLibraryPropertiesCase", checkresult.Fail, ""},
79+
{"Correct", "Recursive", checkresult.Pass, ""},
80+
}
81+
82+
checkLibraryCheckFunction(IncorrectLibraryPropertiesFileNameCase, testTables, t)
83+
}
84+
7685
func TestLibraryPropertiesMissing(t *testing.T) {
7786
testTables := []libraryCheckFunctionTestTable{
7887
{"Legacy", "Legacy", checkresult.Fail, ""},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=IncorrectLibraryPropertiesCase
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/IncorrectLibraryPropertiesCase/src/IncorrectLibraryPropertiesCase.h

Whitespace-only changes.

0 commit comments

Comments
 (0)