Skip to content

Commit d7b7db7

Browse files
authored
Merge pull request #42 from arduino/per1234/paragraph-repeats-sentence-check
Add check for library.properties paragraph repeating sentence
2 parents 2604f4a + 830f028 commit d7b7db7

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,21 @@ var configurations = []Type{
491491
ErrorModes: nil,
492492
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldSpellCheck,
493493
},
494+
{
495+
ProjectType: projecttype.Library,
496+
Category: "library.properties",
497+
Subcategory: "paragraph field",
498+
ID: "",
499+
Brief: "paragraph repeats sentence",
500+
Description: "",
501+
MessageTemplate: "The library.properties paragraph field repeats the sentence field. These are displayed together so redundancy is not needed.",
502+
DisableModes: nil,
503+
EnableModes: []checkmode.Type{checkmode.All},
504+
InfoModes: nil,
505+
WarningModes: []checkmode.Type{checkmode.All},
506+
ErrorModes: nil,
507+
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldRepeatsSentence,
508+
},
494509
{
495510
ProjectType: projecttype.Library,
496511
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+19
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,25 @@ func LibraryPropertiesParagraphFieldSpellCheck() (result checkresult.Type, outpu
471471
return spellCheckLibraryPropertiesFieldValue("paragraph")
472472
}
473473

474+
// LibraryPropertiesParagraphFieldRepeatsSentence checks whether the library.properties `paragraph` value repeats the `sentence` value.
475+
func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type, output string) {
476+
if checkdata.LibraryPropertiesLoadError() != nil {
477+
return checkresult.NotRun, ""
478+
}
479+
480+
sentence, hasSentence := checkdata.LibraryProperties().GetOk("sentence")
481+
paragraph, hasParagraph := checkdata.LibraryProperties().GetOk("paragraph")
482+
483+
if !hasSentence || !hasParagraph {
484+
return checkresult.NotRun, ""
485+
}
486+
487+
if strings.HasPrefix(paragraph, sentence) {
488+
return checkresult.Fail, ""
489+
}
490+
return checkresult.Pass, ""
491+
}
492+
474493
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
475494
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
476495
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) {
115115
checkCheckFunction(LibraryPropertiesParagraphFieldSpellCheck, testTables, t)
116116
}
117117

118+
func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) {
119+
testTables := []checkFunctionTestTable{
120+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
121+
{"Repeat", "ParagraphRepeatsSentence", checkresult.Fail, ""},
122+
{"No repeat", "Recursive", checkresult.Pass, ""},
123+
}
124+
125+
checkCheckFunction(LibraryPropertiesParagraphFieldRepeatsSentence, testTables, t)
126+
}
127+
118128
func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
119129
testTables := []checkFunctionTestTable{
120130
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ParagraphRepeatsSentence
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=A library that makes coding a web server a breeze. 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/ParagraphRepeatsSentence/src/ParagraphRepeatsSentence.h

Whitespace-only changes.

0 commit comments

Comments
 (0)