Skip to content

Commit 0c3260d

Browse files
committed
Remove redundant validation code
This functionality is now provided by Arduino Lint.
1 parent fc202f4 commit 0c3260d

File tree

2 files changed

+0
-150
lines changed

2 files changed

+0
-150
lines changed

Diff for: libraries/metadata/metadata.go

-105
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ import (
4040
"context"
4141
"encoding/base64"
4242
"errors"
43-
"regexp"
44-
"strings"
4543

4644
"github.com/google/go-github/github"
4745
ini "github.com/vaughan0/go-ini"
@@ -64,109 +62,6 @@ type LibraryMetadata struct {
6462
Depends string
6563
}
6664

67-
const categoryUcategorized string = "Uncategorized"
68-
69-
var validCategories = []string{
70-
"Display",
71-
"Communication",
72-
"Signal Input/Output",
73-
"Sensors",
74-
"Device Control",
75-
"Timing",
76-
"Data Storage",
77-
"Data Processing",
78-
"Other",
79-
categoryUcategorized,
80-
}
81-
82-
// IsValidCategory checks if category is a valid category
83-
func IsValidCategory(category string) bool {
84-
for _, c := range validCategories {
85-
if category == c {
86-
return true
87-
}
88-
}
89-
return false
90-
}
91-
92-
// Validate checks LibraryMetadata for errors, returns an array of the errors found
93-
func (library *LibraryMetadata) Validate() []error {
94-
var errorsAccumulator []error
95-
96-
// Check lib name
97-
if !IsValidLibraryName(library.Name) {
98-
errorsAccumulator = append(errorsAccumulator, errors.New("Invalid 'name' field: "+library.Name))
99-
}
100-
101-
// Check author and maintainer existence
102-
if library.Author == "" {
103-
errorsAccumulator = append(errorsAccumulator, errors.New("'author' field must be defined"))
104-
}
105-
if library.Maintainer == "" {
106-
library.Maintainer = library.Author
107-
}
108-
109-
// Check sentence and paragraph and url existence
110-
if library.Sentence == "" || library.URL == "" {
111-
errorsAccumulator = append(errorsAccumulator, errors.New("'sentence' and 'url' fields must be defined"))
112-
}
113-
114-
newVersion, err := VersionToSemverCompliant(library.Version)
115-
if err != nil {
116-
errorsAccumulator = append(errorsAccumulator, err)
117-
}
118-
library.Version = newVersion
119-
120-
// Check if the category is valid and set to "Uncategorized" if not
121-
if !IsValidCategory(library.Category) {
122-
library.Category = categoryUcategorized
123-
}
124-
125-
// Check if 'depends' field is correctly written
126-
if !IsValidDependency(library.Depends) {
127-
errorsAccumulator = append(errorsAccumulator, errors.New("Invalid 'depends' field: "+library.Depends))
128-
}
129-
return errorsAccumulator
130-
}
131-
132-
// IsValidLibraryName checks if a string is a valid library name
133-
func IsValidLibraryName(name string) bool {
134-
if len(name) == 0 {
135-
return false
136-
}
137-
if name[0] == '-' || name[0] == '_' || name[0] == ' ' {
138-
return false
139-
}
140-
for _, char := range name {
141-
if !strings.Contains("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-. ", string(char)) {
142-
return false
143-
}
144-
}
145-
return true
146-
}
147-
148-
var re = regexp.MustCompile("^([a-zA-Z0-9](?:[a-zA-Z0-9._\\- ]*[a-zA-Z0-9])?) *(?: \\(([^()]*)\\))?$")
149-
150-
// IsValidDependency checks if the `depends` field of library.properties is correctly formatted
151-
func IsValidDependency(depends string) bool {
152-
// TODO: merge this method with db.ExtractDependenciesList
153-
depends = strings.TrimSpace(depends)
154-
if depends == "" {
155-
return true
156-
}
157-
for _, dep := range strings.Split(depends, ",") {
158-
dep = strings.TrimSpace(dep)
159-
if dep == "" {
160-
return false
161-
}
162-
matches := re.FindAllStringSubmatch(dep, -1)
163-
if matches == nil {
164-
return false
165-
}
166-
}
167-
return true
168-
}
169-
17065
// ParsePullRequest makes a LibraryMetadata by reading library.properties from a github.PullRequest
17166
func ParsePullRequest(gh *github.Client, pull *github.PullRequest) (*LibraryMetadata, error) {
17267
head := *pull.Head

Diff for: libraries/metadata/metadata_test.go

-45
This file was deleted.

0 commit comments

Comments
 (0)