Make sketch filename matching rule case-sensitive · arduino/arduino-lint@9a2f7fe (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -28,15 +28,20 @@ import (
28 28
29 29 // SketchNameMismatch checks for mismatch between sketch folder name and primary file name.
30 30 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()
37 32
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 + }
40 45 }
41 46 }
42 47
Original file line number Diff line number Diff line change
@@ -64,7 +64,8 @@ func checkSketchRuleFunction(ruleFunction Type, testTables []sketchRuleFunctionT
64 64 func TestSketchNameMismatch(t *testing.T) {
65 65 testTables := []sketchRuleFunctionTestTable{
66 66 {"Valid", "Valid", ruleresult.Pass, ""},
67 - {"Mismatch", "NameMismatch", ruleresult.Fail, ""},
67 + {"Name Mismatch", "NameMismatch", ruleresult.Fail, ""},
68 + {"Case Mismatch", "CaseMismatch", ruleresult.Fail, ""},
68 69 }
69 70
70 71 checkSketchRuleFunction(SketchNameMismatch, testTables, t)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +void setup() {}
2 +void loop() {}