Skip to content

Commit 0b0c264

Browse files
committed
golang-ci lint updates
1 parent 2c73f0b commit 0b0c264

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+397
-730
lines changed

.golangci.yml

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
linters-settings:
22
gci:
33
local-prefixes: github.com/Permify/permify
4+
gosec:
5+
excludes:
6+
- 'G404'
7+
goimports:
8+
local-prefixes: 'github.com/Permify/permify'
9+
maligned:
10+
suggest-new: true
411
dupl:
512
threshold: 100
613
errorlint:
@@ -53,85 +60,49 @@ linters-settings:
5360
require-specific: true
5461

5562
linters:
56-
disable-all: true
5763
enable:
58-
- asciicheck
64+
- bidichk
5965
- bodyclose
60-
- cyclop
61-
- deadcode
62-
- depguard
63-
- dogsled
64-
- dupl
65-
- durationcheck
6666
- errcheck
67+
- errname
6768
- errorlint
68-
- exhaustive
69-
- exportloopref
70-
- forbidigo
71-
- funlen
72-
- gci
73-
- gochecknoglobals
74-
- gochecknoinits
75-
- gocognit
76-
- goconst
77-
- gocritic
78-
- gocyclo
79-
- godot
80-
- godox
81-
- goerr113
82-
- gofmt
8369
- gofumpt
8470
- goimports
85-
- gomnd
86-
- gomodguard
8771
- goprintffuncname
8872
- gosec
8973
- gosimple
9074
- govet
75+
- importas
9176
- ineffassign
9277
- makezero
93-
- misspell
94-
- nakedret
95-
- nestif
96-
- nlreturn
97-
- noctx
98-
- nolintlint
99-
- paralleltest
78+
- prealloc
10079
- predeclared
80+
- promlinter
10181
- revive
102-
- rowserrcheck
103-
- sqlclosecheck
10482
- staticcheck
105-
- structcheck
10683
- stylecheck
107-
- tparallel
108-
- thelper
84+
- tenv
10985
- typecheck
11086
- unconvert
111-
- unparam
11287
- unused
113-
- varcheck
114-
- wsl
11588
- whitespace
11689

117-
# disable:
118-
# - exhaustivestruct
119-
# - ifshort
120-
# - goheader
121-
# - prealloc
122-
# - testpackage
123-
# - wrapcheck
124-
12590
issues:
12691
exclude-rules:
12792
- path: integration-test
12893
linters:
12994
- paralleltest
13095
- godot
131-
- path: internal/servers/http
96+
- text: 'tx.Rollback()'
13297
linters:
133-
- godot
134-
98+
- 'errcheck'
99+
- path: 'internal/repositories/mocks'
100+
linters:
101+
- 'errcheck'
135102
run:
103+
tests: false
136104
skip-dirs:
137105
- docs
106+
107+
output:
108+
sort-results: true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/jackc/pgproto3/v2 v2.3.1
2323
github.com/jackc/pgtype v1.13.0
2424
github.com/jackc/pgx/v4 v4.17.2
25-
github.com/onsi/ginkgo/v2 v2.5.0
25+
github.com/onsi/ginkgo/v2 v2.6.0
2626
github.com/onsi/gomega v1.24.1
2727
github.com/pkg/errors v0.9.1
2828
github.com/rs/cors v1.8.2

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,12 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+
366366
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
367367
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
368368
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
369+
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
369370
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
370371
github.com/onsi/ginkgo/v2 v2.5.0 h1:TRtrvv2vdQqzkwrQ1ke6vtXf7IK34RBUJafIy1wMwls=
371372
github.com/onsi/ginkgo/v2 v2.5.0/go.mod h1:Luc4sArBICYCS8THh8v3i3i5CuSZO+RaQRaJoeNwomw=
373+
github.com/onsi/ginkgo/v2 v2.6.0 h1:9t9b9vRUbFq3C4qKFCGkVuq/fIHji802N1nrtkh1mNc=
374+
github.com/onsi/ginkgo/v2 v2.6.0/go.mod h1:63DOGlLAH8+REH8jUGdL3YpCpu7JODesutUjdENfUAc=
372375
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
373376
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
374377
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=

integration-test/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
attempts = 20
1818

1919
// HTTP REST
20-
basePath = "http://" + host + "/v1"
20+
// basePath = "http://" + host + "/v1"
2121
)
2222

