Skip to content

Commit f8f0278

Browse files
committed
Add check for sketch folder exceeding maximum length
1 parent 9d98e78 commit f8f0278

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,21 @@ var configurations = []Type{
896896
ErrorModes: []checkmode.Type{checkmode.Default},
897897
CheckFunction: checkfunctions.LibraryFolderNameGTMaxLength,
898898
},
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+
},
899914
{
900915
ProjectType: projecttype.Sketch,
901916
Category: "structure",

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,2 @@
1+
void setup() {}
2+
void loop() {}

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

Whitespace-only changes.

0 commit comments

Comments
 (0)