Skip to content

Commit 4f52a4c

Browse files
authored
Merge branch 'master' into windows-junctions
2 parents 0b6f2ce + 8a5d479 commit 4f52a4c

File tree

14 files changed

+95
-43
lines changed

14 files changed

+95
-43
lines changed

.golangci.next.reference.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,6 +2318,23 @@ linters-settings:
23182318
patterns:
23192319
- ".*"
23202320

2321+
recvcheck:
2322+
# Disables the built-in method exclusions:
2323+
# - `MarshalText`
2324+
# - `MarshalJSON`
2325+
# - `MarshalYAML`
2326+
# - `MarshalXML`
2327+
# - `MarshalBinary`
2328+
# - `GobEncode`
2329+
# Default: false
2330+
disable-builtin: true
2331+
# User-defined method exclusions.
2332+
# The format is `struct_name.method_name` (ex: `Foo.MethodName`).
2333+
# A wildcard `*` can use as a struct name (ex: `*.MethodName`).
2334+
# Default: []
2335+
exclusions:
2336+
- "*.Value"
2337+
23212338
revive:
23222339
# Maximum number of open files at the same time.
23232340
# See https://github.com/mgechev/revive#command-line-flags

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ require (
5656
github.com/jgautheron/goconst v1.7.1
5757
github.com/jingyugao/rowserrcheck v1.1.1
5858
github.com/jjti/go-spancheck v0.6.4
59-
github.com/julz/importas v0.1.1-0.20241016092914-b26b8fc96f8a
59+
github.com/julz/importas v0.2.0
6060
github.com/karamaru-alpha/copyloopvar v1.1.0
6161
github.com/kisielk/errcheck v1.8.0
6262
github.com/kkHAIKE/contextcheck v1.1.5
@@ -84,7 +84,7 @@ require (
8484
github.com/pelletier/go-toml/v2 v2.2.3
8585
github.com/polyfloyd/go-errorlint v1.7.0
8686
github.com/quasilyte/go-ruleguard/dsl v0.3.22
87-
github.com/raeperd/recvcheck v0.1.2
87+
github.com/raeperd/recvcheck v0.2.0
8888
github.com/rogpeppe/go-internal v1.13.1
8989
github.com/ryancurrah/gomodguard v1.3.5
9090
github.com/ryanrolds/sqlclosecheck v0.5.1

go.sum

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,24 @@
23942394
}
23952395
}
23962396
},
2397+
"recvcheck": {
2398+
"type": "object",
2399+
"additionalProperties": false,
2400+
"properties": {
2401+
"disable-builtin": {
2402+
"description": "Disables the built-in method exclusions.",
2403+
"type": "boolean",
2404+
"default": true
2405+
},
2406+
"exclusions": {
2407+
"description": "User-defined method exclusions.",
2408+
"type": "array",
2409+
"items": {
2410+
"type": "string"
2411+
}
2412+
}
2413+
}
2414+
},
23972415
"nonamedreturns": {
23982416
"type": "object",
23992417
"additionalProperties": false,

pkg/commands/flagsets.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
5656

5757
internal.AddDeprecatedHackedStringSlice(fs, "skip-files", color.GreenString("Regexps of files to skip"))
5858
internal.AddDeprecatedHackedStringSlice(fs, "skip-dirs", color.GreenString("Regexps of directories to skip"))
59-
internal.AddDeprecatedFlagAndBind(v, fs, fs.Bool, "skip-dirs-use-default", "run.skip-dirs-use-default", true,
60-
formatList("Use or not use default excluded directories:", processors.StdExcludeDirRegexps))
6159

6260
const allowParallelDesc = "Allow multiple parallel golangci-lint instances running.\n" +
6361
"If false (default) - golangci-lint acquires file lock on start."

pkg/config/issues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type Issues struct {
128128

129129
NeedFix bool `mapstructure:"fix"`
130130

131-
ExcludeGeneratedStrict bool `mapstructure:"exclude-generated-strict"` // Deprecated: use ExcludeGenerated instead.
131+
ExcludeGeneratedStrict *bool `mapstructure:"exclude-generated-strict"` // Deprecated: use ExcludeGenerated instead.
132132
}
133133

134134
func (i *Issues) Validate() error {

pkg/config/linters_settings.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ var defaultLintersSettings = LintersSettings{
169169
Unused: UnusedSettings{
170170
FieldWritesAreUses: true,
171171
PostStatementsAreReads: false,
172-
ExportedIsUsed: true,
173172
ExportedFieldsAreUsed: true,
174173
ParametersAreUsed: true,
175174
LocalVariablesAreUsed: true,
@@ -271,6 +270,7 @@ type LintersSettings struct {
271270
Promlinter PromlinterSettings
272271
ProtoGetter ProtoGetterSettings
273272
Reassign ReassignSettings
273+
Recvcheck RecvcheckSettings
274274
Revive ReviveSettings
275275
RowsErrCheck RowsErrCheckSettings
276276
SlogLint SlogLintSettings
@@ -329,8 +329,10 @@ type BiDiChkSettings struct {
329329
}
330330

331331
type CopyLoopVarSettings struct {
332-
IgnoreAlias bool `mapstructure:"ignore-alias"` // Deprecated: use CheckAlias
333-
CheckAlias bool `mapstructure:"check-alias"`
332+
CheckAlias bool `mapstructure:"check-alias"`
333+
334+
// Deprecated: use CheckAlias
335+
IgnoreAlias *bool `mapstructure:"ignore-alias"`
334336
}
335337

336338
type Cyclop struct {
@@ -548,7 +550,7 @@ type GodotSettings struct {
548550
Period bool `mapstructure:"period"`
549551

550552
// Deprecated: use Scope instead
551-
CheckAll bool `mapstructure:"check-all"`
553+
CheckAll *bool `mapstructure:"check-all"`
552554
}
553555

554556
type GodoxSettings struct {
@@ -641,7 +643,7 @@ type GovetSettings struct {
641643
Settings map[string]map[string]any
642644

643645
// Deprecated: the linter should be enabled inside Enable.
644-
CheckShadowing bool `mapstructure:"check-shadowing"`
646+
CheckShadowing *bool `mapstructure:"check-shadowing"`
645647
}
646648

647649
func (cfg *GovetSettings) Validate() error {
@@ -818,6 +820,11 @@ type ReassignSettings struct {
818820
Patterns []string `mapstructure:"patterns"`
819821
}
820822

823+
type RecvcheckSettings struct {
824+
DisableBuiltin bool `mapstructure:"disable-builtin"`
825+
Exclusions []string `mapstructure:"exclusions"`
826+
}
827+
821828
type ReviveSettings struct {
822829
Go string `mapstructure:"-"`
823830
MaxOpenFiles int `mapstructure:"max-open-files"`
@@ -857,7 +864,7 @@ type SlogLintSettings struct {
857864
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
858865

859866
// Deprecated: use Context instead.
860-
ContextOnly bool `mapstructure:"context-only"`
867+
ContextOnly *bool `mapstructure:"context-only"`
861868
}
862869

863870
type SpancheckSettings struct {
@@ -977,11 +984,14 @@ type UseStdlibVarsSettings struct {
977984
TimeLayout bool `mapstructure:"time-layout"`
978985
CryptoHash bool `mapstructure:"crypto-hash"`
979986
DefaultRPCPath bool `mapstructure:"default-rpc-path"`
980-
OSDevNull bool `mapstructure:"os-dev-null"` // Deprecated
981987
SQLIsolationLevel bool `mapstructure:"sql-isolation-level"`
982988
TLSSignatureScheme bool `mapstructure:"tls-signature-scheme"`
983989
ConstantKind bool `mapstructure:"constant-kind"`
984-
SyslogPriority bool `mapstructure:"syslog-priority"` // Deprecated
990+
991+
// Deprecated
992+
OSDevNull *bool `mapstructure:"os-dev-null"`
993+
// Deprecated
994+
SyslogPriority *bool `mapstructure:"syslog-priority"`
985995
}
986996

987997
type UseTestingSettings struct {
@@ -1007,11 +1017,13 @@ type UnparamSettings struct {
10071017
type UnusedSettings struct {
10081018
FieldWritesAreUses bool `mapstructure:"field-writes-are-uses"`
10091019
PostStatementsAreReads bool `mapstructure:"post-statements-are-reads"`
1010-
ExportedIsUsed bool `mapstructure:"exported-is-used"` // Deprecated
10111020
ExportedFieldsAreUsed bool `mapstructure:"exported-fields-are-used"`
10121021
ParametersAreUsed bool `mapstructure:"parameters-are-used"`
10131022
LocalVariablesAreUsed bool `mapstructure:"local-variables-are-used"`
10141023
GeneratedIsUsed bool `mapstructure:"generated-is-used"`
1024+
1025+
// Deprecated
1026+
ExportedIsUsed *bool `mapstructure:"exported-is-used"`
10151027
}
10161028

10171029
type VarnamelenSettings struct {

pkg/config/loader.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ func (l *Loader) handleGoVersion() {
304304
os.Setenv("GOSECGOVERSION", l.cfg.Run.Go)
305305
}
306306

307-
//nolint:gocyclo // The complexity is expected by the cases to handle.
308307
func (l *Loader) handleDeprecation() error {
309308
if l.cfg.InternalTest || l.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
310309
return nil
@@ -322,19 +321,17 @@ func (l *Loader) handleDeprecation() error {
322321
l.cfg.Issues.ExcludeDirs = l.cfg.Run.SkipDirs
323322
}
324323

325-
// The 2 options are true by default.
326324
// Deprecated since v1.57.0
327-
if !l.cfg.Run.UseDefaultSkipDirs {
325+
if l.cfg.Run.UseDefaultSkipDirs != nil {
328326
l.log.Warnf("The configuration option `run.skip-dirs-use-default` is deprecated, please use `issues.exclude-dirs-use-default`.")
327+
l.cfg.Issues.UseDefaultExcludeDirs = *l.cfg.Run.UseDefaultSkipDirs
329328
}
330-
l.cfg.Issues.UseDefaultExcludeDirs = l.cfg.Run.UseDefaultSkipDirs && l.cfg.Issues.UseDefaultExcludeDirs
331329

332-
// The 2 options are false by default.
333330
// Deprecated since v1.57.0
334-
if l.cfg.Run.ShowStats {
331+
if l.cfg.Run.ShowStats != nil {
335332
l.log.Warnf("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`")
333+
l.cfg.Output.ShowStats = *l.cfg.Run.ShowStats
336334
}
337-
l.cfg.Output.ShowStats = l.cfg.Run.ShowStats || l.cfg.Output.ShowStats
338335

339336
// Deprecated since v1.63.0
340337
if l.cfg.Output.UniqByLine != nil {
@@ -363,9 +360,11 @@ func (l *Loader) handleDeprecation() error {
363360
}
364361

365362
// Deprecated since v1.59.0
366-
if l.cfg.Issues.ExcludeGeneratedStrict {
363+
if l.cfg.Issues.ExcludeGeneratedStrict != nil {
367364
l.log.Warnf("The configuration option `issues.exclude-generated-strict` is deprecated, please use `issues.exclude-generated`")
368-
l.cfg.Issues.ExcludeGenerated = "strict" // Don't use the constants to avoid cyclic dependencies.
365+
if !*l.cfg.Issues.ExcludeGeneratedStrict {
366+
l.cfg.Issues.ExcludeGenerated = "strict" // Don't use the constants to avoid cyclic dependencies.
367+
}
369368
}
370369

371370
l.handleLinterOptionDeprecations()
@@ -376,12 +375,12 @@ func (l *Loader) handleDeprecation() error {
376375
func (l *Loader) handleLinterOptionDeprecations() {
377376
// Deprecated since v1.57.0,
378377
// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
379-
if l.cfg.LintersSettings.Govet.CheckShadowing {
378+
if l.cfg.LintersSettings.Govet.CheckShadowing != nil {
380379
l.log.Warnf("The configuration option `linters.govet.check-shadowing` is deprecated. " +
381380
"Please enable `shadow` instead, if you are not using `enable-all`.")
382381
}
383382

384-
if l.cfg.LintersSettings.CopyLoopVar.IgnoreAlias {
383+
if l.cfg.LintersSettings.CopyLoopVar.IgnoreAlias != nil {
385384
l.log.Warnf("The configuration option `linters.copyloopvar.ignore-alias` is deprecated and ignored," +
386385
"please use `linters.copyloopvar.check-alias`.")
387386
}
@@ -403,7 +402,7 @@ func (l *Loader) handleLinterOptionDeprecations() {
403402
}
404403

405404
// Deprecated since v1.33.0.
406-
if l.cfg.LintersSettings.Godot.CheckAll {
405+
if l.cfg.LintersSettings.Godot.CheckAll != nil {
407406
l.log.Warnf("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`.")
408407
}
409408

@@ -428,23 +427,23 @@ func (l *Loader) handleLinterOptionDeprecations() {
428427
}
429428

430429
// Deprecated since v1.60.0
431-
if !l.cfg.LintersSettings.Unused.ExportedIsUsed {
430+
if l.cfg.LintersSettings.Unused.ExportedIsUsed != nil {
432431
l.log.Warnf("The configuration option `linters.unused.exported-is-used` is deprecated.")
433432
}
434433

435434
// Deprecated since v1.58.0
436-
if l.cfg.LintersSettings.SlogLint.ContextOnly {
435+
if l.cfg.LintersSettings.SlogLint.ContextOnly != nil {
437436
l.log.Warnf("The configuration option `linters.sloglint.context-only` is deprecated, please use `linters.sloglint.context`.")
438437
l.cfg.LintersSettings.SlogLint.Context = cmp.Or(l.cfg.LintersSettings.SlogLint.Context, "all")
439438
}
440439

441440
// Deprecated since v1.51.0
442-
if l.cfg.LintersSettings.UseStdlibVars.OSDevNull {
441+
if l.cfg.LintersSettings.UseStdlibVars.OSDevNull != nil {
443442
l.log.Warnf("The configuration option `linters.usestdlibvars.os-dev-null` is deprecated.")
444443
}
445444

446445
// Deprecated since v1.51.0
447-
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority {
446+
if l.cfg.LintersSettings.UseStdlibVars.SyslogPriority != nil {
448447
l.log.Warnf("The configuration option `linters.usestdlibvars.syslog-priority` is deprecated.")
449448
}
450449
}

pkg/config/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ type Run struct {
2929
// Deprecated: use Issues.ExcludeDirs instead.
3030
SkipDirs []string `mapstructure:"skip-dirs"`
3131
// Deprecated: use Issues.UseDefaultExcludeDirs instead.
32-
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`
32+
UseDefaultSkipDirs *bool `mapstructure:"skip-dirs-use-default"`
3333

3434
// Deprecated: use Output.ShowStats instead.
35-
ShowStats bool `mapstructure:"show-stats"`
35+
ShowStats *bool `mapstructure:"show-stats"`
3636
}
3737

3838
func (r *Run) Validate() error {

pkg/golinters/godot/godot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func New(settings *config.GodotSettings) *goanalysis.Linter {
2424
}
2525

2626
// Convert deprecated setting
27-
if settings.CheckAll {
27+
if settings.CheckAll != nil && *settings.CheckAll {
2828
dotSettings.Scope = godot.AllScope
2929
}
3030
}

pkg/golinters/govet/govet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
190190
}
191191

192192
// Keeping for backward compatibility.
193-
if cfg.CheckShadowing && name == shadow.Analyzer.Name {
193+
if cfg.CheckShadowing != nil && *cfg.CheckShadowing && name == shadow.Analyzer.Name {
194194
return true
195195
}
196196

pkg/golinters/recvcheck/recvcheck.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ import (
44
"github.com/raeperd/recvcheck"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/goanalysis"
89
)
910

10-
func New() *goanalysis.Linter {
11-
a := recvcheck.Analyzer
11+
func New(settings *config.RecvcheckSettings) *goanalysis.Linter {
12+
var cfg recvcheck.Settings
13+
14+
if settings != nil {
15+
cfg.DisableBuiltin = settings.DisableBuiltin
16+
cfg.Exclusions = settings.Exclusions
17+
}
18+
19+
a := recvcheck.NewAnalyzer(cfg)
1220

1321
return goanalysis.NewLinter(
1422
a.Name,

pkg/golinters/usestdlibvars/usestdlibvars.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ func New(settings *config.UseStdlibVarsSettings) *goanalysis.Linter {
1818
analyzer.CryptoHashFlag: settings.CryptoHash,
1919
analyzer.HTTPMethodFlag: settings.HTTPMethod,
2020
analyzer.HTTPStatusCodeFlag: settings.HTTPStatusCode,
21-
analyzer.OSDevNullFlag: settings.OSDevNull,
21+
analyzer.OSDevNullFlag: settings.OSDevNull != nil && *settings.OSDevNull,
2222
analyzer.RPCDefaultPathFlag: settings.DefaultRPCPath,
2323
analyzer.SQLIsolationLevelFlag: settings.SQLIsolationLevel,
24-
analyzer.SyslogPriorityFlag: settings.SyslogPriority,
24+
analyzer.SyslogPriorityFlag: settings.SyslogPriority != nil && *settings.SyslogPriority,
2525
analyzer.TimeLayoutFlag: settings.TimeLayout,
2626
analyzer.TimeMonthFlag: settings.TimeMonth,
2727
analyzer.TimeWeekdayFlag: settings.TimeWeekday,

pkg/lint/lintersdb/builder_linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
672672
WithLoadForGoAnalysis().
673673
WithURL("https://github.com/curioswitch/go-reassign"),
674674

675-
linter.NewConfig(recvcheck.New()).
675+
linter.NewConfig(recvcheck.New(&cfg.LintersSettings.Recvcheck)).
676676
WithSince("v1.62.0").
677677
WithPresets(linter.PresetBugs).
678678
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)