Skip to content

Commit 182dbba

Browse files
authored
Merge pull request #176 from per1234/url-min-length-rule
Add min length rule for library.properties url field
2 parents 98ab6a2 + f302419 commit 182dbba

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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, ""},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=UrlLTMinLength
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=
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

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy