Skip to content

Commit a310859

Browse files
committed
Add check for library.properties paragraph repeating sentence
1 parent 336fc8f commit a310859

File tree

7 files changed

+63
-0
lines changed

7 files changed

+63
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ var configurations = []Type{
146146
ErrorModes: []checkmode.Type{checkmode.All},
147147
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldMissing,
148148
},
149+
{
150+
ProjectType: projecttype.Library,
151+
Category: "library.properties",
152+
Subcategory: "paragraph field",
153+
ID: "",
154+
Brief: "paragraph repeats sentence",
155+
Description: "",
156+
MessageTemplate: "The library.properties paragraph field repeats the sentence field. These are displayed together so redundancy is not needed.",
157+
DisableModes: nil,
158+
EnableModes: []checkmode.Type{checkmode.All},
159+
InfoModes: nil,
160+
WarningModes: []checkmode.Type{checkmode.All},
161+
ErrorModes: nil,
162+
CheckFunction: checkfunctions.LibraryPropertiesParagraphFieldRepeatsSentence,
163+
},
149164
{
150165
ProjectType: projecttype.Library,
151166
Category: "library.properties",

check/checkfunctions/library.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output str
110110
return checkresult.Pass, ""
111111
}
112112

113+
// LibraryPropertiesParagraphFieldRepeatsSentence checks whether the library.properties `paragraph` value repeats the `sentence` value.
114+
func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type, output string) {
115+
if checkdata.LibraryPropertiesLoadError() != nil {
116+
return checkresult.NotRun, ""
117+
}
118+
119+
sentence, hasSentence := checkdata.LibraryProperties().GetOk("sentence")
120+
paragraph, hasParagraph := checkdata.LibraryProperties().GetOk("paragraph")
121+
122+
if !hasSentence || !hasParagraph {
123+
return checkresult.NotRun, ""
124+
}
125+
126+
if strings.HasPrefix(paragraph, sentence) {
127+
return checkresult.Fail, ""
128+
}
129+
return checkresult.Pass, ""
130+
}
131+
113132
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114133
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115134
if checkdata.LibraryPropertiesLoadError() != nil {

check/checkfunctions/library_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ func TestLibraryPropertiesNameFieldNotInIndex(t *testing.T) {
8282
checkCheckFunction(LibraryPropertiesNameFieldNotInIndex, testTables, t)
8383
}
8484

85+
func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) {
86+
testTables := []checkFunctionTestTable{
87+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
88+
{"Repeat", "ParagraphRepeatsSentence", checkresult.Fail, ""},
89+
{"No repeat", "Recursive", checkresult.Pass, ""},
90+
}
91+
92+
checkCheckFunction(LibraryPropertiesParagraphFieldRepeatsSentence, testTables, t)
93+
}
94+
8595
func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
8696
testTables := []checkFunctionTestTable{
8797
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ParagraphRepeatsSentence
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian Maglie <c.maglie@example.com>
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

check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/src/ParagraphRepeatsSentence.h

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Recursive
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian Maglie <c.maglie@example.com>
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
10+
includes=Recursive.h

check/checkfunctions/testdata/libraries/Recursive/src/Recursive.h

Whitespace-only changes.

0 commit comments

Comments
 (0)