Skip to content

Commit f0a7bf4

Browse files
committed
Added extra linters
1 parent f670c0a commit f0a7bf4

17 files changed

Lines changed: 239 additions & 57 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ proto:
2323

2424
.PHONY: lint
2525
lint:
26+
@go-cleanarch
2627
@./scripts/lint.sh trainer
2728
@./scripts/lint.sh trainings
2829
@./scripts/lint.sh users

cloudbuild.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
steps:
2+
- id: common-lint
3+
name: golang
4+
entrypoint: ./scripts/lint.sh
5+
args: ['common', '-install']
26
- id: trainer-lint
37
name: golang
48
entrypoint: ./scripts/lint.sh
5-
args: [trainer]
9+
args: ['trainer', '-install']
610
- id: trainings-lint
711
name: golang
812
entrypoint: ./scripts/lint.sh
9-
args: [trainings]
13+
args: ['trainings', '-install']
1014
- id: users-lint
1115
name: golang
1216
entrypoint: ./scripts/lint.sh
13-
args: [users]
17+
args: ['users', '-install']
1418

1519
- id: trainer-docker
1620
name: gcr.io/cloud-builders/docker
@@ -35,6 +39,11 @@ steps:
3539
- 'PROJECT_ID=$PROJECT_ID'
3640
waitFor: [trainer-docker, trainings-docker, users-docker]
3741

42+
- id: common-tests
43+
name: golang
44+
entrypoint: ./scripts/test.sh
45+
args: ["common", ".test.ci.env"]
46+
waitFor: [docker-compose]
3847
- id: trainer-tests
3948
name: golang
4049
entrypoint: ./scripts/test.sh
@@ -96,7 +105,7 @@ steps:
96105
dir: web
97106
waitFor: ['-']
98107
- id: openapi-js
99-
name: openapitools/openapi-generator-cli:v4.3.0
108+
name: openapitools/openapi-generator-cli:v4.3.0
100109
entrypoint: "./scripts/openapi-js.sh"
101110
waitFor: ['-']
102111
- id: web-build

internal/common/.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- deadcode
5+
- errcheck
6+
- gosimple
7+
- govet
8+
- ineffassign
9+
- staticcheck
10+
- structcheck
11+
- typecheck
12+
- unused
13+
- varcheck
14+
- asciicheck
15+
- bodyclose
16+
- dogsled
17+
- exhaustive
18+
- exportloopref
19+
- gocognit
20+
- goconst
21+
- gofmt
22+
- goheader
23+
- goimports
24+
- gosec
25+
- misspell
26+
- nakedret
27+
- nestif
28+
- noctx
29+
- rowserrcheck
30+
- sqlclosecheck
31+
- unconvert
32+
- unparam
33+
- whitespace
34+
35+
issues:
36+
exclude:
37+
- "composite literal uses unkeyed fields"
38+
exclude-rules:
39+
- path: _test\.go
40+
linters:
41+
- gosec
42+
- noctx
43+
- unparam
44+
- bodyclose
45+
- path: fixtures.go
46+
linters:
47+
- gosec

internal/trainer/.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- deadcode
5+
- errcheck
6+
- gosimple
7+
- govet
8+
- ineffassign
9+
- staticcheck
10+
- structcheck
11+
- typecheck
12+
- unused
13+
- varcheck
14+
- asciicheck
15+
- bodyclose
16+
- dogsled
17+
- exhaustive
18+
- exportloopref
19+
- gocognit
20+
- goconst
21+
- gofmt
22+
- goheader
23+
- goimports
24+
- gosec
25+
- misspell
26+
- nakedret
27+
- nestif
28+
- noctx
29+
- rowserrcheck
30+
- sqlclosecheck
31+
- unconvert
32+
- unparam
33+
- whitespace
34+
35+
issues:
36+
exclude:
37+
- "composite literal uses unkeyed fields"
38+
exclude-rules:
39+
- path: _test\.go
40+
linters:
41+
- gosec
42+
- noctx
43+
- unparam
44+
- bodyclose
45+
- path: fixtures.go
46+
linters:
47+
- gosec

internal/trainer/adapters/dates_firestore_repository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app/query"
99
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour"
10+
"github.com/pkg/errors"
1011

