Skip to content

Commit

Permalink
Merge pull request #42 from arduino/per1234/paragraph-repeats-sentenc…
Browse files Browse the repository at this point in the history
…e-check

Add check for library.properties paragraph repeating sentence
  • Loading branch information
per1234 authored Nov 24, 2020
2 parents 2604f4a + 830f028 commit d7b7db7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
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 <[email protected]>, Pippo Pluto <[email protected]>
maintainer=Cristian Maglie <[email protected]>
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

0 comments on commit d7b7db7

Please sign in to comment.