Skip to content

Commit 5ac02e0

Browse files
committed
Add check for Git submodules in library
1 parent 0824294 commit 5ac02e0

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,21 @@ var configurations = []Type{
761761
ErrorModes: nil,
762762
CheckFunction: checkfunctions.LibraryPropertiesMisspelledOptionalField,
763763
},
764+
{
765+
ProjectType: projecttype.Library,
766+
Category: "structure",
767+
Subcategory: "",
768+
ID: "",
769+
Brief: "submodule",
770+
Description: "",
771+
MessageTemplate: `Git submodule detected. Library Manager installations and installations from GitHub's "Download ZIP" will only contain an empty folder in place of the submodule.`,
772+
DisableModes: nil,
773+
EnableModes: []checkmode.Type{checkmode.All},
774+
InfoModes: nil,
775+
WarningModes: []checkmode.Type{checkmode.All},
776+
ErrorModes: nil,
777+
CheckFunction: checkfunctions.LibraryHasSubmodule,
778+
},
764779
{
765780
ProjectType: projecttype.Sketch,
766781
Category: "structure",

Diff for: check/checkfunctions/library.go

+15
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,21 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output
785785
return checkresult.Pass, ""
786786
}
787787

788+
// LibraryHasSubmodule checks whether the library contains a Git submodule.
789+
func LibraryHasSubmodule() (result checkresult.Type, output string) {
790+
dotGitmodulesPath := checkdata.ProjectPath().Join(".gitmodules")
791+
hasDotGitmodules, err := dotGitmodulesPath.ExistCheck()
792+
if err != nil {
793+
panic(err)
794+
}
795+
796+
if hasDotGitmodules && dotGitmodulesPath.IsNotDir() {
797+
return checkresult.Fail, ""
798+
}
799+
800+
return checkresult.Pass, ""
801+
}
802+
788803
// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
789804
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
790805
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,12 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
170170

171171
checkCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)
172172
}
173+
174+
func TestLibraryHasSubmodule(t *testing.T) {
175+
testTables := []checkFunctionTestTable{
176+
{"Has submodule", "Submodule", checkresult.Fail, ""},
177+
{"No submodule", "Recursive", checkresult.Pass, ""},
178+
}
179+
180+
checkCheckFunction(LibraryHasSubmodule, testTables, t)
181+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "foo"]
2+
path = foo
3+
url = https://example.com/foo.git
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Submodule
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr

Diff for: check/checkfunctions/testdata/libraries/Submodule/src/Submodule.h

Whitespace-only changes.

0 commit comments

Comments
 (0)