Skip to content

Add check for library.properties paragraph repeating sentence #42

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 24, 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 @@ -491,6 +491,21 @@ var configurations = []Type{
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldSpellCheck,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "paragraph field",
ID: "",
Brief: "paragraph repeats sentence",
Description: "",
MessageTemplate: "The library.properties paragraph field repeats the sentence field. These are displayed together so redundancy is not needed.",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.All},
ErrorModes: nil,
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldRepeatsSentence,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Expand Down
19 changes: 19 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,25 @@ func LibraryPropertiesParagraphFieldSpellCheck() (result checkresult.Type, outpu
return spellCheckLibraryPropertiesFieldValue("paragraph")
}

// LibraryPropertiesParagraphFieldRepeatsSentence checks whether the library.properties `paragraph` value repeats the `sentence` value.
func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

sentence, hasSentence := checkdata.LibraryProperties().GetOk("sentence")
paragraph, hasParagraph := checkdata.LibraryProperties().GetOk("paragraph")

if !hasSentence || !hasParagraph {
return checkresult.NotRun, ""
}

if strings.HasPrefix(paragraph, sentence) {
return checkresult.Fail, ""
}
return checkresult.Pass, ""
}

// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
Expand Down
10 changes: 10 additions & 0 deletions check/checkfunctions/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) {
checkCheckFunction(LibraryPropertiesParagraphFieldSpellCheck, testTables, t)
}

func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
{"Repeat", "ParagraphRepeatsSentence", checkresult.Fail, ""},
{"No repeat", "Recursive", checkresult.Pass, ""},
}

checkCheckFunction(LibraryPropertiesParagraphFieldRepeatsSentence, testTables, t)
}

func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=ParagraphRepeatsSentence
version=1.0.0
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
maintainer=Cristian Maglie <c.maglie@example.com>
sentence=A library that makes coding a web server a breeze.
paragraph=A library that makes coding a web server a breeze. Supports HTTP1.1 and you can do GET and POST.
category=Communication
url=http://example.com/
architectures=avr