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

Add fparams linter #4853

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ linters-settings:
# Default: false
analyze-types: true

fparams:
# Disable check function params
# Default: false
disableCheckFuncParams: false

# Disable check function return values
# Default false
disableCheckFuncReturns: false

funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
Expand Down Expand Up @@ -2593,6 +2602,7 @@ linters:
- fatcontext
- forbidigo
- forcetypeassert
- fparams
- funlen
- gci
- ginkgolinter
Expand Down Expand Up @@ -2708,6 +2718,7 @@ linters:
- fatcontext
- forbidigo
- forcetypeassert
- fparams
- funlen
- gci
- ginkgolinter
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/golangci/golangci-lint

go 1.21.0
go 1.22

toolchain go1.22.4

require (
4d63.com/gocheckcompilerdirectives v1.2.1
Expand All @@ -19,6 +21,7 @@ require (
github.com/alexkohler/nakedret/v2 v2.0.4
github.com/alexkohler/prealloc v1.0.0
github.com/alingse/asasalint v0.0.11
github.com/artemk1337/fparams v1.0.0
github.com/ashanbrown/forbidigo v1.6.0
github.com/ashanbrown/makezero v1.1.1
github.com/bkielbasa/cyclop v1.2.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type LintersSettings struct {
Exhaustive ExhaustiveSettings
Exhaustruct ExhaustructSettings
Forbidigo ForbidigoSettings
Fparams Fparams
Funlen FunlenSettings
Gci GciSettings
GinkgoLinter GinkgoLinterSettings
Expand Down Expand Up @@ -455,6 +456,11 @@ func (p *ForbidigoPattern) MarshalString() ([]byte, error) {
return yaml.Marshal(p)
}

type Fparams struct {
DisableCheckFuncParams bool `mapstructure:"disable-check-params"`
DisableCheckFuncReturns bool `mapstructure:"disable-check-returns"`
}

type FunlenSettings struct {
Lines int
Statements int
Expand Down
28 changes: 28 additions & 0 deletions pkg/golinters/fparams/fparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package fparams

import (
"github.com/artemk1337/fparams/pkg/analyzer"
"github.com/golangci/golangci-lint/pkg/config"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func New(settings *config.Fparams) *goanalysis.Linter {
a := analyzer.NewAnalyzer()

cfg := map[string]map[string]any{}
if settings != nil {
cfg[a.Name] = map[string]any{
"disableCheckFuncParams": settings.DisableCheckFuncParams,
"disableCheckFuncReturns": settings.DisableCheckFuncReturns,
}
}

return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
11 changes: 11 additions & 0 deletions pkg/golinters/fparams/fparams_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fparams

import (
"testing"

"github.com/golangci/golangci-lint/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
74 changes: 74 additions & 0 deletions pkg/golinters/fparams/testdata/fix/in/fparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//golangcitest:args -Efparams
//golangcitest:expected_exitcode 0
package fparams

func invalidArgsFuncA(a int,
b string) {
return
}

func invalidArgsFuncB(a, b int,
c string) {
return
}

func invalidArgsFuncC(a,
b int,
c string,
) {
return
}

func invalidArgsFuncD(
a, b int,
c string,
) {
return
}

func invalidArgsAndResultsFuncA(a int,
b string) (c bool,
d error) {
return false, nil
}

func invalidArgsAndResultsFuncB(a int, b int,
c string) (
d bool,
e error) {
return false, nil
}

func invalidResultsFuncA() (a bool,
b error) {
return false, nil
}

func invalidResultsFuncB() (
a bool,
b error) {
return false, nil
}

func invalidResultsFuncC() (
a bool, b error) {
return false, nil
}

func invalidResultsFuncD() (
a, b bool,
c error) {
return false, false, nil
}

func invalidResultsFuncE() (bool, bool,
error) {
return false, false, nil
}

func invalidResultsFuncF() (
bool,
bool,
error) {
return false, false, nil
}
100 changes: 100 additions & 0 deletions pkg/golinters/fparams/testdata/fix/out/fparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//golangcitest:args -Efparams
//golangcitest:expected_exitcode 0
package fparams

func invalidArgsFuncA(
a int,
b string,
) {
return
}

func invalidArgsFuncB(
a int,
b int,
c string,
) {
return
}

func invalidArgsFuncC(
a int,
b int,
c string,
) {
return
}

func invalidArgsFuncD(
a int,
b int,
c string,
) {
return
}

func invalidArgsAndResultsFuncA(
a int,
b string,
) (
c bool,
d error,
) {
return false, nil
}

func invalidArgsAndResultsFuncB(
a int,
b int,
c string,
) (
d bool,
e error,
) {
return false, nil
}

func invalidResultsFuncA() (
a bool,
b error,
) {
return false, nil
}

func invalidResultsFuncB() (
a bool,
b error,
) {
return false, nil
}

func invalidResultsFuncC() (
a bool,
b error,
) {
return false, nil
}

func invalidResultsFuncD() (
a bool,
b bool,
c error,
) {
return false, false, nil
}

func invalidResultsFuncE() (
bool,
bool,
error,
) {
return false, false, nil
}

func invalidResultsFuncF() (
bool,
bool,
error,
) {
return false, false, nil
}
Loading