Skip to content

Commit

Permalink
lint all go modules in this repository
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Dec 21, 2023
1 parent 2262fee commit d29a620
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 20 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ generate:

.PHONY: docs
docs:
cd hack/docs-toc && go run .
cd hack/docs-prerender && go run .
cd hack/docs-toc && go mod tidy && go run .
cd hack/docs-prerender && go mod tidy && go run .

.PHONY: clean
clean:
Expand All @@ -46,6 +46,9 @@ test:
.PHONY: lint
lint:
golangci-lint run ./...
cd cmd/rudi && golangci-lint run ./... --config ../../.golangci.yml
cd hack/docs-toc && golangci-lint run ./... --config ../../.golangci.yml
cd hack/docs-prerender && golangci-lint run ./... --config ../../.golangci.yml

.PHONY: spellcheck
spellcheck:
Expand Down
6 changes: 1 addition & 5 deletions cmd/rudi/cmd/console/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"github.com/chzyer/readline"
)

func printPrompt() {
fmt.Print("⮞ ")
}

func helpCommand(ctx types.Context, opts *cmdtypes.Options) error {
content, err := docs.RenderFile("cmd-console.md", nil)
if err != nil {
Expand Down Expand Up @@ -125,7 +121,7 @@ func processInput(ctx context.Context, rudiCtx types.Context, opts *cmdtypes.Opt

// TODO: Setup a new context that can be cancelled with Ctrl-C to interrupt long running statements.

newCtx, evaluated, err := program.RunContext(rudiCtx.WithContext(ctx))
newCtx, evaluated, err := program.RunContext(rudiCtx.WithGoContext(ctx))
if err != nil {
return rudiCtx, false, err
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/rudi/cmd/script/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (

func Run(ctx context.Context, opts *types.Options, args []string) error {
// determine input script to evaluate
script := ""
scriptName := ""
var (
script string
scriptName string
)

if opts.ScriptFile != "" {
content, err := os.ReadFile(opts.ScriptFile)
Expand Down Expand Up @@ -71,7 +73,7 @@ func Run(ctx context.Context, opts *types.Options, args []string) error {
}

// evaluate the script
_, evaluated, err := program.RunContext(rudiCtx.WithContext(ctx))
_, evaluated, err := program.RunContext(rudiCtx.WithGoContext(ctx))
if err != nil {
return fmt.Errorf("failed to evaluate script: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rudi/docs/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ const (
// ChromaNameException Node = 0xd7d7af
// ChromaNameOther Node = 0xd7d7d7
// ChromaLiteral Node = 0xd7d7ff
// ChromaLiteralDate Node = 0xd7ff00
// ChromaLiteralDate Node = 0xd7ff00.
)
1 change: 1 addition & 0 deletions cmd/rudi/util/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ func SetupRudiContext(opts *types.Options, files []any) (rudi.Context, error) {

// No context set here, caller is expected to provide their own (the Rudi context is re-used
// in the console, but the Go context should not be, hence the separation).
//nolint:staticcheck
return rudi.NewContext(nil, document, vars, funcs, coalescer), nil
}
6 changes: 3 additions & 3 deletions hack/docs-prerender/ansidoc/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func Optimize(tokens []*ansi.StyledText) []*ansi.StyledText {
return output
}

func colorChange(old, new *ansi.Col) bool {
if new == nil && old == nil {
func colorChange(oldColor, newColor *ansi.Col) bool {
if newColor == nil && oldColor == nil {
return false
}

return new == nil || old == nil || old.Hex != new.Hex
return newColor == nil || oldColor == nil || oldColor.Hex != newColor.Hex
}
12 changes: 9 additions & 3 deletions hack/docs-prerender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,18 @@ func prerenderFile(source string, dest string) {
if err != nil {
log.Fatal(err)
}
defer f.Close()

gzipwriter := gzip.NewWriter(f)
defer gzipwriter.Close()

io.WriteString(gzipwriter, prerendered)
_, err = io.WriteString(gzipwriter, prerendered)

// do not use defers or as they would not run when log.Fatal is called
gzipwriter.Close()
f.Close()

if err != nil {
log.Fatal(err)
}
}

func prerender(markdown string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/eval/eval_tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func EvalTuple(ctx types.Context, tup ast.Tuple) (types.Context, any, error) {
// Function calls are the only place where we check if the Go context has been cancelled.
// This error should not be caught and swallowed by any other function, like `try` or `default`.
if err := ctx.Context().Err(); err != nil {
if err := ctx.GoContext().Err(); err != nil {
return ctx, nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/eval/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c Context) Coalesce() coalescing.Coalescer {
return c.coalescer
}

func (c Context) Context() context.Context {
func (c Context) GoContext() context.Context {
return c.ctx
}

Expand All @@ -91,7 +91,7 @@ func (c Context) GetFunction(name string) (Function, bool) {
return c.userFuncs.Get(name)
}

func (c Context) WithContext(ctx context.Context) Context {
func (c Context) WithGoContext(ctx context.Context) Context {
return Context{
ctx: ctx,
document: c.document,
Expand Down

0 comments on commit d29a620

Please sign in to comment.