Skip to content

Commit

Permalink
chore: upgrade golangci-lint (#1146)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
alecthomas and github-actions[bot] authored Mar 27, 2024
1 parent 11b2561 commit afb6a53
Show file tree
Hide file tree
Showing 24 changed files with 41 additions and 38 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ linters:
- tagalign
- nolintlint
- wrapcheck # We might want to re-enable this if we manually wrap all the existing errors with fmt.Errorf
- protogetter

linters-settings:
exhaustive:
Expand Down Expand Up @@ -135,3 +136,6 @@ issues:
- "^loopclosure:"
- 'shadow: declaration of "ctx" shadows declaration at'
- 'shadow: declaration of "ok" shadows declaration'
- "^dot-imports:"
- "fmt.Errorf can be replaced with errors.New"
- "fmt.Sprintf can be replaced with string concatenation"
2 changes: 1 addition & 1 deletion backend/controller/dal/dal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func TestControllerStateFromProto(t *testing.T) {
}

func normaliseEvents(events []Event) []Event {
for i := 0; i < len(events); i++ {
for i := range len(events) {
event := events[i]
re := reflect.Indirect(reflect.ValueOf(event))
f := re.FieldByName("Time")
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func validateValue(fieldType schema.Type, path path, value any, sch *schema.Sche
return fmt.Errorf("%s is not a slice", path)
}
elementType := fieldType.Element
for i := 0; i < rv.Len(); i++ {
for i := range rv.Len() {
elemPath := append(path, fmt.Sprintf("[%d]", i)) //nolint:gocritic
elem := rv.Index(i).Interface()
if err := validateValue(elementType, elemPath, elem, sch); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions backend/controller/scaling/localscaling/local_scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (l *LocalScaling) SetReplicas(ctx context.Context, replicas int, idleRunner
if replicasToAdd <= 0 {
replicasToRemove := -replicasToAdd

for i := 0; i < replicasToRemove; i++ {
for range replicasToRemove {
if len(idleRunners) == 0 {
return nil
}
Expand All @@ -74,7 +74,7 @@ func (l *LocalScaling) SetReplicas(ctx context.Context, replicas int, idleRunner
}

logger.Debugf("Adding %d replicas", replicasToAdd)
for i := 0; i < replicasToAdd; i++ {
for range replicasToAdd {
controllerEndpoint := l.controllerAddresses[len(l.runners)%len(l.controllerAddresses)]

bind := l.portAllocator.Next()
Expand Down
1 change: 0 additions & 1 deletion backend/controller/scheduledtask/scheduledtask.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func (s *Scheduler) run(ctx context.Context) {
if job.next.After(s.clock.Now()) {
continue
}
job := job
hashring := s.hashring.Load()

// If the job is singly homed, check that we are the active controller.
Expand Down
1 change: 0 additions & 1 deletion backend/controller/scheduledtask/scheduledtask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestCron(t *testing.T) {
clock := clock.NewMock()

for _, c := range controllers {
c := c
c.cron = NewForTesting(ctx, c.controller.Key, DALFunc(func(ctx context.Context, all bool) ([]dal.Controller, error) {
return slices.Map(controllers, func(c *controller) dal.Controller { return c.controller }), nil
}), clock)
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/sql/databasetesting/devel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func CreateForDevel(ctx context.Context, dsn string, recreate bool) (*pgxpool.Po
noDBDSN := config.Copy()
noDBDSN.Database = ""
var conn *pgx.Conn
for i := 0; i < 10; i++ {
for range 10 {
conn, err = pgx.ConnectConfig(ctx, noDBDSN)
if err == nil {
defer conn.Close(ctx)
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/intvalue.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package schema

import (
"fmt"
"strconv"

"google.golang.org/protobuf/proto"

Expand All @@ -28,7 +28,7 @@ func (i *IntValue) Position() Position { return i.Pos }
func (i *IntValue) schemaChildren() []Node { return nil }

func (i *IntValue) String() string {
return fmt.Sprintf("%d", i.Value)
return strconv.Itoa(i.Value)
}

func (i *IntValue) GetValue() any { return i.Value }
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/strcase/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func split(src string) (entries []string) {
}
// handle upper case -> lower case sequences, e.g.
// "PDFL", "oader" -> "PDF", "Loader"
for i := 0; i < len(runes)-1; i++ {
for i := range len(runes) - 1 {
if unicode.IsUpper(runes[i][0]) && unicode.IsLower(runes[i+1][0]) {
runes[i+1] = append([]rune{runes[i][len(runes[i])-1]}, runes[i+1]...)
runes[i] = runes[i][:len(runes[i])-1]
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/golangci-lint
10 changes: 5 additions & 5 deletions buildengine/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type deploymentArtefact struct {
}

type DeployClient interface {
GetArtefactDiffs(context.Context, *connect.Request[ftlv1.GetArtefactDiffsRequest]) (*connect.Response[ftlv1.GetArtefactDiffsResponse], error)
UploadArtefact(context.Context, *connect.Request[ftlv1.UploadArtefactRequest]) (*connect.Response[ftlv1.UploadArtefactResponse], error)
CreateDeployment(context.Context, *connect.Request[ftlv1.CreateDeploymentRequest]) (*connect.Response[ftlv1.CreateDeploymentResponse], error)
ReplaceDeploy(context.Context, *connect.Request[ftlv1.ReplaceDeployRequest]) (*connect.Response[ftlv1.ReplaceDeployResponse], error)
Status(context.Context, *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error)
GetArtefactDiffs(ctx context.Context, req *connect.Request[ftlv1.GetArtefactDiffsRequest]) (*connect.Response[ftlv1.GetArtefactDiffsResponse], error)
UploadArtefact(ctx context.Context, req *connect.Request[ftlv1.UploadArtefactRequest]) (*connect.Response[ftlv1.UploadArtefactResponse], error)
CreateDeployment(ctx context.Context, req *connect.Request[ftlv1.CreateDeploymentRequest]) (*connect.Response[ftlv1.CreateDeploymentResponse], error)
ReplaceDeploy(ctx context.Context, req *connect.Request[ftlv1.ReplaceDeployRequest]) (*connect.Response[ftlv1.ReplaceDeployResponse], error)
Status(ctx context.Context, req *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error)
}

// Deploy a module to the FTL controller with the given number of replicas. Optionally wait for the deployment to become ready.
Expand Down
2 changes: 1 addition & 1 deletion buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (e *Engine) buildAndDeploy(ctx context.Context, replicas int32, waitForDepl
})

// Process deployment queue.
for i := 0; i < len(projects); i++ {
for range len(projects) {
wg.Go(func() error {
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion buildengine/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Project interface {
sealed()

Config() ProjectConfig
CopyWithDependencies([]string) Project
CopyWithDependencies(deps []string) Project
TypeString() string
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/ftl/cmd_schema_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
"path/filepath"
"strconv"

"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/ollama"
Expand Down Expand Up @@ -142,7 +143,7 @@ func (s *schemaImportCmd) setup(ctx context.Context) error {
return err
}

port := fmt.Sprintf("%d", s.OllamaPort)
port := strconv.Itoa(s.OllamaPort)

if len(output) == 0 {
logger.Debugf("Creating docker container '%s' for ollama", ollamaContainerName)
Expand All @@ -157,7 +158,7 @@ func (s *schemaImportCmd) setup(ctx context.Context) error {
err = exec.Command(ctx, log.Debug, "./", "docker", "run",
"-d", // run detached so we can follow with other commands
"-v", ollamaVolume,
"-p", fmt.Sprintf("%s:11434", port),
"-p", port+":11434",
"--name", ollamaContainerName,
"ollama/ollama").RunBuffered(ctx)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions cmd/ftl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *serveCmd) Run(ctx context.Context) error {
}

controllerAddresses := make([]*url.URL, 0, s.Controllers)
for i := 0; i < s.Controllers; i++ {
for range s.Controllers {
controllerAddresses = append(controllerAddresses, bindAllocator.Next())
}

Expand All @@ -99,8 +99,7 @@ func (s *serveCmd) Run(ctx context.Context) error {
return err
}

for i := 0; i < s.Controllers; i++ {
i := i
for i := range s.Controllers {
config := controller.Config{
Bind: controllerAddresses[i],
Key: model.NewLocalControllerKey(i),
Expand Down Expand Up @@ -159,7 +158,7 @@ func runInBackground(logger *log.Logger) {
return
}

if err := os.WriteFile(pidFilePath, []byte(fmt.Sprintf("%d", cmd.Process.Pid)), 0600); err != nil {
if err := os.WriteFile(pidFilePath, []byte(strconv.Itoa(cmd.Process.Pid)), 0600); err != nil {
logger.Errorf(err, "failed to write pid file")
return
}
Expand Down Expand Up @@ -269,7 +268,7 @@ func (s *serveCmd) setupDB(ctx context.Context) (string, error) {
"--user", "postgres",
"--restart", "always",
"-e", "POSTGRES_PASSWORD=secret",
"-p", fmt.Sprintf("%s:5432", port),
"-p", port+":5432",
"--health-cmd=pg_isready",
"--health-interval=1s",
"--health-timeout=60s",
Expand Down
3 changes: 2 additions & 1 deletion go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
stdreflect "reflect"
"strconv"
"strings"

"github.com/TBD54566975/scaffolder"
Expand Down Expand Up @@ -257,7 +258,7 @@ var scaffoldFuncs = scaffolder.FuncMap{
case *schema.StringValue:
return fmt.Sprintf("%q", t.Value)
case *schema.IntValue:
return fmt.Sprintf("%d", t.Value)
return strconv.Itoa(t.Value)
}
panic(fmt.Sprintf("unsupported value %T", v))
},
Expand Down
6 changes: 3 additions & 3 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func visitStruct(pctx *parseContext, pos token.Pos, tnode types.Type) (*schema.R
Module: destModule,
Name: named.Obj().Name(),
}
for i := 0; i < named.TypeArgs().Len(); i++ {
for i := range named.TypeArgs().Len() {
arg := named.TypeArgs().At(i)
typeArg, err := visitType(pctx, pos, arg)
if err != nil {
Expand Down Expand Up @@ -554,7 +554,7 @@ func visitStruct(pctx *parseContext, pos token.Pos, tnode types.Type) (*schema.R
Module: pctx.module.Name,
Name: out.Name,
}
for i := 0; i < named.TypeParams().Len(); i++ {
for i := range named.TypeParams().Len() {
param := named.TypeParams().At(i)
out.TypeParameters = append(out.TypeParameters, &schema.TypeParameter{
Pos: goPosToSchemaPos(pos),
Expand Down Expand Up @@ -598,7 +598,7 @@ func visitStruct(pctx *parseContext, pos token.Pos, tnode types.Type) (*schema.R
if !ok {
return nil, errorf(pos, "expected struct but got %s", named)
}
for i := 0; i < s.NumFields(); i++ {
for i := range s.NumFields() {
f := s.Field(i)
ft, err := visitType(pctx, f.Pos(), f.Type())
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func TestExtractModuleSchemaTwo(t *testing.T) {
verb callsTwo(two.Payload<String>) two.Payload<String>
+calls two.two
verb returnsUser(Unit) two.UserResponse
verb two(two.Payload<String>) two.Payload<String>
}
`
Expand Down Expand Up @@ -192,7 +192,6 @@ func TestParseDirectives(t *testing.T) {
}},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := directiveParser.ParseString("", tt.input)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func encodeValue(v reflect.Value, w *bytes.Buffer) error {
func encodeStruct(v reflect.Value, w *bytes.Buffer) error {
w.WriteRune('{')
afterFirst := false
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
ft := v.Type().Field(i)
t := ft.Type
fv := v.Field(i)
Expand Down Expand Up @@ -146,7 +146,7 @@ func encodeBytes(v reflect.Value, w *bytes.Buffer) error {

func encodeSlice(v reflect.Value, w *bytes.Buffer) error {
w.WriteRune('[')
for i := 0; i < v.Len(); i++ {
for i := range v.Len() {
if i > 0 {
w.WriteRune(',')
}
Expand Down
3 changes: 2 additions & 1 deletion go-runtime/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"reflect"
"testing"

"github.com/alecthomas/assert/v2"

. "github.com/TBD54566975/ftl/go-runtime/encoding"
"github.com/TBD54566975/ftl/go-runtime/ftl"
"github.com/alecthomas/assert/v2"
)

func TestMarshal(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/ftl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func callerModule() string {
return "testing"
}
if !strings.HasPrefix(module, "ftl/") {
panic(fmt.Sprintf("must be called from an FTL module not %s", module))
panic("must be called from an FTL module not " + module)
}
return strings.Split(strings.Split(module, "/")[1], ".")[0]
}
2 changes: 1 addition & 1 deletion go-runtime/ftl/observability/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func TracerWithVerb(ctx context.Context) trace.Tracer {
}

func StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return TracerWithVerb(ctx).Start(ctx, name, opts...)
return TracerWithVerb(ctx).Start(ctx, name, opts...) //nolint:spancheck
}
2 changes: 1 addition & 1 deletion internal/exec/circularbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cb *CircularBuffer) Bytes() []byte {
var buf bytes.Buffer
start := cb.r.Move(-cb.size) // Correctly calculate the starting position

for i := 0; i < cb.size; i++ {
for range cb.size {
if str, ok := start.Value.(string); ok {
buf.WriteString(str)
} else {
Expand Down

0 comments on commit afb6a53

Please sign in to comment.