Skip to content

feat: add linter pairedbrackets #3225

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
github.com/ldez/tagliatelle v0.3.1
github.com/leonklingele/grouper v1.1.0
github.com/lufeee/execinquery v1.2.1
github.com/maratori/pairedbrackets v1.0.0
github.com/maratori/testableexamples v1.0.0
github.com/maratori/testpackage v1.1.0
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0
Expand Down Expand Up @@ -179,7 +180,7 @@ require (
golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum

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

12 changes: 12 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ var defaultLintersSettings = LintersSettings{
RequireSpecific: false,
AllowUnused: false,
},
PairedBrackets: PairedBracketsSettings{
IgnoreFuncCalls: []string{
"github.com/stretchr/testify/assert",
"github.com/stretchr/testify/require",
},
},
Prealloc: PreallocSettings{
Simple: true,
RangeLoops: true,
Expand Down Expand Up @@ -184,6 +190,7 @@ type LintersSettings struct {
Nlreturn NlreturnSettings
NoLintLint NoLintLintSettings
NoNamedReturns NoNamedReturnsSettings
PairedBrackets PairedBracketsSettings
ParallelTest ParallelTestSettings
Prealloc PreallocSettings
Predeclared PredeclaredSettings
Expand Down Expand Up @@ -556,6 +563,11 @@ type NoLintLintSettings struct {
type NoNamedReturnsSettings struct {
ReportErrorInDefer bool `mapstructure:"report-error-in-defer"`
}

type PairedBracketsSettings struct {
IgnoreFuncCalls []string `mapstructure:"ignore-func-calls"`
}

type ParallelTestSettings struct {
IgnoreMissing bool `mapstructure:"ignore-missing"`
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/golinters/pairedbrackets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package golinters

import (
"github.com/maratori/pairedbrackets/pkg/pairedbrackets"
"golang.org/x/tools/go/analysis"

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

func NewPairedbrackets(cfg *config.PairedBracketsSettings) *goanalysis.Linter {
var a = pairedbrackets.NewAnalyzer()

var settings map[string]map[string]interface{}
if cfg != nil {
settings = map[string]map[string]interface{}{
a.Name: {
pairedbrackets.IgnoreFuncCallsFlagName: cfg.IgnoreFuncCalls,
},
}
}

return goanalysis.NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, settings).
WithLoadMode(goanalysis.LoadModeTypesInfo)
}
8 changes: 8 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
nlreturnCfg *config.NlreturnSettings
noLintLintCfg *config.NoLintLintSettings
noNamedReturnsCfg *config.NoNamedReturnsSettings
pairedBracketsCfg *config.PairedBracketsSettings
parallelTestCfg *config.ParallelTestSettings
preallocCfg *config.PreallocSettings
predeclaredCfg *config.PredeclaredSettings
Expand Down Expand Up @@ -229,6 +230,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
noLintLintCfg = &m.cfg.LintersSettings.NoLintLint
noNamedReturnsCfg = &m.cfg.LintersSettings.NoNamedReturns
preallocCfg = &m.cfg.LintersSettings.Prealloc
pairedBracketsCfg = &m.cfg.LintersSettings.PairedBrackets
parallelTestCfg = &m.cfg.LintersSettings.ParallelTest
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
promlinterCfg = &m.cfg.LintersSettings.Promlinter
Expand Down Expand Up @@ -674,6 +676,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/stbenjam/no-sprintf-host-port"),

linter.NewConfig(golinters.NewPairedbrackets(pairedBracketsCfg)).
WithSince("v1.50.0").
WithPresets(linter.PresetFormatting).
WithLoadForGoAnalysis().
WithURL("https://github.com/maratori/pairedbrackets"),

linter.NewConfig(golinters.NewParallelTest(parallelTestCfg)).
WithSince("v1.33.0").
WithLoadForGoAnalysis().
Expand Down
Loading