2323
func TestMain(m *testing.M) {

internal/commands/check.go

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package commands
33
import (
44
"context"
55
"errors"
6-
`sync`
7-
`sync/atomic`
6+
"sync"
7+
"sync/atomic"
88

99
"github.com/Permify/permify/internal/keys"
1010
"github.com/Permify/permify/internal/repositories"
1111
"github.com/Permify/permify/pkg/database"
12-
`github.com/Permify/permify/pkg/dsl/schema`
12+
"github.com/Permify/permify/pkg/dsl/schema"
1313
"github.com/Permify/permify/pkg/logger"
1414
base "github.com/Permify/permify/pkg/pb/base/v1"
15-
`github.com/Permify/permify/pkg/token`
15+
"github.com/Permify/permify/pkg/token"
1616
"github.com/Permify/permify/pkg/tuple"
1717
)
1818

@@ -39,7 +39,6 @@ func NewCheckCommand(km keys.CommandKeyManager, sr repositories.SchemaReader, rr
3939

4040
// Execute -
4141
func (command *CheckCommand) Execute(ctx context.Context, request *base.PermissionCheckRequest) (response *base.PermissionCheckResponse, err error) {
42-
4342
if request.Depth == 0 {
4443
request.Depth = 20
4544
}
@@ -83,7 +82,6 @@ func (command *CheckCommand) Execute(ctx context.Context, request *base.Permissi
8382
return response, err
8483
}
8584
child = action.Child
86-
break
8785
case base.EntityDefinition_RELATIONAL_REFERENCE_RELATION:
8886
var leaf *base.Leaf
8987
computedUserSet := &base.ComputedUserSet{Relation: request.GetPermission()}
@@ -92,7 +90,6 @@ func (command *CheckCommand) Execute(ctx context.Context, request *base.Permissi
9290
Exclusion: false,
9391
}
9492
child = &base.Child{Type: &base.Child_Leaf{Leaf: leaf}}
95-
break
9693
default:
9794
return response, errors.New(base.ErrorCode_ERROR_CODE_ACTION_DEFINITION_NOT_FOUND.String())
9895
}
@@ -199,15 +196,13 @@ func (command *CheckCommand) checkDirect(ctx context.Context, request *base.Perm
199196
if exclusion {
200197
if resp.GetCan() == base.PermissionCheckResponse_RESULT_ALLOWED {
201198
return denied(loadDepth(request))
202-
} else {
203-
return allowed(loadDepth(request))
204199
}
205-
} else {
206-
return &base.PermissionCheckResponse{
207-
Can: resp.GetCan(),
208-
RemainingDepth: loadDepth(request),
209-
}, nil
200+
return allowed(loadDepth(request))
210201
}
202+
return &base.PermissionCheckResponse{
203+
Can: resp.GetCan(),
204+
RemainingDepth: loadDepth(request),
205+
}, nil
211206
}
212207

213208
if isDepthFinish(request) {
@@ -252,22 +247,21 @@ func (command *CheckCommand) checkDirect(ctx context.Context, request *base.Perm
252247
}
253248
command.commandKeyManager.SetCheckKey(request, result)
254249
return result, nil
255-
} else {
256-
if !tuple.IsSubjectUser(t.GetSubject()) && t.GetSubject().GetRelation() != tuple.ELLIPSIS {
257-
i++
258-
decrease(request, int32(i))
259-
checkFunctions = append(checkFunctions, command.checkDirect(ctx, &base.PermissionCheckRequest{
260-
Entity: &base.Entity{
261-
Type: t.GetSubject().GetType(),
262-
Id: t.GetSubject().GetId(),
263-
},
264-
Permission: t.GetSubject().GetRelation(),
265-
Subject: request.GetSubject(),
266-
SnapToken: request.GetSnapToken(),
267-
SchemaVersion: request.GetSchemaVersion(),
268-
Depth: loadDepth(request),
269-
}, exclusion))
270-
}
250+
}
251+
if !tuple.IsSubjectUser(t.GetSubject()) && t.GetSubject().GetRelation() != tuple.ELLIPSIS {
252+
i++
253+
decrease(request, int32(i))
254+
checkFunctions = append(checkFunctions, command.checkDirect(ctx, &base.PermissionCheckRequest{
255+
Entity: &base.Entity{
256+
Type: t.GetSubject().GetType(),
257+
Id: t.GetSubject().GetId(),
258+
},
259+
Permission: t.GetSubject().GetRelation(),
260+
Subject: request.GetSubject(),
261+
SnapToken: request.GetSnapToken(),
262+
SchemaVersion: request.GetSchemaVersion(),
263+
Depth: loadDepth(request),
264+
}, exclusion))
271265
}
272266
}
273267

@@ -294,7 +288,6 @@ func (command *CheckCommand) checkDirect(ctx context.Context, request *base.Perm
294288
// checkTupleToUserSet -
295289
func (command *CheckCommand) checkTupleToUserSet(ctx context.Context, request *base.PermissionCheckRequest, ttu *base.TupleToUserSet, exclusion bool) CheckFunction {
296290
return func(ctx context.Context) (*base.PermissionCheckResponse, error) {
297-
298291
if isDepthFinish(request) {
299292
return &base.PermissionCheckResponse{
300293
Can: base.PermissionCheckResponse_RESULT_DENIED,

internal/commands/check_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package commands
22

33
import (
44
"context"
5+
56
. "github.com/onsi/ginkgo/v2"
67
. "github.com/onsi/gomega"
78

8-
`github.com/Permify/permify/internal/keys`
9+
"github.com/Permify/permify/internal/keys"
910
"github.com/Permify/permify/internal/repositories/mocks"
1011
"github.com/Permify/permify/pkg/database"
1112
"github.com/Permify/permify/pkg/dsl/compiler"
1213
"github.com/Permify/permify/pkg/dsl/schema"
1314
"github.com/Permify/permify/pkg/logger"
1415
base "github.com/Permify/permify/pkg/pb/base/v1"
15-
`github.com/Permify/permify/pkg/token`
16+
"github.com/Permify/permify/pkg/token"
1617
"github.com/Permify/permify/pkg/tuple"
1718
)
1819

@@ -485,7 +486,6 @@ entity doc {
485486

486487
Context("Github Sample: Check", func() {
487488
It("Github Sample: Case 1", func() {
488-
489489
var err error
490490

491491
// SCHEMA
@@ -544,7 +544,6 @@ entity doc {
544544
})
545545

546546
It("Github Sample: Case 2", func() {
547-
548547
var err error
549548

550549
// SCHEMA
@@ -669,7 +668,6 @@ entity doc {
669668
})
670669

671670
It("Github Sample: Case 3", func() {
672-
673671
var err error
674672

675673
// SCHEMA

internal/commands/expand.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66

77
"github.com/Permify/permify/internal/repositories"
88
"github.com/Permify/permify/pkg/database"
9-
`github.com/Permify/permify/pkg/dsl/schema`
9+
"github.com/Permify/permify/pkg/dsl/schema"
1010
"github.com/Permify/permify/pkg/logger"
1111
base "github.com/Permify/permify/pkg/pb/base/v1"
12-
`github.com/Permify/permify/pkg/token`
13-
`github.com/Permify/permify/pkg/tuple`
12+
"github.com/Permify/permify/pkg/token"
13+
"github.com/Permify/permify/pkg/tuple"
1414
)
1515

1616
// ExpandCommand -
@@ -33,7 +33,6 @@ func NewExpandCommand(sr repositories.SchemaReader, rr repositories.Relationship
3333

3434
// Execute -
3535
func (command *ExpandCommand) Execute(ctx context.Context, request *base.PermissionExpandRequest) (response *base.PermissionExpandResponse, err error) {
36-
3736
if request.GetSnapToken() == "" {
3837
var st token.SnapToken
3938
st, err = command.relationshipReader.HeadSnapshot(ctx)
@@ -73,7 +72,6 @@ func (command *ExpandCommand) Execute(ctx context.Context, request *base.Permiss
7372
return response, err
7473
}
7574
child = action.Child
76-
break
7775
case base.EntityDefinition_RELATIONAL_REFERENCE_RELATION:
7876
var leaf *base.Leaf
7977
computedUserSet := &base.ComputedUserSet{Relation: request.GetPermission()}
@@ -82,7 +80,6 @@ func (command *ExpandCommand) Execute(ctx context.Context, request *base.Permiss
8280
Exclusion: false,
8381
}
8482
child = &base.Child{Type: &base.Child_Leaf{Leaf: leaf}}
85-
break
8683
default:
8784
return response, errors.New(base.ErrorCode_ERROR_CODE_ACTION_DEFINITION_NOT_FOUND.String())
8885
}
@@ -143,7 +140,6 @@ func (command *ExpandCommand) expandLeaf(ctx context.Context, request *base.Perm
143140

144141
// set -
145142
func (command *ExpandCommand) setChild(ctx context.Context, request *base.PermissionExpandRequest, children []*base.Child, combiner ExpandCombiner) ExpandFunction {
146-
147143
var functions []ExpandFunction
148144
for _, child := range children {
149145
switch child.GetType().(type) {
@@ -164,7 +160,6 @@ func (command *ExpandCommand) setChild(ctx context.Context, request *base.Permis
164160
// expandDirect -
165161
func (command *ExpandCommand) expandDirect(ctx context.Context, request *base.PermissionExpandRequest, exclusion bool) ExpandFunction {
166162
return func(ctx context.Context, expandChan chan<- ExpandResponse) {
167-
168163
target := &base.EntityAndRelation{
169164
Entity: request.GetEntity(),
170165
Relation: request.GetPermission(),

0 commit comments

Comments
 (0)