Skip to content

Commit 33e3c49

Browse files
authored
Merge pull request #46 from ThreeDotsLabs/added-linters
Added linters
2 parents ca092e9 + 74a0270 commit 33e3c49

20 files changed

Lines changed: 251 additions & 59 deletions

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ proto:
2323

2424
.PHONY: lint
2525
lint:
26+
@go-cleanarch
27+
@./scripts/lint.sh common
2628
@./scripts/lint.sh trainer
2729
@./scripts/lint.sh trainings
2830
@./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/common/client/grpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func grpcDialOpts(grpcAddr string) ([]grpc.DialOption, error) {
7070
return nil, errors.Wrap(err, "cannot load root CA cert")
7171
}
7272
creds := credentials.NewTLS(&tls.Config{
73-
RootCAs: systemRoots,
73+
RootCAs: systemRoots,
74+
MinVersion: tls.VersionTLS12,
7475
})
7576

7677
return []grpc.DialOption{

internal/common/server/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func RunHTTPServerOnAddr(addr string, createHandler func(router chi.Router) http
3131

3232
logrus.Info("Starting HTTP server")
3333

34-
http.ListenAndServe(addr, rootRouter)
34+
_ = http.ListenAndServe(addr, rootRouter)
3535
}
3636

3737
func setMiddlewares(router *chi.Mux) {

internal/common/tests/clients.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func (c TrainerHTTPClient) MakeHourAvailable(t *testing.T, hour time.Time) int {
4949
Hours: []time.Time{hour},
5050
})
5151
require.NoError(t, err)
52+
require.NoError(t, response.Body.Close())
53+
5254
return response.StatusCode
5355
}
5456

@@ -57,6 +59,8 @@ func (c TrainerHTTPClient) MakeHourUnavailable(t *testing.T, hour time.Time) {
5759
Hours: []time.Time{hour},
5860
})
5961
require.NoError(t, err)
62+
require.NoError(t, response.Body.Close())
63+
6064
require.Equal(t, http.StatusNoContent, response.StatusCode)
6165
}
6266

@@ -113,6 +117,8 @@ func (c TrainingsHTTPClient) CreateTrainingShouldFail(t *testing.T, note string,
113117
Time: hour,
114118
})
115119
require.NoError(t, err)
120+
require.NoError(t, response.Body.Close())
121+
116122
require.Equal(t, http.StatusInternalServerError, response.StatusCode)
117123
}
118124

@@ -127,6 +133,8 @@ func (c TrainingsHTTPClient) GetTrainings(t *testing.T) trainings.Trainings {
127133
func (c TrainingsHTTPClient) CancelTraining(t *testing.T, trainingUUID string, expectedStatusCode int) {
128134
response, err := c.client.CancelTraining(context.Background(), trainingUUID)
129135
require.NoError(t, err)
136+
require.NoError(t, response.Body.Close())
137+
130138
require.Equal(t, expectedStatusCode, response.StatusCode)
131139
}
132140

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 {

0 commit comments

Comments
 (0)