-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlint.go
More file actions
68 lines (56 loc) · 1.17 KB
/
Copy pathlint.go
File metadata and controls
68 lines (56 loc) · 1.17 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"fmt"
"os"
"slices"
"strings"
"github.com/gnolang/gno/tm2/pkg/commands"
)
func newLintCmd(cfg *cfg) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
Name: "lint",
ShortHelp: "lint the README table",
},
commands.NewEmptyConfig(),
func(_ context.Context, args []string) error {
return execLint(cfg)
},
)
return cmd
}
func execLint(cfg *cfg) error {
dirs, err := os.ReadDir(cfg.presentationsPath)
if err != nil {
panic(err)
}
var dates []string
for _, dir := range dirs {
// Skip special dirs
switch dir.Name() {
case "static", "templates":
continue
}
// Skip non-dirs
if !dir.IsDir() {
continue
}
dates = append(dates, dir.Name()[:10]) // get date out of dir name
}
slices.Sort(dates)
slices.Reverse(dates)
rawContents, err := os.ReadFile(cfg.readmePath)
if err != nil {
panic(err)
}
cts := string(rawContents)
for _, date := range dates {
date = strings.ReplaceAll(date, "-", ".")
if !strings.Contains(cts, date) {
panic("could not find some items in README table - did you run `make build`? (" + date + ")")
}
}
fmt.Println("All good!")
return nil
}