Skip to content

Commit 9a2f7fe

Browse files
committed
Make sketch filename matching rule case-sensitive
The primary sketch file name must match the sketch folder exactly. Previously, the rule did not check for file name case matching on case-insensitive file systems.
1 parent 09f7530 commit 9a2f7fe

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Diff for: internal/rule/rulefunction/sketch.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,20 @@ import (
2828

2929
// SketchNameMismatch checks for mismatch between sketch folder name and primary file name.
3030
func SketchNameMismatch() (result ruleresult.Type, output string) {
31-
for extension := range globals.MainFileValidExtensions {
32-
validPrimarySketchFilePath := projectdata.ProjectPath().Join(projectdata.ProjectPath().Base() + extension)
33-
exist, err := validPrimarySketchFilePath.ExistCheck()
34-
if err != nil {
35-
panic(err)
36-
}
31+
primarySketchFilePrefix := projectdata.ProjectPath().Base()
3732

38-
if exist {
39-
return ruleresult.Pass, ""
33+
directoryListing, err := projectdata.ProjectPath().ReadDir()
34+
if err != nil {
35+
panic(err)
36+
}
37+
directoryListing.FilterOutDirs()
38+
39+
for _, filePath := range directoryListing {
40+
for extension := range globals.MainFileValidExtensions {
41+
if filePath.Base() == primarySketchFilePrefix+extension {
42+
// There was a case-sensitive match (paths package's Exist() is not always case-sensitive, so can't be used here).
43+
return ruleresult.Pass, ""
44+
}
4045
}
4146
}
4247

Diff for: internal/rule/rulefunction/sketch_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func checkSketchRuleFunction(ruleFunction Type, testTables []sketchRuleFunctionT
6464
func TestSketchNameMismatch(t *testing.T) {
6565
testTables := []sketchRuleFunctionTestTable{
6666
{"Valid", "Valid", ruleresult.Pass, ""},
67-
{"Mismatch", "NameMismatch", ruleresult.Fail, ""},
67+
{"Name Mismatch", "NameMismatch", ruleresult.Fail, ""},
68+
{"Case Mismatch", "CaseMismatch", ruleresult.Fail, ""},
6869
}
6970

7071
checkSketchRuleFunction(SketchNameMismatch, testTables, t)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}

0 commit comments

Comments
 (0)