From 731acc02fdf9d5658ddbdfe39a36e1b22a8cbdae Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 18:10:59 -0800 Subject: [PATCH 01/10] Remove stray debugging code --- result/result_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/result/result_test.go b/result/result_test.go index 735b673ea..bab43d5ac 100644 --- a/result/result_test.go +++ b/result/result_test.go @@ -55,7 +55,6 @@ func TestInitialize(t *testing.T) { require.Nil(t, err) var results Type results.Initialize() - fmt.Printf("paths: %s", configuration.TargetPaths()) assert.Equal(t, paths.NewPathList(workingDirectoryPath), results.Configuration.Paths) assert.Equal(t, projecttype.Sketch.String(), results.Configuration.ProjectType) assert.False(t, results.Configuration.Recursive) From 83fd617b0a7eeb31dbe40e91e2f4ee12528bef6f Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 18:49:28 -0800 Subject: [PATCH 02/10] Use check failure message template when the check fails Previously, the check level was being used rather than the check result, meaning the failure message wasn't shown when the check failed but the configuration resulted it being a warning. --- result/result.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/result/result.go b/result/result.go index 3bc592ed8..61ff2709b 100644 --- a/result/result.go +++ b/result/result.go @@ -102,7 +102,7 @@ func (results *Type) Record(checkedProject project.Type, checkConfiguration chec summaryText := fmt.Sprintf("Check %s result: %s\n", checkConfiguration.ID, checkResult) checkMessage := "" - if checkLevel == checklevel.Error { + if checkResult == checkresult.Fail { checkMessage = message(checkConfiguration.MessageTemplate, checkOutput) } else { // Checks may provide an explanation for their non-fail result. From a2e7d885e66547dbcca728a39a642da529b9024e Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 19:00:13 -0800 Subject: [PATCH 03/10] Fix scope of check for prohibited characters in library.properties name Previously, the check was failing for any pattern validation failure, causing it to overlap with other checks. --- check/checkfunctions/library.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 3941eedc5..4c439a7f5 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -185,7 +185,7 @@ func LibraryPropertiesNameFieldDisallowedCharacters() (result checkresult.Type, return checkresult.NotRun, "Field not present" } - if schema.PropertyPatternMismatch("name", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { + if schema.ValidationErrorMatch("^#/name$", "/patternObjects/allowedCharacters", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { return checkresult.Fail, name } From 12073aaa79dd47788c255aa3e7c44b70fd7b35fd Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 19:23:28 -0800 Subject: [PATCH 04/10] Fix schema test configuration Three identical tests were being run for the permissive compliance level when the intent was to run one for each level. --- .../libraryproperties/librarypropertiesschemas_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/library/libraryproperties/librarypropertiesschemas_test.go b/project/library/libraryproperties/librarypropertiesschemas_test.go index 75802b28c..227c0446c 100644 --- a/project/library/libraryproperties/librarypropertiesschemas_test.go +++ b/project/library/libraryproperties/librarypropertiesschemas_test.go @@ -368,8 +368,8 @@ func TestPropertiesUrlFormat(t *testing.T) { func TestPropertiesDependsPattern(t *testing.T) { testTables := []propertyValueTestTable{ {"Invalid characters", "-foo", compliancelevel.Permissive, assert.True}, - {"Invalid characters", "-foo", compliancelevel.Permissive, assert.True}, - {"Invalid characters", "-foo", compliancelevel.Permissive, assert.True}, + {"Invalid characters", "-foo", compliancelevel.Specification, assert.True}, + {"Invalid characters", "-foo", compliancelevel.Strict, assert.True}, } checkPropertyPatternMismatch("depends", testTables, t) From 839541ab7d1fbaa1269ac2ab5358475155eee206 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 19:24:29 -0800 Subject: [PATCH 05/10] Allow empty depends field The regular expression was only intended to check for prohibited characters, but it was inadvertently enforcing a minimum length of 1, which was also inherited by the name property schema (which already has a separate minimum length schema). There is currently no plans to add a minimum length requirement for the depends field, and if that is desired, it is better accomplished via the "minLength" schema. --- .../arduino-library-properties-definitions-schema.json | 2 +- .../libraryproperties/librarypropertiesschemas_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/etc/schemas/arduino-library-properties-definitions-schema.json b/etc/schemas/arduino-library-properties-definitions-schema.json index e15f7a949..aa6b6983a 100644 --- a/etc/schemas/arduino-library-properties-definitions-schema.json +++ b/etc/schemas/arduino-library-properties-definitions-schema.json @@ -490,7 +490,7 @@ "base": { "definitions": { "patternObject": { - "pattern": "^(([a-zA-Z][a-zA-Z0-9 _\\.\\-,]*)|([0-9][a-zA-Z0-9 _\\.\\-]*[a-zA-Z][a-zA-Z0-9 _\\.\\-,]*))$" + "pattern": "^(([a-zA-Z][a-zA-Z0-9 _\\.\\-,]*)|([0-9][a-zA-Z0-9 _\\.\\-]*[a-zA-Z][a-zA-Z0-9 _\\.\\-,]*))*$" } }, "object": { diff --git a/project/library/libraryproperties/librarypropertiesschemas_test.go b/project/library/libraryproperties/librarypropertiesschemas_test.go index 227c0446c..36d32df59 100644 --- a/project/library/libraryproperties/librarypropertiesschemas_test.go +++ b/project/library/libraryproperties/librarypropertiesschemas_test.go @@ -283,6 +283,11 @@ func TestPropertiesNamePattern(t *testing.T) { {"Disallowed character", "-foo", "/patternObjects/allowedCharacters", compliancelevel.Specification, assert.True}, {"Disallowed character", "-foo", "/patternObjects/allowedCharacters", compliancelevel.Strict, assert.True}, + // The "minLength" schema will enforce the minimum length, so this is not the responsibility of the pattern schema. + {"Empty", "", "/patternObjects/allowedCharacters", compliancelevel.Permissive, assert.False}, + {"Empty", "", "/patternObjects/allowedCharacters", compliancelevel.Specification, assert.False}, + {"Empty", "", "/patternObjects/allowedCharacters", compliancelevel.Strict, assert.False}, + {"Starts with arduino", "arduinofoo", "/patternObjects/notStartsWithArduino", compliancelevel.Permissive, assert.False}, {"Starts with arduino", "arduinofoo", "/patternObjects/notStartsWithArduino", compliancelevel.Specification, assert.True}, {"Starts with arduino", "arduinofoo", "/patternObjects/notStartsWithArduino", compliancelevel.Strict, assert.True}, @@ -370,6 +375,10 @@ func TestPropertiesDependsPattern(t *testing.T) { {"Invalid characters", "-foo", compliancelevel.Permissive, assert.True}, {"Invalid characters", "-foo", compliancelevel.Specification, assert.True}, {"Invalid characters", "-foo", compliancelevel.Strict, assert.True}, + + {"Empty", "", compliancelevel.Permissive, assert.False}, + {"Empty", "", compliancelevel.Specification, assert.False}, + {"Empty", "", compliancelevel.Strict, assert.False}, } checkPropertyPatternMismatch("depends", testTables, t) From 37e4d10f405847ff10b1516c928f23b6ba3b5e91 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 19:38:38 -0800 Subject: [PATCH 06/10] Only require semver-compliant library.properties version in strict mode Although the library specification says "Version should be semver compliant", it also says "1.2 is accepted", so relaxed semver is specification-compliant. --- .../arduino-library-properties-definitions-schema.json | 7 +++++-- .../libraryproperties/librarypropertiesschemas_test.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/etc/schemas/arduino-library-properties-definitions-schema.json b/etc/schemas/arduino-library-properties-definitions-schema.json index aa6b6983a..cf19dda85 100644 --- a/etc/schemas/arduino-library-properties-definitions-schema.json +++ b/etc/schemas/arduino-library-properties-definitions-schema.json @@ -145,7 +145,7 @@ "$ref": "#/definitions/propertiesObjects/version/base/object" }, { - "$ref": "general-definitions-schema.json#/definitions/patternObjects/semver" + "$ref": "general-definitions-schema.json#/definitions/patternObjects/relaxedSemver" } ] } @@ -154,7 +154,10 @@ "object": { "allOf": [ { - "$ref": "#/definitions/propertiesObjects/version/specification/object" + "$ref": "#/definitions/propertiesObjects/version/base/object" + }, + { + "$ref": "general-definitions-schema.json#/definitions/patternObjects/semver" } ] } diff --git a/project/library/libraryproperties/librarypropertiesschemas_test.go b/project/library/libraryproperties/librarypropertiesschemas_test.go index 36d32df59..440174555 100644 --- a/project/library/libraryproperties/librarypropertiesschemas_test.go +++ b/project/library/libraryproperties/librarypropertiesschemas_test.go @@ -319,11 +319,11 @@ func TestPropertiesVersionPattern(t *testing.T) { {"vX.Y.Z", "v1.0.0", compliancelevel.Strict, assert.True}, {"X.Y", "1.0", compliancelevel.Permissive, assert.False}, - {"X.Y", "1.0", compliancelevel.Specification, assert.True}, + {"X.Y", "1.0", compliancelevel.Specification, assert.False}, {"X.Y", "1.0", compliancelevel.Strict, assert.True}, {"X", "1", compliancelevel.Permissive, assert.False}, - {"X", "1", compliancelevel.Specification, assert.True}, + {"X", "1", compliancelevel.Specification, assert.False}, {"X", "1", compliancelevel.Strict, assert.True}, } From 331e48f38c6b2691b27e6ed2bb3c750238d5aaeb Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 20:11:56 -0800 Subject: [PATCH 07/10] Fix false positives from spellcheck checks For some reason, this specific sentence results in a non-nil diff of lenght > 0. The previous approach of checking if the diff was nil resulted in a false positive, which is avoided by basing the check on the length of the diff. --- check/checkfunctions/library.go | 2 +- check/checkfunctions/library_test.go | 2 ++ .../library.properties | 9 +++++++++ .../src/SpuriousMisspelledSentenceParagraphValue.h | 0 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/library.properties create mode 100644 check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/src/SpuriousMisspelledSentenceParagraphValue.h diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 4c439a7f5..9629c1f8a 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -1281,7 +1281,7 @@ func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult } replaced, diff := checkdata.MisspelledWordsReplacer().Replace(fieldValue) - if diff != nil { + if len(diff) > 0 { return checkresult.Fail, replaced } diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index 50cefd510..ddfe471f5 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -264,6 +264,7 @@ func TestLibraryPropertiesSentenceFieldSpellCheck(t *testing.T) { {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Not defined", "MissingFields", checkresult.NotRun, ""}, {"Misspelled word", "MisspelledSentenceParagraphValue", checkresult.Fail, "^grill broccoli now$"}, + {"Non-nil diff but no typos", "SpuriousMisspelledSentenceParagraphValue", checkresult.Pass, ""}, {"Correct spelling", "Recursive", checkresult.Pass, ""}, } @@ -275,6 +276,7 @@ func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) { {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Not defined", "MissingFields", checkresult.NotRun, ""}, {"Misspelled word", "MisspelledSentenceParagraphValue", checkresult.Fail, "^There is a zebra$"}, + {"Non-nil diff but no typos", "SpuriousMisspelledSentenceParagraphValue", checkresult.Pass, ""}, {"Correct spelling", "Recursive", checkresult.Pass, ""}, } diff --git a/check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/library.properties b/check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/library.properties new file mode 100644 index 000000000..5114bac7b --- /dev/null +++ b/check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/library.properties @@ -0,0 +1,9 @@ +name=SpuriousMisspelledSentenceParagraphValue +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +sentence=Minimal bit bang send serial 115200 or 38400 baud for 1 MHz or 230400 baud for 16 MHz clock. Perfect +paragraph=Minimal bit bang send serial 115200 or 38400 baud for 1 MHz or 230400 baud for 16 MHz clock. Perfect +category=Communication +url=http://example.com/ +architectures=avr diff --git a/check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/src/SpuriousMisspelledSentenceParagraphValue.h b/check/checkfunctions/testdata/libraries/SpuriousMisspelledSentenceParagraphValue/src/SpuriousMisspelledSentenceParagraphValue.h new file mode 100644 index 000000000..e69de29bb From c0d9f386e8f086bdfd376c3e18090826772c6d6e Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 21:51:38 -0800 Subject: [PATCH 08/10] Make depends in index check support spaces in library names --- check/checkfunctions/library.go | 10 ++++++---- check/checkfunctions/library_test.go | 1 + .../testdata/libraries/DependsEmpty/library.properties | 10 ++++++++++ .../testdata/libraries/DependsEmpty/src/DependsEmpty.h | 0 .../libraries/DependsIndexed/library.properties | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 check/checkfunctions/testdata/libraries/DependsEmpty/library.properties create mode 100644 check/checkfunctions/testdata/libraries/DependsEmpty/src/DependsEmpty.h diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 9629c1f8a..bc94ef7a7 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -841,12 +841,14 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output return checkresult.NotRun, "Field not present" } - dependencies, err := properties.SplitQuotedString(depends, "", false) - if err != nil { - panic(err) - } + dependencies := strings.Split(depends, ",") + dependenciesNotInIndex := []string{} for _, dependency := range dependencies { + dependency = strings.TrimSpace(dependency) + if dependency == "" { + continue + } logrus.Tracef("Checking if dependency %s is in index.", dependency) if !nameInLibraryManagerIndex(dependency) { dependenciesNotInIndex = append(dependenciesNotInIndex, dependency) diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index ddfe471f5..dbefeddcf 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -309,6 +309,7 @@ func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) { {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Dependency not in index", "DependsNotIndexed", checkresult.Fail, "^NotIndexed$"}, {"Dependency in index", "DependsIndexed", checkresult.Pass, ""}, + {"Depends field empty", "DependsEmpty", checkresult.Pass, ""}, {"No depends", "NoDepends", checkresult.NotRun, ""}, } diff --git a/check/checkfunctions/testdata/libraries/DependsEmpty/library.properties b/check/checkfunctions/testdata/libraries/DependsEmpty/library.properties new file mode 100644 index 000000000..1684f10e2 --- /dev/null +++ b/check/checkfunctions/testdata/libraries/DependsEmpty/library.properties @@ -0,0 +1,10 @@ +name=DependsEmpty +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Communication +url=http://example.com/ +architectures=avr +depends= diff --git a/check/checkfunctions/testdata/libraries/DependsEmpty/src/DependsEmpty.h b/check/checkfunctions/testdata/libraries/DependsEmpty/src/DependsEmpty.h new file mode 100644 index 000000000..e69de29bb diff --git a/check/checkfunctions/testdata/libraries/DependsIndexed/library.properties b/check/checkfunctions/testdata/libraries/DependsIndexed/library.properties index 1f2f33a07..356911342 100644 --- a/check/checkfunctions/testdata/libraries/DependsIndexed/library.properties +++ b/check/checkfunctions/testdata/libraries/DependsIndexed/library.properties @@ -7,4 +7,4 @@ paragraph=Supports HTTP1.1 and you can do GET and POST. category=Communication url=http://example.com/ architectures=avr -depends=Servo +depends=Servo, , Adafruit NeoPixel From 4da8e2932e71206287f873e93d233ba3f5bf158f Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 6 Dec 2020 22:20:36 -0800 Subject: [PATCH 09/10] Fix handling of multiple items by includes not in library check --- check/checkfunctions/library.go | 10 +++++----- .../libraries/MissingIncludes/library.properties | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index bc94ef7a7..1655f2789 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -33,7 +33,6 @@ import ( "github.com/arduino/arduino-check/project/sketch" "github.com/arduino/arduino-cli/arduino/libraries" "github.com/arduino/arduino-cli/arduino/utils" - "github.com/arduino/go-properties-orderedmap" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" @@ -925,12 +924,13 @@ func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, outp return checkresult.NotRun, "Field not present" } - includesList, err := properties.SplitQuotedString(includes, "", false) - if err != nil { - panic(err) - } + includesList := strings.Split(includes, ",") findInclude := func(include string) bool { + include = strings.TrimSpace(include) + if include == "" { + return true + } for _, header := range checkdata.SourceHeaders() { logrus.Tracef("Comparing include %s with header file %s", include, header) if include == header { diff --git a/check/checkfunctions/testdata/libraries/MissingIncludes/library.properties b/check/checkfunctions/testdata/libraries/MissingIncludes/library.properties index 6ee2bd744..77e670e5f 100644 --- a/check/checkfunctions/testdata/libraries/MissingIncludes/library.properties +++ b/check/checkfunctions/testdata/libraries/MissingIncludes/library.properties @@ -7,4 +7,4 @@ paragraph=Supports HTTP1.1 and you can do GET and POST. category=Communication url=http://example.com/ architectures=avr -includes=Nonexistent.h +includes=Nonexistent.h,MissingIncludes.h From be24c8e9e15e2d74572f49a76f48c519cd3134f0 Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 10 Dec 2020 02:40:35 -0800 Subject: [PATCH 10/10] Don't run checks for required library.properties fields on legacy libs The checks for library.properties field formatting are skipped if the field is not present, but that was not possible with the required fields, since that is exactly what is being checked. So the checks should only be skipped if there is no library.properties at all. --- check/checkfunctions/library.go | 57 ++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 1655f2789..1dbc0dce5 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -110,8 +110,9 @@ func RedundantLibraryProperties() (result checkresult.Type, output string) { // LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field. func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("name", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -339,8 +340,9 @@ func LibraryPropertiesNameFieldHeaderMismatch() (result checkresult.Type, output // LibraryPropertiesVersionFieldMissing checks for missing library.properties "version" field. func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("version", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -480,8 +482,9 @@ func LibraryPropertiesVersionFieldBehindTag() (result checkresult.Type, output s // LibraryPropertiesAuthorFieldMissing checks for missing library.properties "author" field. func LibraryPropertiesAuthorFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -509,8 +512,9 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output // LibraryPropertiesMaintainerFieldMissing checks for missing library.properties "maintainer" field. func LibraryPropertiesMaintainerFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -612,8 +616,9 @@ func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, ou // LibraryPropertiesSentenceFieldMissing checks for missing library.properties "sentence" field. func LibraryPropertiesSentenceFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("sentence", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -646,8 +651,9 @@ func LibraryPropertiesSentenceFieldSpellCheck() (result checkresult.Type, output // LibraryPropertiesParagraphFieldMissing checks for missing library.properties "paragraph" field. func LibraryPropertiesParagraphFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("paragraph", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -682,8 +688,9 @@ func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type, // LibraryPropertiesCategoryFieldMissing checks for missing library.properties "category" field. func LibraryPropertiesCategoryFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -730,8 +737,9 @@ func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, out // LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field. func LibraryPropertiesUrlFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("url", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -784,8 +792,9 @@ func LibraryPropertiesUrlFieldDeadLink() (result checkresult.Type, output string // LibraryPropertiesArchitecturesFieldMissing checks for missing library.properties "architectures" field. func LibraryPropertiesArchitecturesFieldMissing() (result checkresult.Type, output string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return checkresult.NotRun, "Couldn't load library.properties" + shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() + if !shouldRun { + return checkresult.NotRun, reason } if schema.RequiredPropertyMissing("architectures", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -1318,3 +1327,15 @@ func nameInLibraryManagerIndex(name string) bool { return false } + +func runRequiredLibraryPropertiesFieldCheck() (bool, string) { + if checkdata.LibraryPropertiesLoadError() != nil { + return false, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return false, "Library has legacy format" + } + + return true, "" +}