Skip to content

Commit

Permalink
[TT-7431] Configure golangci-lint enabled/disables linters (TykTechno…
Browse files Browse the repository at this point in the history
…logies#4594)

<!-- Provide a general summary of your changes in the Title above -->

## Description

<!-- Describe your changes in detail -->
Changes configuration of golangci-lint.

## Related Issue

<!-- This project only accepts pull requests related to open issues. -->
<!-- If suggesting a new feature or change, please discuss it in an
issue first. -->
<!-- If fixing a bug, there should be an issue describing it with steps
to reproduce. -->
<!-- OSS: Please link to the issue here. Tyk: please create/link the
JIRA ticket. -->

https://tyktech.atlassian.net/browse/TT-7431

## Motivation and Context

<!-- Why is this change required? What problem does it solve? -->
Reduce verbosity of linter failures due to poorly configured linter
rules.

## How This Has Been Tested

<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests -->
<!-- you ran to see how your change affects other areas of the code,
etc. -->
<!-- This information is helpful for reviewers and QA. -->
`golangci-lint run --fix ./...` - updates typoes in codebase (commit
2/2) :)

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

Co-authored-by: Tit Petric <[email protected]>
  • Loading branch information
titpetric and Tit Petric authored Dec 28, 2022
1 parent 2ec3a3f commit 6a1a561
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 17 deletions.
37 changes: 37 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,40 @@ run:
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
go: '1.16'

linters:
disable:
- varnamelen
- tagliatelle
- testpackage
- paralleltest
- forbidigo
- ireturn
- goerr113
enable:
- thelper
- errcheck
- errorlint
- noctx
- dupl
- nilerr
- misspell

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
exclude-functions:
- (*github.com/TykTechnologies/tyk/gateway.Test).Run

issues:
exclude-rules:
- path: _test\.go
linters:
- dupl # many functions looks like dupes
- gocyclo # many functions can be very long
- funlen # many functions can be very long
- gosec # tests don't have CVEs
exclude:
- G404 # Use of weak random number generator (math/rand instead of crypto/rand)
- SA9004 # only the first constant in this group has an explicit type
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ type HealthCheckConfig struct {
}

type LivenessCheckConfig struct {
// Frequence of performing interval healthchecks for Redis, Dashboard, and RPC layer. Default: 10 seconds.
// Frequencies of performing interval healthchecks for Redis, Dashboard, and RPC layer. Default: 10 seconds.
CheckDuration time.Duration `json:"check_duration"`
}

