run linter in github actions (#20)

* run linter in github actions

* try fixing go mod

* no install go

* again

* maybe this?

* separate install

* no v

* fix lint errors
This commit is contained in:
Facundo Olano 2024-02-29 19:34:33 -03:00 committed by GitHub
parent 3064beb3a1
commit adb17ad9d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 32 additions and 24 deletions

View file

@ -26,3 +26,12 @@ jobs:
- name: Test - name: Test
run: go test -v ./... run: go test -v ./...
- name: Vet
run: go vet -v ./...
- name: install staticcheck
run: go install "honnef.co/go/tools/cmd/staticcheck@latest"
- name: staticcheck
run: staticcheck ./...

View file

@ -59,6 +59,9 @@ func (cmd *Init) Run(ctx *kong.Context) error {
initfilesRoot := "initfiles" initfilesRoot := "initfiles"
return fs.WalkDir(initfiles, initfilesRoot, func(path string, entry fs.DirEntry, err error) error { return fs.WalkDir(initfiles, initfilesRoot, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if path == initfilesRoot { if path == initfilesRoot {
return nil return nil
} }

View file

@ -135,18 +135,17 @@ func setupWatcher(config *config.Config) (*fsnotify.Watcher, *EventBroker, error
// Add the layouts and all source directories to the given watcher // Add the layouts and all source directories to the given watcher
func addAll(watcher *fsnotify.Watcher, config *config.Config) error { func addAll(watcher *fsnotify.Watcher, config *config.Config) error {
err := watcher.Add(config.LayoutsDir) watcher.Add(config.LayoutsDir)
err = watcher.Add(config.DataDir) watcher.Add(config.DataDir)
err = watcher.Add(config.IncludesDir) watcher.Add(config.IncludesDir)
// fsnotify watches all files within a dir, but non recursively // fsnotify watches all files within a dir, but non recursively
// this walks through the src dir and adds watches for each found directory // this walks through the src dir and adds watches for each found directory
filepath.WalkDir(config.SrcDir, func(path string, entry fs.DirEntry, err error) error { return filepath.WalkDir(config.SrcDir, func(path string, entry fs.DirEntry, err error) error {
if entry.IsDir() { if entry.IsDir() {
watcher.Add(path) watcher.Add(path)
} }
return nil return nil
}) })
return err
} }
func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *EventBroker) { func rebuildSite(config *config.Config, watcher *fsnotify.Watcher, broker *EventBroker) {

6
go.mod
View file

@ -1,6 +1,6 @@
module github.com/facundoolano/jorge module github.com/facundoolano/jorge
go 1.22.0 go 1.22
require ( require (
github.com/alecthomas/chroma/v2 v2.5.0 github.com/alecthomas/chroma/v2 v2.5.0
@ -12,8 +12,8 @@ require (
github.com/tdewolff/minify/v2 v2.20.16 github.com/tdewolff/minify/v2 v2.20.16
github.com/yuin/goldmark v1.7.0 github.com/yuin/goldmark v1.7.0
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
golang.org/x/net v0.0.0-20201224014010-6772e930b67b golang.org/x/net v0.14.0
golang.org/x/text v0.3.3 golang.org/x/text v0.12.0
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
) )

11
go.sum
View file

@ -44,15 +44,12 @@ github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ= github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I= github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

View file

@ -8,7 +8,7 @@ import (
var cli struct { var cli struct {
Init commands.Init `cmd:"" help:"Initialize a new website project." aliases:"i"` Init commands.Init `cmd:"" help:"Initialize a new website project." aliases:"i"`
Build commands.Build `cmd:"" help:"Build a website project." aliases:"b"` Build commands.Build `cmd:"" help:"Build a website project." aliases:"b"`
Post commands.Post `cmd:"" help:"Initialize a new post template file." help:"title of the new post." aliases:"p"` Post commands.Post `cmd:"" help:"Initialize a new post template file." aliases:"p"`
Serve commands.Serve `cmd:"" help:"Run a local server for the website." aliases:"s"` Serve commands.Serve `cmd:"" help:"Run a local server for the website." aliases:"s"`
Version kong.VersionFlag `short:"v"` Version kong.VersionFlag `short:"v"`
} }

View file

@ -58,7 +58,6 @@ var smartifyTransforms = []struct {
} }
var smartifyReplacer *strings.Replacer var smartifyReplacer *strings.Replacer
var smartifyReplaceSpans = map[string]string{}
func init() { func init() {
smartifyReplacer = strings.NewReplacer( smartifyReplacer = strings.NewReplacer(

View file

@ -20,10 +20,11 @@ const string = "joe's garage";
</html>` </html>`
output, err := Smartify(".html", strings.NewReader(input)) output, err := Smartify(".html", strings.NewReader(input))
assertEqual(t, err, nil)
buf := new(strings.Builder) buf := new(strings.Builder)
_, err = io.Copy(buf, output) _, err = io.Copy(buf, output)
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, buf.String(), `<html><head> assertEqual(t, buf.String(), `<html><head>
<script type="text/javascript"> <script type="text/javascript">
const url = 'http://localhost:4001/_events/'; const url = 'http://localhost:4001/_events/';

View file

@ -69,7 +69,7 @@ title: about
// add a static file (no front matter) // add a static file (no front matter)
content = `go away!` content = `go away!`
file = newFile(config.SrcDir, "robots.txt", content) newFile(config.SrcDir, "robots.txt", content)
site, err := Load(*config) site, err := Load(*config)
@ -155,7 +155,7 @@ date: 2023-01-01
file = newFile(config.SrcDir, "about.html", content) file = newFile(config.SrcDir, "about.html", content)
defer os.Remove(file.Name()) defer os.Remove(file.Name())
site, err := Load(*config) site, _ := Load(*config)
output, err := site.render(site.templates[file.Name()]) output, err := site.render(site.templates[file.Name()])
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, string(output), `<ul> assertEqual(t, string(output), `<ul>
@ -208,7 +208,7 @@ tags: [software]
file = newFile(config.SrcDir, "about.html", content) file = newFile(config.SrcDir, "about.html", content)
defer os.Remove(file.Name()) defer os.Remove(file.Name())
site, err := Load(*config) site, _ := Load(*config)
output, err := site.render(site.templates[file.Name()]) output, err := site.render(site.templates[file.Name()])
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, string(output), `<h1>software</h1> assertEqual(t, string(output), `<h1>software</h1>
@ -259,7 +259,7 @@ title: "2. an oldie!"
file = newFile(config.SrcDir, "index.html", content) file = newFile(config.SrcDir, "index.html", content)
defer os.Remove(file.Name()) defer os.Remove(file.Name())
site, err := Load(*config) site, _ := Load(*config)
output, err := site.render(site.templates[file.Name()]) output, err := site.render(site.templates[file.Name()])
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, string(output), `<ul> assertEqual(t, string(output), `<ul>
@ -314,7 +314,7 @@ tags: [software]
file = newFile(config.SrcDir, "about.html", content) file = newFile(config.SrcDir, "about.html", content)
defer os.Remove(file.Name()) defer os.Remove(file.Name())
site, err := Load(*config) site, _ := Load(*config)
output, err := site.render(site.templates[file.Name()]) output, err := site.render(site.templates[file.Name()])
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, strings.TrimSpace(string(output)), `goodbye! - an overridden excerpt assertEqual(t, strings.TrimSpace(string(output)), `goodbye! - an overridden excerpt
@ -347,7 +347,7 @@ func TestRenderDataFile(t *testing.T) {
file = newFile(config.SrcDir, "projects.html", content) file = newFile(config.SrcDir, "projects.html", content)
defer os.Remove(file.Name()) defer os.Remove(file.Name())
site, err := Load(*config) site, _ := Load(*config)
output, err := site.render(site.templates[file.Name()]) output, err := site.render(site.templates[file.Name()])
assertEqual(t, err, nil) assertEqual(t, err, nil)
assertEqual(t, string(output), `<ul> assertEqual(t, string(output), `<ul>