-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.go
47 lines (40 loc) · 966 Bytes
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"path/filepath"
)
var invalidFileCount = 0
func ValidateSingleFile(fullFilepath string) error {
recipeFile, err := ParseFile(fullFilepath)
if err != nil {
fmt.Printf("%s (%s)\n", fullFilepath, err.Error())
invalidFileCount++
return nil
}
_, err = ParseFrontMatter(recipeFile.FrontMatter)
if err != nil {
fmt.Printf("%s (%s)\n", fullFilepath, err.Error())
invalidFileCount++
return nil
}
return nil
}
func ValidateFile() filepath.WalkFunc {
return func(fullFilepath string, info os.FileInfo, err error) error {
shouldSkip := ShouldSkipFile(info, err)
if shouldSkip {
return nil
}
return ValidateSingleFile(fullFilepath)
}
}
// Scan the list of files in `prefix` and output all the ones that don't
// conform to the formatting.
func ValidateFiles() {
err := filepath.Walk(prefix, ValidateFile())
if err != nil {
fmt.Println(err)
}
fmt.Printf("# invalid files: %d\n", invalidFileCount)
}