1112
"cloud.google.com/go/firestore"
1213
"google.golang.org/api/iterator"
@@ -56,7 +57,7 @@ func (d DatesFirestoreRepository) AvailableHours(ctx context.Context, from time.
5657

5758
for {
5859
doc, err := iter.Next()
59-
if err == iterator.Done {
60+
if errors.Is(err, iterator.Done) {
6061
break
6162
}
6263
if err != nil {

internal/trainer/adapters/hour_repository_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func testUpdateHour_rollback(t *testing.T, repository hour.Repository) {
216216
require.NoError(t, h.MakeAvailable())
217217
return h, nil
218218
})
219+
require.Error(t, err)
219220

220221
err = repository.UpdateHour(ctx, hourTime, func(h *hour.Hour) (*hour.Hour, error) {
221222
assert.True(t, h.IsAvailable())

internal/trainer/fixtures.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func loadFixtures(app app.Application) {
2525
return
2626
}
2727

28-
logrus.WithField("after", time.Now().Sub(start)).Debug("Trainer service is available")
28+
logrus.WithField("after", time.Since(start)).Debug("Trainer service is available")
2929

3030
if !canLoadFixtures(app, ctx) {
3131
logrus.Debug("Trainer fixtures are already loaded")
@@ -42,7 +42,7 @@ func loadFixtures(app app.Application) {
4242
time.Sleep(10 * time.Second)
4343
}
4444

45-
logrus.WithField("after", time.Now().Sub(start)).Debug("Trainer fixtures loaded")
45+
logrus.WithField("after", time.Since(start)).Debug("Trainer fixtures loaded")
4646
}
4747

4848
func loadTrainerFixtures(ctx context.Context, application app.Application) error {

internal/trainer/ports/grpc.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package ports
22

33
import (
44
"context"
5-
"errors"
65
"time"
76

87
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/genproto/trainer"
98
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app"
10-
"github.com/golang/protobuf/ptypes"
119
"github.com/golang/protobuf/ptypes/empty"
1210
"github.com/golang/protobuf/ptypes/timestamp"
1311
"google.golang.org/grpc/codes"
@@ -23,10 +21,7 @@ func NewGrpcServer(application app.Application) GrpcServer {
2321
}
2422

2523
func (g GrpcServer) MakeHourAvailable(ctx context.Context, request *trainer.UpdateHourRequest) (*empty.Empty, error) {
26-
trainingTime, err := protoTimestampToTime(request.Time)
27-
if err != nil {
28-
return nil, status.Error(codes.InvalidArgument, "unable to parse time")
29-
}
24+
trainingTime := protoTimestampToTime(request.Time)
3025

3126
if err := g.app.Commands.MakeHoursAvailable.Handle(ctx, []time.Time{trainingTime}); err != nil {
3227
return nil, status.Error(codes.Internal, err.Error())
@@ -36,10 +31,7 @@ func (g GrpcServer) MakeHourAvailable(ctx context.Context, request *trainer.Upda
3631
}
3732

3833
func (g GrpcServer) ScheduleTraining(ctx context.Context, request *trainer.UpdateHourRequest) (*empty.Empty, error) {
39-
trainingTime, err := protoTimestampToTime(request.Time)
40-
if err != nil {
41-
return nil, status.Error(codes.InvalidArgument, "unable to parse time")
42-
}
34+
trainingTime := protoTimestampToTime(request.Time)
4335

4436
if err := g.app.Commands.ScheduleTraining.Handle(ctx, trainingTime); err != nil {
4537
return nil, status.Error(codes.Internal, err.Error())
@@ -49,10 +41,7 @@ func (g GrpcServer) ScheduleTraining(ctx context.Context, request *trainer.Updat
4941
}
5042

5143
func (g GrpcServer) CancelTraining(ctx context.Context, request *trainer.UpdateHourRequest) (*empty.Empty, error) {
52-
trainingTime, err := protoTimestampToTime(request.Time)
53-
if err != nil {
54-
return nil, status.Error(codes.InvalidArgument, "unable to parse time")
55-
}
44+
trainingTime := protoTimestampToTime(request.Time)
5645

5746
if err := g.app.Commands.CancelTraining.Handle(ctx, trainingTime); err != nil {
5847
return nil, status.Error(codes.Internal, err.Error())
@@ -62,10 +51,7 @@ func (g GrpcServer) CancelTraining(ctx context.Context, request *trainer.UpdateH
6251
}
6352

6453
func (g GrpcServer) IsHourAvailable(ctx context.Context, request *trainer.IsHourAvailableRequest) (*trainer.IsHourAvailableResponse, error) {
65-
trainingTime, err := protoTimestampToTime(request.Time)
66-
if err != nil {
67-
return nil, status.Error(codes.InvalidArgument, "unable to parse time")
68-
}
54+
trainingTime := protoTimestampToTime(request.Time)
6955

7056
isAvailable, err := g.app.Queries.HourAvailability.Handle(ctx, trainingTime)
7157
if err != nil {
@@ -75,13 +61,6 @@ func (g GrpcServer) IsHourAvailable(ctx context.Context, request *trainer.IsHour
7561
return &trainer.IsHourAvailableResponse{IsAvailable: isAvailable}, nil
7662
}
7763

78-
func protoTimestampToTime(timestamp *timestamp.Timestamp) (time.Time, error) {
79-
t, err := ptypes.Timestamp(timestamp)
80-
if err != nil {
81-
return time.Time{}, errors.New("unable to parse time")
82-
}
83-
84-
t = t.UTC().Truncate(time.Hour)
85-
86-
return t, nil
64+
func protoTimestampToTime(timestamp *timestamp.Timestamp) time.Time {
65+
return timestamp.AsTime().UTC().Truncate(time.Hour)
8766
}

internal/trainer/ports/http.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func NewHttpServer(application app.Application) HttpServer {
2222
}
2323

2424
func (h HttpServer) GetTrainerAvailableHours(w http.ResponseWriter, r *http.Request, params GetTrainerAvailableHoursParams) {
25-
2625
dateModels, err := h.app.Queries.TrainerAvailableHours.Handle(r.Context(), query.AvailableHours{
2726
From: params.DateFrom,
2827
To: params.DateTo,

internal/trainings/.golangci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- deadcode
5+
- errcheck
6+
- gosimple
7+
- govet
8+
- ineffassign
9+
- staticcheck
10+
- structcheck
11+
- typecheck
12+
- unused
13+
- varcheck
14+
- asciicheck
15+
- bodyclose
16+
- dogsled
17+
- exhaustive
18+
- exportloopref
19+
- gocognit
20+
- goconst
21+
- gofmt
22+
- goheader
23+
- goimports
24+
- gosec
25+
- misspell
26+
- nakedret
27+
- nestif
28+
- noctx
29+
- rowserrcheck
30+
- sqlclosecheck
31+
- unconvert
32+
- unparam
33+
- whitespace
34+
35+
issues:
36+
exclude:
37+
- "composite literal uses unkeyed fields"
38+
exclude-rules:
39+
- path: _test\.go
40+
linters:
41+
- gosec
42+
- noctx
43+
- unparam
44+
- bodyclose
45+
- path: fixtures.go
46+
linters:
47+
- gosec

0 commit comments

Comments
 (0)