Skip to content

Commit

Permalink
chore: bump golangci-lint (#1852)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas authored Jun 21, 2024
1 parent 3147067 commit f8ca3c6
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 152 deletions.
16 changes: 4 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ output:
linters:
enable-all: true
disable:
- maligned
- megacheck
- mnd # So annoying
- execinquery
- lll
- typecheck # `go build` catches this, and it doesn't currently work with Go 1.11 modules
- goimports # horrendously slow with go modules :(
- dupl # has never been actually useful
- gochecknoglobals
- gochecknoinits
- interfacer # author deprecated it because it provides bad suggestions
- funlen
- whitespace
- godox
Expand All @@ -25,37 +24,29 @@ linters:
- gomnd
- gocognit
- gocyclo
- scopelint
- godot
- nestif
- testpackage
- goerr113
- gci
- gofumpt
- exhaustivestruct
- nlreturn
- forbidigo
- cyclop
- paralleltest
- ifshort # so annoying
- golint
- tagliatelle
- gomoddirectives
- err113
- varnamelen
- ireturn
- containedctx
- nilnil
- contextcheck
- nonamedreturns
- exhaustruct
- nosnakecase
- nosprintfhostport
- nilerr
- goconst
- prealloc
- deadcode # doesn't support generics
- varcheck # doesn't support generics
- structcheck # doesn't support generics
- rowserrcheck # doesn't support generics
- wastedassign # doesn't support generics
- goprintffuncname
Expand Down Expand Up @@ -143,3 +134,4 @@ issues:
- "^dot-imports:"
- "fmt.Errorf can be replaced with errors.New"
- "fmt.Sprintf can be replaced with string concatenation"
- "strings.Title has been deprecated"
42 changes: 0 additions & 42 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"math/rand"
"net/http"
"net/url"
"reflect"
"runtime"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -1625,46 +1623,6 @@ func (s *Service) getActiveSchema(ctx context.Context) (*schema.Schema, error) {
})
}

func runWithRetries(ctx context.Context, success, failure time.Duration, fn func(ctx context.Context) error) {
name := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
name = name[strings.LastIndex(name, ".")+1:]
name = strings.TrimSuffix(name, "-fm")

ctx = log.ContextWithLogger(ctx, log.FromContext(ctx).Scope(name))
failureRetry := backoff.Backoff{
Min: failure,
Max: failure * 2,
Jitter: true,
Factor: 2,
}
failed := false
logger := log.FromContext(ctx)
for {
err := fn(ctx)
if err != nil {
next := failureRetry.Duration()
logger.Errorf(err, "Failed, retrying in %s", next)
select {
case <-time.After(next):
case <-ctx.Done():
return
}
} else {
if failed {
logger.Debugf("Recovered")
failed = false
}
failureRetry.Reset()
logger.Tracef("Success, next run in %s", success)
select {
case <-time.After(success):
case <-ctx.Done():
return
}
}
}
}

func extractIngressRoutingEntries(req *ftlv1.CreateDeploymentRequest) []dal.IngressRoutingEntry {
var ingressRoutes []dal.IngressRoutingEntry
for _, decl := range req.Schema.Decls {
Expand Down
11 changes: 0 additions & 11 deletions backend/schema/normalise.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,3 @@ func Normalise[T Node](n T) T {
})
return ni //nolint:forcetypeassert
}

