Skip to content

Commit 9d98e78

Browse files
committed
Add check for library folder exceeding maximum length
1 parent 84919e1 commit 9d98e78

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,21 @@ var configurations = []Type{
881881
ErrorModes: []checkmode.Type{checkmode.Default},
882882
CheckFunction: checkfunctions.ProhibitedCharactersInSketchFileName,
883883
},
884+
{
885+
ProjectType: projecttype.Library,
886+
Category: "structure",
887+
Subcategory: "",
888+
ID: "",
889+
Brief: "folder name too long",
890+
Description: "This will be problematic for people doing manual installation of the library.",
891+
MessageTemplate: "Folder name {{.}} exceeds maximum length. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-root-folder",
892+
DisableModes: nil,
893+
EnableModes: []checkmode.Type{checkmode.All},
894+
InfoModes: nil,
895+
WarningModes: []checkmode.Type{checkmode.Permissive},
896+
ErrorModes: []checkmode.Type{checkmode.Default},
897+
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
898+
},
884899
{
885900
ProjectType: projecttype.Sketch,
886901
Category: "structure",

check/checkfunctions/library.go

+9
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,15 @@ func ProhibitedCharactersInLibraryFolderName() (result checkresult.Type, output
938938
return checkresult.Pass, ""
939939
}
940940

941+
// LibraryFolderNameGTMaxLength checks if the library folder name exceeds the maximum length.
942+
func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) {
943+
if len(checkdata.ProjectPath().Base()) > 63 {
944+
return checkresult.Fail, checkdata.ProjectPath().Base()
945+
}
946+
947+
return checkresult.Pass, ""
948+
}
949+
941950
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
942951
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
943952
if checkdata.LibraryPropertiesLoadError() != nil {

check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,12 @@ func TestProhibitedCharactersInLibraryFolderName(t *testing.T) {
251251

252252
checkLibraryCheckFunction(ProhibitedCharactersInLibraryFolderName, testTables, t)
253253
}
254+
255+
func TestLibraryFolderNameGTMaxLength(t *testing.T) {
256+
testTables := []libraryCheckFunctionTestTable{
257+
{"Has folder name > max length", "FolderNameTooLong12345678901234567890123456789012345678901234567890", checkresult.Fail, "^FolderNameTooLong12345678901234567890123456789012345678901234567890$"},
258+
{"Folder name <= max length", "Recursive", checkresult.Pass, ""},
259+
}
260+
261+
checkLibraryCheckFunction(LibraryFolderNameGTMaxLength, testTables, t)
262+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=FolderNameTooLong
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/FolderNameTooLong12345678901234567890123456789012345678901234567890/src/FolderNameTooLong.h

Whitespace-only changes.

0 commit comments

Comments
 (0)