Skip to content

Commit 5a56b42

Browse files
committed
Add check for sketch name mismatch
1 parent 6ce9b3b commit 5a56b42

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,21 @@ var configurations = []Type{
12411241
ErrorModes: []checkmode.Type{checkmode.Default},
12421242
CheckFunction: checkfunctions.SketchDotJSONFormat,
12431243
},
1244+
{
1245+
ProjectType: projecttype.Sketch,
1246+
Category: "structure",
1247+
Subcategory: "",
1248+
ID: "",
1249+
Brief: "name mismatch",
1250+
Description: "",
1251+
MessageTemplate: "Sketch file/folder name mismatch. The primary sketch file name must match the folder: {{.}}. See: https://arduino.github.io/arduino-cli/latest/sketch-specification/#primary-sketch-file",
1252+
DisableModes: nil,
1253+
EnableModes: []checkmode.Type{checkmode.Default},
1254+
InfoModes: nil,
1255+
WarningModes: []checkmode.Type{checkmode.Permissive},
1256+
ErrorModes: []checkmode.Type{checkmode.Default},
1257+
CheckFunction: checkfunctions.SketchNameMismatch,
1258+
},
12441259
{
12451260
ProjectType: projecttype.Sketch,
12461261
Category: "code",

Diff for: check/checkfunctions/sketch.go

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/arduino/arduino-check/check/checkdata"
2424
"github.com/arduino/arduino-check/check/checkresult"
2525
"github.com/arduino/arduino-check/project/sketch"
26+
"github.com/arduino/arduino-cli/arduino/globals"
2627
)
2728

2829
// IncorrectSketchSrcFolderNameCase checks for incorrect case of src subfolder name in recursive format libraries.
@@ -128,3 +129,20 @@ func SketchDotJSONFormat() (result checkresult.Type, output string) {
128129

129130
return checkresult.Fail, checkdata.MetadataLoadError().Error()
130131
}
132+
133+
// SketchNameMismatch checks for mismatch between sketch folder name and primary file name.
134+
func SketchNameMismatch() (result checkresult.Type, output string) {
135+
for extension := range globals.MainFileValidExtensions {
136+
validPrimarySketchFilePath := checkdata.ProjectPath().Join(checkdata.ProjectPath().Base() + extension)
137+
exist, err := validPrimarySketchFilePath.ExistCheck()
138+
if err != nil {
139+
panic(err)
140+
}
141+
142+
if exist {
143+
return checkresult.Pass, ""
144+
}
145+
}
146+
147+
return checkresult.Fail, checkdata.ProjectPath().Base() + ".ino"
148+
}

Diff for: check/checkfunctions/sketch_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,12 @@ func TestSketchDotJSONFormat(t *testing.T) {
116116

117117
checkSketchCheckFunction(SketchDotJSONFormat, testTables, t)
118118
}
119+
120+
func TestSketchNameMismatch(t *testing.T) {
121+
testTables := []sketchCheckFunctionTestTable{
122+
{"Valid", "Valid", checkresult.Pass, ""},
123+
{"Mismatch", "NameMismatch", checkresult.Fail, ""},
124+
}
125+
126+
checkSketchCheckFunction(SketchNameMismatch, testTables, t)
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

0 commit comments

Comments
 (0)