Skip to content

Commit f302419

Browse files
committed
Add min length rule for library.properties url field
Previously, the permissive compliance mode only required that the library.properties url field was present. The field was allowed to be empty in this mode. Investigation revealed that the Arduino Library Manager indexer system, which Arduino Lint's permissive compliance mode is intended to match, requires the url field value to be at least one character long: https://github.com/arduino/libraries-repository-engine/blob/c395aaf14e7568f585a6a96350b584682a3c7feb/libraries/metadata/metadata.go#L110
1 parent 85638b8 commit f302419

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

etc/schemas/arduino-library-properties-definitions-schema.json

+3
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@
413413
"allOf": [
414414
{
415415
"type": "string"
416+
},
417+
{
418+
"minLength": 1
416419
}
417420
]
418421
}

internal/rule/ruleconfiguration/ruleconfiguration.go

+16
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,22 @@ var configurations = []Type{
889889
ErrorModes: []rulemode.Type{rulemode.Default},
890890
RuleFunction: rulefunction.LibraryPropertiesUrlFieldMissing,
891891
},
892+
{
893+
ProjectType: projecttype.Library,
894+
SuperprojectType: projecttype.All,
895+
Category: "library.properties",
896+
Subcategory: "url field",
897+
ID: "LP056",
898+
Brief: "url < min length",
899+
Description: "",
900+
MessageTemplate: "library.properties url value is less than minimum length.",
901+
DisableModes: nil,
902+
EnableModes: []rulemode.Type{rulemode.Default},
903+
InfoModes: nil,
904+
WarningModes: nil,
905+
ErrorModes: []rulemode.Type{rulemode.Default},
906+
RuleFunction: rulefunction.LibraryPropertiesUrlFieldLTMinLength,
907+
},
892908
{
893909
ProjectType: projecttype.Library,
894910
SuperprojectType: projecttype.All,

internal/rule/rulefunction/library.go

+17
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,23 @@ func LibraryPropertiesUrlFieldMissing() (result ruleresult.Type, output string)
944944
return ruleresult.Pass, ""
945945
}
946946

947+
// LibraryPropertiesUrlFieldLTMinLength checks if the library.properties "url" value is less than the minimum length.
948+
func LibraryPropertiesUrlFieldLTMinLength() (result ruleresult.Type, output string) {
949+
if projectdata.LibraryPropertiesLoadError() != nil {
950+
return ruleresult.NotRun, "Couldn't load library.properties"
951+
}
952+
953+
if !projectdata.LibraryProperties().ContainsKey("url") {
954+
return ruleresult.NotRun, "Field not present"
955+
}
956+
957+
if schema.PropertyLessThanMinLength("url", projectdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Permissive]) {
958+
return ruleresult.Fail, ""
959+
}
960+
961+
return ruleresult.Pass, ""
962+
}
963+
947964
// LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format.
948965
func LibraryPropertiesUrlFieldInvalid() (result ruleresult.Type, output string) {
949966
if projectdata.LibraryPropertiesLoadError() != nil {

internal/rule/rulefunction/library_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,17 @@ func TestLibraryPropertiesUrlFieldMissing(t *testing.T) {
714714
checkLibraryRuleFunction(LibraryPropertiesUrlFieldMissing, testTables, t)
715715
}
716716

717+
func TestLibraryPropertiesUrlFieldLTMinLength(t *testing.T) {
718+
testTables := []libraryRuleFunctionTestTable{
719+
{"Invalid", "InvalidLibraryProperties", ruleresult.NotRun, ""},
720+
{"Legacy", "Legacy", ruleresult.NotRun, ""},
721+
{"url field too short", "UrlLTMinLength", ruleresult.Fail, ""},
722+
{"Valid", "Recursive", ruleresult.Pass, ""},
723+
}
724+
725+
checkLibraryRuleFunction(LibraryPropertiesUrlFieldLTMinLength, testTables, t)
726+
}
727+
717728
func TestLibraryPropertiesUrlFieldInvalid(t *testing.T) {
718729
testTables := []libraryRuleFunctionTestTable{
719730
{"Invalid", "InvalidLibraryProperties", ruleresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=UrlLTMinLength
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=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=
9+
architectures=avr
10+
includes=UrlLTMinLength.h

internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/src/UrlLTMinLength.h

Whitespace-only changes.

internal/rule/schema/schemadata/bindata.go

+3
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,9 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
18321832
"allOf": [
18331833
{
18341834
"type": "string"
1835+
},
1836+
{
1837+
"minLength": 1
18351838
}
18361839
]
18371840
}

0 commit comments

Comments
 (0)