Skip to content

Add check for Git submodules in library #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,21 @@ var configurations = []Type{
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesMisspelledOptionalField,
},
{
ProjectType: projecttype.Library,
Category: "structure",
Subcategory: "",
ID: "",
Brief: "submodule",
Description: "",
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.`,
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryHasSubmodule,
},
{
ProjectType: projecttype.Sketch,
Category: "structure",
Expand Down
15 changes: 15 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,21 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output
return checkresult.Pass, ""
}

// LibraryHasSubmodule checks whether the library contains a Git submodule.
func LibraryHasSubmodule() (result checkresult.Type, output string) {
dotGitmodulesPath := checkdata.ProjectPath().Join(".gitmodules")
hasDotGitmodules, err := dotGitmodulesPath.ExistCheck()
if err != nil {
panic(err)
}

if hasDotGitmodules && dotGitmodulesPath.IsNotDir() {
return checkresult.Fail, ""
}

return checkresult.Pass, ""
}

// spellCheckLibraryPropertiesFieldValue returns the value of the provided library.properties field with commonly misspelled words corrected.
func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
Expand Down
9 changes: 9 additions & 0 deletions check/checkfunctions/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,12 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {

checkCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)
}

func TestLibraryHasSubmodule(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Has submodule", "Submodule", checkresult.Fail, ""},
{"No submodule", "Recursive", checkresult.Pass, ""},
}

checkCheckFunction(LibraryHasSubmodule, testTables, t)
}
3 changes: 3 additions & 0 deletions check/checkfunctions/testdata/libraries/Submodule/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "foo"]
path = foo
url = https://example.com/foo.git
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=Submodule
version=1.0.0
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
maintainer=Cristian Maglie <[email protected]>
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
Empty file.