func normaliseSlice[T Node](in []T) []T {
if in == nil {
return nil
}
var out []T
for _, n := range in {
out = append(out, Normalise(n))
}
return out
}
8 changes: 6 additions & 2 deletions backend/schema/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,12 @@ func validateVerbMetadata(scopes Scopes, module *Module, n *Verb) (merr []error)
func validateIngressRequestOrResponse(scopes Scopes, module *Module, n *Verb, reqOrResp string, r Type) (fieldType Type, body Symbol, merr []error) {
rref, _ := r.(*Ref)
resp, sym := ResolveTypeAs[*Data](scopes, r)
m, _ := sym.Module.Get()
if sym == nil || m == nil || m.Name != "builtin" || resp.Name != "Http"+strings.Title(reqOrResp) {
invalid := sym == nil
if !invalid {
m, _ := sym.Module.Get()
invalid = m == nil || m.Name != "builtin" || resp.Name != "Http"+strings.Title(reqOrResp)
}
if invalid {
merr = append(merr, errorf(r, "ingress verb %s: %s type %s must be builtin.HttpRequest", n.Name, reqOrResp, r))
return
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/golangci-lint
10 changes: 4 additions & 6 deletions cmd/ftl-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ func main() {
configProviders := []cf.Provider[cf.Configuration]{cf.NewDBConfigProvider(dal)}
configResolver := cf.NewDBConfigResolver(dal)
cm, err := cf.New[cf.Configuration](ctx, configResolver, configProviders)
if err != nil {
kctx.Fatalf(err.Error())
}
kctx.FatalIfErrorf(err)

ctx = cf.ContextWithConfig(ctx, cm)

// The FTL controller currently only supports AWS Secrets Manager as a secrets provider.
awsConfig, err := config.LoadDefaultConfig(ctx)
kctx.FatalIfErrorf(err)
asmClient := secretsmanager.NewFromConfig(awsConfig)
secretsResolver := cf.ASM{Client: *asmClient}
secretsProviders := []cf.Provider[cf.Secrets]{cf.ASM{Client: *asmClient}}
sm, err := cf.New[cf.Secrets](ctx, secretsResolver, secretsProviders)
if err != nil {
kctx.Fatalf(err.Error())
}
kctx.FatalIfErrorf(err)
ctx = cf.ContextWithSecrets(ctx, sm)

err = controller.Start(ctx, cli.ControllerConfig, scaling.NewK8sScaling())
Expand Down
39 changes: 0 additions & 39 deletions cmd/ftl/cmd_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package main

import (
"context"
"os"
"path/filepath"

ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
"github.com/TBD54566975/ftl/internal/download"
"github.com/TBD54566975/ftl/internal/model"
"github.com/TBD54566975/ftl/internal/sha256"
)

type downloadCmd struct {
Expand All @@ -20,38 +16,3 @@ type downloadCmd struct {
func (d *downloadCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceClient) error {
return download.Artefacts(ctx, client, d.Deployment, d.Dest)
}

func (d *downloadCmd) getLocalArtefacts() ([]*ftlv1.DeploymentArtefact, error) {
haveArtefacts := []*ftlv1.DeploymentArtefact{}
dest, err := filepath.Abs(d.Dest)
if err != nil {
return nil, err
}
err = filepath.Walk(dest, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
sum, err := sha256.SumFile(path)
if err != nil {
return err
}

relPath, err := filepath.Rel(dest, path)
if err != nil {
return err
}
haveArtefacts = append(haveArtefacts, &ftlv1.DeploymentArtefact{
Path: relPath,
Digest: sum.String(),
Executable: info.Mode()&0111 != 0,
})
return nil
})
if err != nil {
return nil, err
}
return haveArtefacts, nil
}
17 changes: 8 additions & 9 deletions cmd/ftl/cmd_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package main
import (
"context"
"fmt"
"os"
"sort"
"strings"

"connectrpc.com/connect"
"github.com/golang/protobuf/jsonpb"
"golang.org/x/exp/maps"
jsonpb "google.golang.org/protobuf/encoding/protojson"

ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
Expand All @@ -26,13 +25,13 @@ func (s *psCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceCl
return err
}
if s.JSON {
marshaller := jsonpb.Marshaler{Indent: " "}
marshaller := jsonpb.MarshalOptions{Indent: " "}
for _, process := range status.Msg.Processes {
err = marshaller.Marshal(os.Stdout, process)
data, err := marshaller.Marshal(process)
if err != nil {
return err
}
fmt.Println()
fmt.Printf("%s\n", data)
}
return nil
}
Expand Down Expand Up @@ -65,19 +64,19 @@ func (s *psCmd) Run(ctx context.Context, client ftlv1connect.ControllerServiceCl
key = fmt.Sprintf("%s-%s", key, strings.ToLower(runner.Key[len(runner.Key)-5:]))
runnerKey = runner.Key
endpoint = runner.Endpoint
labels, err := (&jsonpb.Marshaler{}).MarshalToString(runner.Labels)
labels, err := jsonpb.Marshal(runner.Labels)
if err != nil {
return err
}
runnerLabels = labels
runnerLabels = string(labels)
}
args := []any{key, fmt.Sprintf("%d/%d", i+1, first.MinReplicas), "live", runnerKey, endpoint}
if s.Verbose > 1 {
labels, err := (&jsonpb.Marshaler{}).MarshalToString(first.Labels)
labels, err := jsonpb.Marshal(first.Labels)
if err != nil {
return err
}
args = append(args, labels, runnerLabels)
args = append(args, string(labels), runnerLabels)
}
fmt.Printf(format, args...)
}
Expand Down
14 changes: 9 additions & 5 deletions cmd/ftl/cmd_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"context"
"os"
"fmt"

"connectrpc.com/connect"
"github.com/golang/protobuf/jsonpb"
jsonpb "google.golang.org/protobuf/encoding/protojson"

ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
Expand All @@ -30,7 +30,11 @@ func (s *statusCmd) Run(ctx context.Context, client ftlv1connect.ControllerServi
deployment.Schema = nil
}
}
return (&jsonpb.Marshaler{
Indent: " ",
}).Marshal(os.Stdout, status.Msg)
marshaler := jsonpb.MarshalOptions{Indent: " "}
data, err := marshaler.Marshal(status.Msg)
if err != nil {
return fmt.Errorf("failed to marshal status: %w", err)
}
fmt.Printf("%s\n", data)
return nil
}
7 changes: 0 additions & 7 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,10 +1615,3 @@ func isIotaEnum(node ast.Node) bool {
return false
}
}

func exportedName(name string) string {
if name == "" {
return ""
}
return string(unicode.ToUpper(rune(name[0]))) + name[1:]
}
4 changes: 2 additions & 2 deletions go-runtime/schema/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ func GetTypeForNode(node ast.Node, info *types.Info) types.Type {
if obj := info.ObjectOf(n); obj != nil {
return obj.Type()
}
case ast.Expr:
return info.TypeOf(n)
case *ast.AssignStmt:
if len(n.Lhs) > 0 {
return info.TypeOf(n.Lhs[0])
Expand Down Expand Up @@ -296,6 +294,8 @@ func GetTypeForNode(node ast.Node, info *types.Info) types.Type {
return t
}
}
case ast.Expr:
return info.TypeOf(n)
}
return nil
}
Expand Down
7 changes: 0 additions & 7 deletions go-runtime/schema/common/fact.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ func MarkSchemaDecl(pass *analysis.Pass, obj types.Object, decl schema.Decl) {
pass.ExportObjectFact(obj, fact)
}

// markSchemaDeclIncluded marks the given decl as included in the schema.
func markSchemaDeclIncluded(pass *analysis.Pass, obj types.Object) {
for _, f := range GetFactsForObject[*ExtractedDecl](pass, obj) {
f.ShouldInclude = true
}
}

// MarkFailedExtraction marks the given object as having failed extraction.
func MarkFailedExtraction(pass *analysis.Pass, obj types.Object) {
fact := newFact(pass)
Expand Down
7 changes: 4 additions & 3 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/docker/go-connections/nat"

Expand Down Expand Up @@ -41,15 +42,15 @@ func DoesExist(ctx context.Context, name string) (bool, error) {
}

// Pull pulls the given image.
func Pull(ctx context.Context, image string) error {
func Pull(ctx context.Context, imageName string) error {
cli, err := dockerClient.Get(ctx)
if err != nil {
return err
}

reader, err := cli.ImagePull(ctx, image, types.ImagePullOptions{})
reader, err := cli.ImagePull(ctx, imageName, image.PullOptions{})
if err != nil {
return fmt.Errorf("failed to pull %s image: %w", image, err)
return fmt.Errorf("failed to pull %s image: %w", imageName, err)
}
defer reader.Close()

Expand Down
1 change: 0 additions & 1 deletion internal/cron/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func Parse(text string) (Pattern, error) {

// A helper struct to build up a cron pattern with a short syntax.
type shortState struct {
position int
seenNonZero bool
components []Component
err error
Expand Down
Loading

0 comments on commit f8ca3c6

Please sign in to comment.