Skip to content

Commit

Permalink
feat: update lint
Browse files Browse the repository at this point in the history
  • Loading branch information
boodyvo committed Sep 25, 2024
1 parent cbbf9ad commit df40d96
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 8 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ jobs:
with:
go-version: '1.21'

- name: Load Version
id: load-version
run: |
GOLANGCI_VERSION=$(cat .golangci-version)
REV=$(git merge-base origin/master HEAD)
echo "GOLANGCI_VERSION=$GOLANGCI_VERSION" >> $GITHUB_ENV
echo "REV=$REV" >> $GITHUB_ENV
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=10m
version: ${{ env.GOLANGCI_VERSION }}
args: -v -c .golangci.yml --new-from-rev ${{ env.REV }}

integration-tests:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .golangci-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.59
133 changes: 133 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
run:
timeout: 20m # set maximum time allowed for the linter to run. If the linting process exceeds this duration, it will be terminated
modules-download-mode: readonly # Ensures that modules are not modified during the linting process
allow-parallel-runners: true # enables parallel execution of linters to speed up linting process
skip-dirs:
- vendor
- hard-keeper-bot # a lot of errors for old code, need to fix

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
# - dupl
# - dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
# - exhaustive
- exportloopref
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
- goconst
- gocritic
- godox
- gofmt
# - gofumpt
- goheader
- goimports
- mnd
# - gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- importas
- ineffassign
# - interfacebloat
- lll
- loggercheck
- makezero
- mirror
- misspell
- musttag
# - nakedret
# - nestif
- nilerr
# - nilnil
# - noctx
- nolintlint
# - nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
# - reassign
- revive
- rowserrcheck
- staticcheck
# - stylecheck
- tagalign
# - testpackage
# - thelper
# - tparallel
- typecheck
# - unconvert
- unparam
- unused
# - usestdlibvars
- wastedassign
# - whitespace
- wrapcheck

issues:
exclude-rules:
# Disable funlen for "func Test..." or func (suite *Suite) Test..." type functions
# These functions tend to be descriptive and exceed length limits.
- source: "^func (\\(.*\\) )?Test"
linters:
- funlen

linters-settings:
errcheck:
check-blank: true # check for assignments to the blank identifier '_' when errors are returned
check-type-assertions: false # check type assertion
errorlint:
check-generated: false # disabled linting of generated files
default-signifies-exhaustive: false # exhaustive handling of error types
exhaustive:
default-signifies-exhaustive: false # exhaustive handling of error types
gci:
sections: # defines the order of import sections
- standard
- default
- localmodule
goconst:
min-len: 3 # min length for string constants to be checked
min-occurrences: 3 # min occurrences of the same constant before it's flagged
godox:
keywords: # specific keywords to flag for further action
- BUG
- FIXME
- HACK
gosec:
exclude-generated: true
lll:
line-length: 120
misspell:
locale: US
ignore-words: expect
nolintlint:
allow-leading-space: false
require-explanation: true
require-specific: true
prealloc:
simple: true # enables simple preallocation checks
range-loops: true # enabled preallocation checks in range loops
for-loops: false # disables preallocation checks in for loops
unparam:
check-exported: true # checks exported functions and methods for unused params
16 changes: 9 additions & 7 deletions grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ import (

// NewGrpcConnection parses a GRPC endpoint and creates a connection to it
func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) {
grpcUrl, err := url.Parse(endpoint)
grpcURL, err := url.Parse(endpoint)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse grpc url: %w", err)
}

var secureOpt grpc.DialOption
switch grpcUrl.Scheme {
switch grpcURL.Scheme {
case "http":
secureOpt = grpc.WithInsecure()
case "https":
creds := credentials.NewTLS(&tls.Config{})
creds := credentials.NewTLS(&tls.Config{
MinVersion: tls.VersionTLS12,
})
secureOpt = grpc.WithTransportCredentials(creds)
default:
return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcUrl.Scheme)
return nil, fmt.Errorf("unknown grpc url scheme: %s", grpcURL.Scheme)
}

grpcConn, err := grpc.Dial(grpcUrl.Host, secureOpt)
grpcConn, err := grpc.Dial(grpcURL.Host, secureOpt)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to dial grpc: %w", err)
}

return grpcConn, nil
Expand Down

0 comments on commit df40d96

Please sign in to comment.