Expand Down Expand Up @@ -559,10 +559,10 @@ type Config struct {
// was written.
OriginalPath string `json:"-"`

// Force your Gateway to work only on a specifc domain name. Can be overriden by API custom domain.
// Force your Gateway to work only on a specific domain name. Can be overridden by API custom domain.
HostName string `json:"hostname"`

// If your machine has mulitple network devices or IPs you can force the Gateway to use the IP address you want.
// If your machine has multiple network devices or IPs you can force the Gateway to use the IP address you want.
ListenAddress string `json:"listen_address"`

// Setting this value will change the port that Tyk listens on. Default: 8080.
Expand Down Expand Up @@ -685,7 +685,7 @@ type Config struct {
// The standard rate limiter offers similar performance as the sentinel-based limiter. This is disabled by default.
EnableSentinelRateLimiter bool `json:"enable_sentinel_rate_limiter"`

// An enchancment for the Redis and Sentinel rate limiters, that offers a significant improvement in performance by not using transactions on Redis rate-limit buckets.
// An enhancement for the Redis and Sentinel rate limiters, that offers a significant improvement in performance by not using transactions on Redis rate-limit buckets.
EnableNonTransactionalRateLimiter bool `json:"enable_non_transactional_rate_limiter"`

// How frequently a distributed rate limiter synchronises information between the Gateway nodes. Default: 2 seconds.
Expand Down Expand Up @@ -970,7 +970,7 @@ type Config struct {
// global session lifetime, in seconds.
GlobalSessionLifetime int64 `bson:"global_session_lifetime" json:"global_session_lifetime"`

// This section enables the use of the KV capabilites to substitute configuration values.
// This section enables the use of the KV capabilities to substitute configuration values.
// See more details https://tyk.io/docs/tyk-configuration-reference/kv-store/
KV struct {
Consul ConsulConfig `json:"consul"`
Expand Down
2 changes: 1 addition & 1 deletion gateway/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestAnalytics_Write(t *testing.T) {

// expect a status 499 (context canceled) from the request
assert.Equal(t, 499, record.ResponseCode)
// expect that the analytic record mantained the APIKey
// expect that the analytic record maintained the APIKey
assert.Equal(t, key, record.APIKey)

})
Expand Down
2 changes: 1 addition & 1 deletion gateway/api_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ func (gw *Gateway) loadApps(specs []*APISpec) {
for _, spec := range specs {
func() {
defer func() {
// recover from panic if one occured. Set err to nil otherwise.
// recover from panic if one occurred. Set err to nil otherwise.
if err := recover(); err != nil {
log.Errorf("Panic while loading an API: %v, panic: %v, stacktrace: %v", spec.APIDefinition, err, string(debug.Stack()))
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (gw *Gateway) getPinnedPublicKeys(host string, spec *APISpec, conf config.C
return gw.CertificateManager.ListPublicKeys(strings.Split(keyIDs, ","))
}

// dummyGetCertificate needed because TLSConfig require setting Certificates array or GetCertificate function from start, even if it get overriden by `getTLSConfigForClient`
// dummyGetCertificate needed because TLSConfig require setting Certificates array or GetCertificate function from start, even if it get overridden by `getTLSConfigForClient`
func dummyGetCertificate(*tls.ClientHelloInfo) (*tls.Certificate, error) {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/mw_redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func Test_addBodyHash(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if addBodyHash(tt.args.req, tt.args.regex, tt.args.h); hex.EncodeToString(tt.args.h.Sum(nil)) != tt.expected {
t.Errorf("addBodyHash() recieved = %v, expected %v", hex.EncodeToString(tt.args.h.Sum(nil)), tt.expected)
t.Errorf("addBodyHash() received = %v, expected %v", hex.EncodeToString(tt.args.h.Sum(nil)), tt.expected)
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions gateway/mw_url_rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ func TestInitTriggerRx(t *testing.T) {
Options.
HeaderMatches["abc"]
if headerMatch.Check("abc") == "" {
t.Errorf("Expected HeaderMatches initalized and matched, received no match")
t.Errorf("Expected HeaderMatches initialized and matched, received no match")
}

// assert QueryValMatches
Expand All @@ -1174,7 +1174,7 @@ func TestInitTriggerRx(t *testing.T) {
Options.
QueryValMatches["def"]
if queryValMatch.Check("def") == "" {
t.Errorf("Expected QueryValMatches initalized and matched, received no match")
t.Errorf("Expected QueryValMatches initialized and matched, received no match")
}

// assert PayloadMatches
Expand All @@ -1189,7 +1189,7 @@ func TestInitTriggerRx(t *testing.T) {
Options.
PayloadMatches
if payloadMatch.Check("ghi") == "" {
t.Errorf("Expected PayloadMatches initalized and matched, received no match")
t.Errorf("Expected PayloadMatches initialized and matched, received no match")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gateway/rpc_storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func (gw *Gateway) ProcessSingleOauthClientEvent(apiId, oauthClientId, orgID, ev
}
}

// ProcessOauthClientsOps performs the appropiate action for the received clients
// ProcessOauthClientsOps performs the appropriate action for the received clients
// it can be any of the Create,Update and Delete operations
func (gw *Gateway) ProcessOauthClientsOps(clients map[string]string) {
for clientInfo, action := range clients {
Expand Down
2 changes: 1 addition & 1 deletion gateway/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestSyncAPISpecsRPCFailure_CheckGlobals(t *testing.T) {
}()
dispatcher := gorpc.NewDispatcher()
dispatcher.AddFunc("GetApiDefinitions", func(clientAddr string, dr *apidef.DefRequest) (string, error) {
// the firts time called is when we start the slave gateway
// the first time called is when we start the slave gateway
return a()
})
dispatcher.AddFunc("Login", func(clientAddr, userKey string) bool {
Expand Down
4 changes: 2 additions & 2 deletions gateway/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *ReloadMachinery) OnReload() {
}
}

// Reloaded returns true if a read has occured since r was enabled
// Reloaded returns true if a read has occurred since r was enabled
func (r *ReloadMachinery) Reloaded() bool {
r.mu.RLock()
defer r.mu.RUnlock()
Expand Down Expand Up @@ -215,7 +215,7 @@ func (r *ReloadMachinery) Tick() {
r.reloadTick <- time.Time{}
}

// TickOk triggers a reload and ensures a queue happend and a reload cycle
// TickOk triggers a reload and ensures a queue happened and a reload cycle
// happens. This will block until all the cases are met.
func (r *ReloadMachinery) TickOk(t *testing.T) {
r.EnsureQueued(t)
Expand Down
2 changes: 1 addition & 1 deletion storage/redis_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (r *RedisCluster) IsMemberOfSet(keyName, value string) bool {
val, err := r.singleton().SIsMember(r.RedisController.ctx, r.fixKey(keyName), value).Result()

if err != nil {
log.Error("Error trying to check set memeber: ", err)
log.Error("Error trying to check set member: ", err)
return false
}

Expand Down

0 comments on commit 6a1a561

Please sign in to comment.