From 830f028bb6d634534288e203de5d95b880726689 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 23 Nov 2020 19:58:43 -0800 Subject: [PATCH] Add check for library.properties paragraph repeating sentence --- .../checkconfigurations.go | 15 +++++++++++++++ check/checkfunctions/library.go | 19 +++++++++++++++++++ check/checkfunctions/library_test.go | 10 ++++++++++ .../library.properties | 9 +++++++++ .../src/ParagraphRepeatsSentence.h | 0 5 files changed, 53 insertions(+) create mode 100644 check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/library.properties create mode 100644 check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/src/ParagraphRepeatsSentence.h diff --git a/check/checkconfigurations/checkconfigurations.go b/check/checkconfigurations/checkconfigurations.go index 188078cd1..94c40f344 100644 --- a/check/checkconfigurations/checkconfigurations.go +++ b/check/checkconfigurations/checkconfigurations.go @@ -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", diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index d8ad78f9a..3fd010460 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -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 { diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index 6a473ee0f..d9549f980 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -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, ""}, diff --git a/check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/library.properties b/check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/library.properties new file mode 100644 index 000000000..d7d185348 --- /dev/null +++ b/check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/library.properties @@ -0,0 +1,9 @@ +name=ParagraphRepeatsSentence +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +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 diff --git a/check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/src/ParagraphRepeatsSentence.h b/check/checkfunctions/testdata/libraries/ParagraphRepeatsSentence/src/ParagraphRepeatsSentence.h new file mode 100644 index 000000000..e69de29bb