Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: upgrade lint & go #649

Merged
merged 11 commits into from
Nov 14, 2024
4 changes: 2 additions & 2 deletions .github/workflows/dapr-bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (b *Bot) HandleEvent(ctx context.Context, event Event) (res string, err err
switch command {
case "/assign":
assignee, err := b.AssignIssueToCommenter(event)
res = fmt.Sprintf("👍 Issue assigned to %s", assignee)
res = "👍 Issue assigned to " + assignee
if err == nil {
err = b.CreateIssueComment(fmt.Sprintf("🚀 Issue assigned to you @%s", assignee), event)
err = b.CreateIssueComment("🚀 Issue assigned to you @"+assignee, event)
} else {
err = b.CreateIssueComment("⚠️ Unable to assign issue", event)
}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/dapr-bot/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/dapr/go-sdk/.github/workflows/dapr-bot

go 1.22

toolchain go1.22.0
go 1.23.3

require (
github.com/google/go-github/v55 v55.0.0
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-dapr-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
env:
GOVER: ${{ matrix.gover }}
GOLANGCILINT_VER: v1.55.2
GOLANGCILINT_VER: v1.61.0

steps:
- name: Checkout
Expand All @@ -38,7 +37,7 @@ jobs:
run: make test

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCILINT_VER }}
working-directory: ./.github/workflows/dapr-bot
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-on-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:

jobs:
build:
name: Test on ${{ matrix.gover }}
name: Test
runs-on: ubuntu-latest
env:
GOLANGCILINT_VER: v1.55.2
GOLANGCILINT_VER: v1.61.0

steps:
- name: Checkout
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/test-tooling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ jobs:
strategy:
fail-fast: false
matrix:
gover:
- "1.21"
- "1.22"
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
runs-on: ${{ matrix.os }}
env:
GOVER: ${{ matrix.gover }}
GOLANGCILINT_VER: v1.55.2 # Make sure to bump /tools/check-lint-version/main_test.go
GOLANGCILINT_VER: v1.61.0 # Make sure to bump /tools/check-lint-version/main_test.go

steps:
- name: Checkout
Expand All @@ -38,7 +34,7 @@ jobs:
- name: Setup
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOVER }}
go-version-file: ./tools/check-lint-version/go.mod

- name: Tidy
working-directory: ./tools/check-lint-version
Expand Down
117 changes: 41 additions & 76 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 10m
timeout: 15m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1
Expand All @@ -13,31 +13,35 @@ run:
tests: true

# list of build tags, all linters use it. Default is empty list.
#build-tags:
# - mytag
build-tags:
- unit
- allcomponents
- subtlecrypto

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# skip-files:
# - ".*\\.my\\.go$"
# - lib/bad.go

issues:
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
exclude-dirs:
- ^pkg.*client.*clientset.*versioned.*
- ^pkg.*client.*informers.*externalversions.*
- ^pkg.*proto.*

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# skip-files:
# - ".*\\.my\\.go$"
# - lib/bad.go

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: tab
formats:
- format: tab

# print lines of code with issue, default is true
print-issued-lines: true
Expand All @@ -57,23 +61,19 @@ linters-settings:
# default is false: such cases aren't reported by default.
check-blank: false

# [deprecated] comma-separated list of pairs of the form pkg:regex
# the regex is used to ignore names within pkg. (default "fmt:.*").
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
ignore: fmt:.*,io/ioutil:^Read.*
exclude-functions:
- fmt:.*
- io/ioutil:^Read.*

# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
# exclude:
# exclude:

funlen:
lines: 60
statements: 40

govet:
# report about shadowed variables
check-shadowing: true

# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand All @@ -86,28 +86,12 @@ linters-settings:
# enable or disable analyzers by name
enable:
- atomicalign
enable-all: false
disable:
- shadow
enable-all: false
disable-all: false
revive:
max-open-files: 2048
# enable-all-rules: true
rules:
- name: cyclomatic
severity: warning
disabled: false
arguments: [20]
- name: argument-limit
severity: warning
disabled: false
arguments: [8]
- name: if-return
severity: warning
disabled: false
- name: unused-parameter
severity: warning
disabled: true
# minimal confidence for issues, default is 0.8
confidence: 0.8
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
Expand All @@ -121,9 +105,6 @@ linters-settings:
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
dupl:
# tokens count to trigger issue, 150 by default
threshold: 100
Expand Down Expand Up @@ -152,10 +133,9 @@ linters-settings:
desc: "you must use github.com/cenkalti/backoff/v4"
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English. (Do not specify a locale value)
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
# locale:

# locale: default
ignore-words:
- someword
lll:
Expand All @@ -164,12 +144,6 @@ linters-settings:
line-length: 120
# tab width in spaces. Default to 1.
tab-width: 1
unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
Expand All @@ -187,7 +161,7 @@ linters-settings:
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
# enabled-checks:
# enabled-checks:

# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
Expand Down Expand Up @@ -235,17 +209,20 @@ linters-settings:
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow case blocks to end with a whitespace.
force-case-trailing-whitespace: 0
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
# If the number of lines in a case block is equal to or lager than this number,
# the case *must* end white a newline.
# https://github.com/bombsimon/wsl/blob/master/doc/configuration.md#force-case-trailing-whitespace
# Default: 0
force-case-trailing-whitespace: 1

linters:
fast: false
enable-all: true
disable:
# TODO Enforce the below linters later
- nosnakecase
- musttag
- dupl
- errcheck
- funlen
Expand All @@ -254,26 +231,17 @@ linters:
- gocyclo
- gocognit
- godox
- interfacer
- lll
- maligned
- scopelint
- unparam
- wsl
- gomnd
- testpackage
- goerr113
- nestif
- nlreturn
- tagliatelle
- ifshort
- forbidigo
- exhaustive
- exhaustruct
- exhaustivestruct
- noctx
- gci
- golint
- tparallel
- paralleltest
- wrapcheck
Expand All @@ -287,7 +255,6 @@ linters:
- varnamelen
- errorlint
- forcetypeassert
- ifshort
- maintidx
- nilnil
- predeclared
Expand All @@ -300,14 +267,12 @@ linters:
- asasalint
- rowserrcheck
- sqlclosecheck
- structcheck
- varcheck
- deadcode
- golint
- inamedparam
issues:
exclude-rules:
- path: .*_test.go
linters:
- godot

- tagalign
- mnd
- canonicalheader
- exportloopref
- execinquery
- err113
- fatcontext
- forbidigo # TODO: Re-enable and remove fmt.println
6 changes: 3 additions & 3 deletions actor/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var ignoredActorMethods = []string{"Type"}
// init initializes the action method exclusion list with methods from ServerImplBaseCtx and ReminderCallee interfaces.
func init() {
serverImplBaseCtxType := reflect.TypeOf(&actor.ServerImplBaseCtx{})
for i := 0; i < serverImplBaseCtxType.NumMethod(); i++ {
for i := range serverImplBaseCtxType.NumMethod() {
ignoredActorMethods = append(ignoredActorMethods, serverImplBaseCtxType.Method(i).Name)
}
ReminderCallType := reflect.TypeOf((*actor.ReminderCallee)(nil)).Elem()
for i := 0; i < ReminderCallType.NumMethod(); i++ {
for i := range ReminderCallType.NumMethod() {
ignoredActorMethods = append(ignoredActorMethods, ReminderCallType.Method(i).Name)
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ type MethodType struct {
// suitableMethods returns suitable Rpc methods of typ.
func suitableMethods(typ reflect.Type) map[string]*MethodType {
methods := make(map[string]*MethodType)
for m := 0; m < typ.NumMethod(); m++ {
for m := range typ.NumMethod() {
method := typ.Method(m)
// skip methods from ServerImplBaseCtx struct and ServerContext and ReminderCallee interfaces.
if slices.Contains(ignoredActorMethods, method.Name) {
Expand Down
1 change: 0 additions & 1 deletion actor/state/actor_state_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func TestNewActorStateChange(t *testing.T) {
},
}
for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.want, NewActorStateChange(test.stateName, test.value, test.changeKind, &test.ttl))
})
Expand Down
4 changes: 2 additions & 2 deletions client/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
}

numField := valueOfActor.NumField()
for i := 0; i < numField; i++ {
for i := range numField {

Check warning on line 292 in client/actor.go

View check run for this annotation

Codecov / codecov/patch

client/actor.go#L292

Added line #L292 was not covered by tests
t := typeOfActor.Field(i)
methodName := t.Name
if methodName == "Type" {
Expand All @@ -312,7 +312,7 @@
}

funcOuts := make([]reflect.Type, outNum)
for i := 0; i < outNum; i++ {
for i := range outNum {

Check warning on line 315 in client/actor.go

View check run for this annotation

Codecov / codecov/patch

client/actor.go#L315

Added line #L315 was not covered by tests
funcOuts[i] = t.Type.Out(i)
}

Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (s *testDaprServer) SubscribeConfiguration(in *pb.SubscribeConfigurationReq
return err
}

for i := 0; i < 5; i++ {
for range 5 {
select {
case <-stopCh:
return nil
Expand Down
1 change: 0 additions & 1 deletion client/internal/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Parsed struct {
TLS bool
}

//nolint:revive
func ParseGRPCEndpoint(endpoint string) (Parsed, error) {
target := endpoint
if len(target) == 0 {
Expand Down
Loading