Skip to content

Commit b34a379

Browse files
authored
Merge pull request #62 from arduino/per1234/name-length-check
Add checks for library and sketch base path names exceeding maximum length
2 parents 84919e1 + f8f0278 commit b34a379

File tree

9 files changed

+89
-0
lines changed

9 files changed

+89
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+30
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,36 @@ 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+
},
899+
{
900+
ProjectType: projecttype.Sketch,
901+
Category: "structure",
902+
Subcategory: "",
903+
ID: "",
904+
Brief: "file name too long",
905+
Description: "",
906+
MessageTemplate: "File name(s): {{.}} exceed maximum length. See: https://arduino.github.io/arduino-cli/latest/sketch-specification/#sketch-root-folder",
907+
DisableModes: nil,
908+
EnableModes: []checkmode.Type{checkmode.All},
909+
InfoModes: nil,
910+
WarningModes: nil,
911+
ErrorModes: []checkmode.Type{checkmode.All},
912+
CheckFunction: checkfunctions.SketchFileNameGTMaxLength,
913+
},
884914
{
885915
ProjectType: projecttype.Sketch,
886916
Category: "structure",

Diff for: 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 {

Diff for: 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+
}

Diff for: check/checkfunctions/sketch.go

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ func ProhibitedCharactersInSketchFileName() (result checkresult.Type, output str
4646
return checkresult.Pass, ""
4747
}
4848

49+
// SketchFileNameGTMaxLength checks if the sketch file names exceed the maximum length.
50+
func SketchFileNameGTMaxLength() (result checkresult.Type, output string) {
51+
directoryListing, _ := checkdata.ProjectPath().ReadDir()
52+
directoryListing.FilterOutDirs()
53+
54+
foundTooLongSketchFileNames := []string{}
55+
for _, potentialSketchFile := range directoryListing {
56+
if sketch.HasSupportedExtension(potentialSketchFile) {
57+
if len(potentialSketchFile.Base())-len(potentialSketchFile.Ext()) > 63 {
58+
foundTooLongSketchFileNames = append(foundTooLongSketchFileNames, potentialSketchFile.Base())
59+
}
60+
}
61+
}
62+
63+
if len(foundTooLongSketchFileNames) > 0 {
64+
return checkresult.Fail, strings.Join(foundTooLongSketchFileNames, ", ")
65+
}
66+
67+
return checkresult.Pass, ""
68+
}
69+
4970
// PdeSketchExtension checks for use of deprecated .pde sketch file extensions.
5071
func PdeSketchExtension() (result checkresult.Type, output string) {
5172
directoryListing, _ := checkdata.ProjectPath().ReadDir()

Diff for: check/checkfunctions/sketch_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ func TestProhibitedCharactersInSketchFileName(t *testing.T) {
6868

6969
checkSketchCheckFunction(ProhibitedCharactersInSketchFileName, testTables, t)
7070
}
71+
72+
func TestSketchFileNameGTMaxLength(t *testing.T) {
73+
testTables := []sketchCheckFunctionTestTable{
74+
{"Has file name > max length", "FileNameTooLong", checkresult.Fail, "^FileNameTooLong12345678901234567890123456789012345678901234567890.h$"},
75+
{"File names <= max length", "Valid", checkresult.Pass, ""},
76+
}
77+
78+
checkSketchCheckFunction(SketchFileNameGTMaxLength, testTables, t)
79+
}
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

Diff for: check/checkfunctions/testdata/libraries/FolderNameTooLong12345678901234567890123456789012345678901234567890/src/FolderNameTooLong.h

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

Diff for: check/checkfunctions/testdata/sketches/FileNameTooLong/FileNameTooLong12345678901234567890123456789012345678901234567890.h

Whitespace-only changes.

0 commit comments

Comments
 (0)