From 0d75f459516009ec208d85d77264545d792c8304 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Aug 2021 22:38:12 +0000 Subject: [PATCH 1/2] Bump github.com/arduino/go-paths-helper from 1.4.0 to 1.6.1 Bumps [github.com/arduino/go-paths-helper](https://github.com/arduino/go-paths-helper) from 1.4.0 to 1.6.1. - [Release notes](https://github.com/arduino/go-paths-helper/releases) - [Commits](https://github.com/arduino/go-paths-helper/compare/v1.4.0...v1.6.1) --- updated-dependencies: - dependency-name: github.com/arduino/go-paths-helper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docsgen/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docsgen/go.sum b/docsgen/go.sum index 05dbe4c4..e8d4e170 100644 --- a/docsgen/go.sum +++ b/docsgen/go.sum @@ -52,8 +52,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1: github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.4.0 h1:ilnseAdxmN1bFnLxxXHRtcdmt9jBf3O4jtYfWfqule4= -github.com/arduino/go-paths-helper v1.4.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU= +github.com/arduino/go-paths-helper v1.6.1 h1:lha+/BuuBsx0qTZ3gy6IO1kU23lObWdQ/UItkzVWQ+0= +github.com/arduino/go-paths-helper v1.6.1/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-properties-orderedmap v1.6.0 h1:gp2JoWRETtqwsZ+UHu/PBuYWYH2x2+d+uipDxS4WmvM= github.com/arduino/go-properties-orderedmap v1.6.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= diff --git a/go.mod b/go.mod index 79f8f6a8..3a8eaa44 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/OneOfOne/xxhash v1.2.8 // indirect github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect github.com/arduino/arduino-cli v0.0.0-20201210103408-bf7a3194bb63 - github.com/arduino/go-paths-helper v1.4.0 + github.com/arduino/go-paths-helper v1.6.1 github.com/arduino/go-properties-orderedmap v1.6.0 github.com/client9/misspell v0.3.4 github.com/daaku/go.zipexe v1.0.1 // indirect diff --git a/go.sum b/go.sum index 9af99e49..5a3d1193 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1: github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck= -github.com/arduino/go-paths-helper v1.4.0 h1:ilnseAdxmN1bFnLxxXHRtcdmt9jBf3O4jtYfWfqule4= -github.com/arduino/go-paths-helper v1.4.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU= +github.com/arduino/go-paths-helper v1.6.1 h1:lha+/BuuBsx0qTZ3gy6IO1kU23lObWdQ/UItkzVWQ+0= +github.com/arduino/go-paths-helper v1.6.1/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU= github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= github.com/arduino/go-properties-orderedmap v1.6.0 h1:gp2JoWRETtqwsZ+UHu/PBuYWYH2x2+d+uipDxS4WmvM= github.com/arduino/go-properties-orderedmap v1.6.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk= From 26b7c9defb169e1f8c82f31d49ab66e95fbfeaec Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 8 Aug 2021 17:21:18 -0700 Subject: [PATCH 2/2] Fix handling of missing lib examples folder The `rulefunction.MissingExamples` function was previously relying on the github.com/arduino/go-paths-helper IsDirCheck() method for two things - Does examples path exist? - Is examples path a folder? The code made the unreasonable assumption that IsDirCheck() would return `false, nil` if the path did not exist, and an error only if some unexpected failure occurred. That is not how IsDirCheck() is intended to work, as is clearly described in its documentation. A bug fix to align the method's behavior with that stated in its docs caused it to correctly return an error when the path did not exist, which caused an inappropriate panic from the `rulefunction.MissingExamples` function when checking an examples folder that did not exist. There is a dedicated method for checking path existence. By calling this method before `IsDirCheck()`, the code can achieve its intended behavior of handling missing examples folders gracefully, only panicing in the event of some unexpected failure that can't be handled without risking spurious linting results. --- internal/rule/rulefunction/library.go | 27 +++++++++++++------ internal/rule/rulefunction/library_test.go | 1 + .../testdata/libraries/ExamplesFile/examples | 0 .../libraries/ExamplesFile/library.properties | 9 +++++++ .../ExamplesFile/src/ExamplesFolder.h | 0 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 internal/rule/rulefunction/testdata/libraries/ExamplesFile/examples create mode 100644 internal/rule/rulefunction/testdata/libraries/ExamplesFile/library.properties create mode 100644 internal/rule/rulefunction/testdata/libraries/ExamplesFile/src/ExamplesFolder.h diff --git a/internal/rule/rulefunction/library.go b/internal/rule/rulefunction/library.go index 471d4294..f75b0d8e 100644 --- a/internal/rule/rulefunction/library.go +++ b/internal/rule/rulefunction/library.go @@ -1456,17 +1456,28 @@ func LibraryHasStraySketches() (result ruleresult.Type, output string) { func MissingExamples() (result ruleresult.Type, output string) { for _, examplesFolderName := range library.ExamplesFolderSupportedNames() { examplesPath := projectdata.ProjectPath().Join(examplesFolderName) - exists, err := examplesPath.IsDirCheck() + + exists, err := examplesPath.ExistCheck() if err != nil { panic(err) } - if exists { - directoryListing, _ := examplesPath.ReadDirRecursive() - directoryListing.FilterDirs() - for _, potentialExamplePath := range directoryListing { - if sketch.ContainsMainSketchFile(potentialExamplePath) { - return ruleresult.Pass, "" - } + if !exists { + continue + } + + isDir, err := examplesPath.IsDirCheck() + if err != nil { + panic(err) + } + if !isDir { + continue + } + + directoryListing, _ := examplesPath.ReadDirRecursive() + directoryListing.FilterDirs() + for _, potentialExamplePath := range directoryListing { + if sketch.ContainsMainSketchFile(potentialExamplePath) { + return ruleresult.Pass, "" } } } diff --git a/internal/rule/rulefunction/library_test.go b/internal/rule/rulefunction/library_test.go index 8cb59c2e..1178e557 100644 --- a/internal/rule/rulefunction/library_test.go +++ b/internal/rule/rulefunction/library_test.go @@ -952,6 +952,7 @@ func TestLibraryHasStraySketches(t *testing.T) { func TestMissingExamples(t *testing.T) { testTables := []libraryRuleFunctionTestTable{ + {"File name collision", "ExamplesFile", ruleresult.Fail, ""}, {"Has examples", "ExamplesFolder", ruleresult.Pass, ""}, {`Has examples (in "example" folder)`, "ExampleFolder", ruleresult.Pass, ""}, {"No examples", "NoExamples", ruleresult.Fail, ""}, diff --git a/internal/rule/rulefunction/testdata/libraries/ExamplesFile/examples b/internal/rule/rulefunction/testdata/libraries/ExamplesFile/examples new file mode 100644 index 00000000..e69de29b diff --git a/internal/rule/rulefunction/testdata/libraries/ExamplesFile/library.properties b/internal/rule/rulefunction/testdata/libraries/ExamplesFile/library.properties new file mode 100644 index 00000000..ebc274cc --- /dev/null +++ b/internal/rule/rulefunction/testdata/libraries/ExamplesFile/library.properties @@ -0,0 +1,9 @@ +name=ExamplesFolder +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Communication +url=http://example.com/ +architectures=avr diff --git a/internal/rule/rulefunction/testdata/libraries/ExamplesFile/src/ExamplesFolder.h b/internal/rule/rulefunction/testdata/libraries/ExamplesFile/src/ExamplesFolder.h new file mode 100644 index 00000000..e69de29b