Skip to content

Commit

Permalink
gets golang lint working better
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei committed Nov 1, 2024
1 parent 6532258 commit e4e40c0
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 66 deletions.
53 changes: 9 additions & 44 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
linters-settings:
depguard:
# new configuration
rules:
# logger:
# deny:
# # logging is allowed only by logutils.Log,
# # logrus is allowed to use only in logutils package.
# - pkg: "github.com/sirupsen/logrus"
# desc: logging is allowed only by logutils.Log
dupl:
threshold: 150
funlen:
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
statements: 50
goconst:
min-len: 2
min-occurrences: 3
min-occurrences: 10
gocritic:
enabled-tags:
- diagnostic
Expand All @@ -34,7 +25,7 @@ linters-settings:
rewrite-rules:
- pattern: "interface{}"
replacement: "any"
gomnd:
mnd:
# don't include the "operation" and "assign"
checks:
- argument
Expand All @@ -51,15 +42,6 @@ linters-settings:
ignored-functions:
- strings.SplitN

govet:
check-shadowing: false
# settings:
# printf:
# funcs:
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
# - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
Expand All @@ -78,60 +60,42 @@ linters:
disable-all: true
enable:
- bodyclose
# - depguard
- dogsled
# - dupl
- errcheck
- forbidigo
# - funlen
# - gochecknoinits
- goconst
- gocritic
# - gocyclo
- gofmt
- goimports
# - gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
# - lll
- misspell
- nakedret
- noctx
- nolintlint
- revive
- staticcheck
# - stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - wsl
- usestdlibvars

issues:
excluded-dirs:
exclude-dirs:
- frontend
- charts
- docs
- node_modules
- backend/gen
- tilt
- scripts
- python
- keycloak
# # Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
Expand All @@ -145,3 +109,4 @@ issues:

run:
timeout: 10m
tests: false # exclude test files
8 changes: 4 additions & 4 deletions backend/internal/auth/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Client) GetTokenResponse(
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", tokenurl, payload)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenurl, payload)
if err != nil {
return nil, fmt.Errorf("unable to request oauth authorization code: %w", err)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *Client) GetRefreshedAccessToken(
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "POST", tokenurl, payload)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenurl, payload)

if err != nil {
return nil, fmt.Errorf("unable to initiate refresh token request: %w", err)
Expand Down Expand Up @@ -208,7 +208,7 @@ func (c *Client) GetUserInfo(
return nil, err
}

req, err := http.NewRequestWithContext(ctx, "GET", userinfourl, http.NoBody)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, userinfourl, http.NoBody)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -276,7 +276,7 @@ type openIdConfiguration struct {
func (c *Client) getOpenIdConfiguration(ctx context.Context) (*openIdConfiguration, error) {
configUrl := fmt.Sprintf("%s/.well-known/openid-configuration", strings.TrimSuffix(c.authBaseUrl, "/"))

req, err := http.NewRequestWithContext(ctx, "GET", configUrl, http.NoBody)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, configUrl, http.NoBody)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/auth/clientcred_token_provider/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *tokenProviderClient) GetToken(ctx context.Context) (*auth_client.AuthTo
payload := strings.NewReader(
values.Encode(),
)
req, err := http.NewRequestWithContext(ctx, "POST", c.tokenurl, payload)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.tokenurl, payload)
if err != nil {
return nil, fmt.Errorf("unable to request oauth authorization code: %w", err)
}
Expand Down
5 changes: 0 additions & 5 deletions backend/pkg/metrics/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,3 @@ func timeToDate(t time.Time) mgmtv1alpha1.Date {
Day: uint32(t.Day()), //nolint:gosec // Ignoring for now
}
}

// Formats the day into the Neosync Date Format of YYYY-DD-MM
func formatDate(d *mgmtv1alpha1.Date) string {
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
}
2 changes: 1 addition & 1 deletion backend/pkg/sqlmanager/postgres/postgres-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (p *PostgresManager) GetTableInitStatements(ctx context.Context, tables []*
DataType: record.DataType,
IsNullable: record.IsNullable == "YES",
GeneratedType: record.GeneratedType,
IsSerial: record.SequenceType == "SERIAL", //nolint:goconst
IsSerial: record.SequenceType == "SERIAL",
Sequence: seqConfig,
IdentityType: &record.IdentityGeneration,
}))
Expand Down
2 changes: 1 addition & 1 deletion backend/sql/postgresql/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ func (s *PostgresSourceOptions) FromDto(dto *mgmtv1alpha1.PostgresSourceConnecti
s.NewColumnAdditionStrategy = &PostgresNewColumnAdditionStrategy{}
s.NewColumnAdditionStrategy.FromDto(dto.GetNewColumnAdditionStrategy())
} else if dto.GetHaltOnNewColumnAddition() {
// halt on new column addition is deprecated, so if the new column strat is nil but the deprecated value is true,
// halt on new column addition is deprecated, so if the new column strategy is nil but the deprecated value is true,
// we are going to store it in the new strategy format.
s.NewColumnAdditionStrategy = &PostgresNewColumnAdditionStrategy{
HaltJob: &PostgresHaltJobStrategy{},
Expand Down
4 changes: 2 additions & 2 deletions internal/postgres/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ func CreateMultiDimSlice(dims []int, elements []any) any {

// handles multi-dimensional slices
subSize := 1
for _, dim := range dims[1:] { //nolint:gosec
for _, dim := range dims[1:] {
subSize *= dim
}

for i := 0; i < firstDim; i++ {
start := i * subSize
end := start + subSize
subSlice := CreateMultiDimSlice(dims[1:], elements[start:end]) //nolint:gosec
subSlice := CreateMultiDimSlice(dims[1:], elements[start:end])
slice.Index(i).Set(reflect.ValueOf(subSlice))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package transformers
import (
"errors"
"fmt"
"strings"

mgmtv1alpha1 "github.com/nucleuscloud/neosync/backend/gen/go/protos/mgmt/v1alpha1"
transformer_utils "github.com/nucleuscloud/neosync/worker/pkg/benthos/transformers/utils"
Expand Down Expand Up @@ -95,10 +94,3 @@ func generateInternationalPhoneNumber(randomizer rng.Rand, minValue, maxValue in

return fmt.Sprintf("+%d", val), nil
}

func validateE164(p string) bool {
if len(p) >= 10 && len(p) <= 15 && strings.Contains(p, "+") {
return true
}
return false
}

0 comments on commit e4e40c0

Please sign in to comment.