Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8d7a6f7

Browse files
authoredNov 24, 2020
Merge pull request #38 from arduino/per1234/version-schema-checks
Add schema provided checks for library.properties version field
2 parents 336fc8f + 07a11ce commit 8d7a6f7

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
 

‎check/checkconfigurations/checkconfigurations.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,36 @@ 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: "version field",
153+
ID: "",
154+
Brief: "invalid",
155+
Description: `Must be compliant with "relaxed semver".`,
156+
MessageTemplate: "library.properties version value {{.}} is invalid. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
157+
DisableModes: nil,
158+
EnableModes: []checkmode.Type{checkmode.All},
159+
InfoModes: nil,
160+
WarningModes: nil,
161+
ErrorModes: []checkmode.Type{checkmode.All},
162+
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldNonRelaxedSemver,
163+
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "version field",
168+
ID: "",
169+
Brief: "non-semver",
170+
Description: "",
171+
MessageTemplate: "library.properties version value {{.}} is not compliant with the semver specification. See https://semver.org/",
172+
DisableModes: nil,
173+
EnableModes: []checkmode.Type{checkmode.All},
174+
InfoModes: nil,
175+
WarningModes: []checkmode.Type{checkmode.All},
176+
ErrorModes: nil,
177+
CheckFunction: checkfunctions.LibraryPropertiesVersionFieldNonSemver,
178+
},
149179
{
150180
ProjectType: projecttype.Library,
151181
Category: "library.properties",

‎check/checkfunctions/library.go

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

113+
// LibraryPropertiesVersionFieldNonRelaxedSemver checks whether the library.properties "version" value is "relaxed semver" compliant.
114+
func LibraryPropertiesVersionFieldNonRelaxedSemver() (result checkresult.Type, output string) {
115+
if checkdata.LibraryPropertiesLoadError() != nil {
116+
return checkresult.NotRun, ""
117+
}
118+
119+
version, ok := checkdata.LibraryProperties().GetOk("version")
120+
if !ok {
121+
return checkresult.NotRun, ""
122+
}
123+
124+
if schema.PropertyPatternMismatch("version", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
125+
return checkresult.Fail, version
126+
}
127+
128+
return checkresult.Pass, ""
129+
}
130+
131+
// LibraryPropertiesVersionFieldNonSemver checks whether the library.properties "version" value is semver compliant.
132+
func LibraryPropertiesVersionFieldNonSemver() (result checkresult.Type, output string) {
133+
if checkdata.LibraryPropertiesLoadError() != nil {
134+
return checkresult.NotRun, ""
135+
}
136+
137+
version, ok := checkdata.LibraryProperties().GetOk("version")
138+
if !ok {
139+
return checkresult.NotRun, ""
140+
}
141+
142+
if schema.PropertyPatternMismatch("version", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Strict], configuration.SchemasPath()) {
143+
return checkresult.Fail, version
144+
}
145+
146+
return checkresult.Pass, ""
147+
}
148+
113149
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
114150
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
115151
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.