File tree Expand file tree Collapse file tree 4 files changed +55
-5
lines changed
golinters/gomoddirectives Expand file tree Collapse file tree 4 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -1355,17 +1355,29 @@ linters-settings:
13551355 gomoddirectives :
13561356 # Allow local `replace` directives.
13571357 # Default: false
1358- replace-local : false
1358+ replace-local : true
13591359 # List of allowed `replace` directives.
13601360 # Default: []
13611361 replace-allow-list :
13621362 - launchpad.net/gocheck
13631363 # Allow to not explain why the version has been retracted in the `retract` directives.
13641364 # Default: false
1365- retract-allow-no-explanation : false
1365+ retract-allow-no-explanation : true
13661366 # Forbid the use of the `exclude` directives.
13671367 # Default: false
1368- exclude-forbidden : false
1368+ exclude-forbidden : true
1369+ # Forbid the use of the `toolchain` directive.
1370+ # Default: false
1371+ toolchain-forbidden : true
1372+ # Forbid the use of the `tool` directives.
1373+ # Default: false
1374+ tool-forbidden : true
1375+ # Forbid the use of the `godebug` directive.
1376+ # Default: false
1377+ go-debug-forbidden : true
1378+ # Defines a pattern to validate `go` minimum version directive.
1379+ # Default: '' (no match)
1380+ go-version-pattern : ' \d\.\d+(\.0)?'
13691381
13701382 gomodguard :
13711383 allowed :
Original file line number Diff line number Diff line change 16681668 "retract-allow-no-explanation" : {
16691669 "description" : " Allow to not explain why the version has been retracted in the `retract` directives." ,
16701670 "type" : " boolean" ,
1671- "default" : true
1671+ "default" : false
16721672 },
16731673 "exclude-forbidden" : {
16741674 "description" : " Forbid the use of the `exclude` directives." ,
16751675 "type" : " boolean" ,
1676- "default" : true
1676+ "default" : false
1677+ },
1678+ "toolchain-forbidden" : {
1679+ "description" : " Forbid the use of the `toolchain` directive." ,
1680+ "type" : " boolean" ,
1681+ "default" : false
1682+ },
1683+ "tool-forbidden" : {
1684+ "description" : " Forbid the use of the `tool` directives." ,
1685+ "type" : " boolean" ,
1686+ "default" : false
1687+ },
1688+ "go-debug-forbidden" : {
1689+ "description" : " Forbid the use of the `godebug` directive." ,
1690+ "type" : " boolean" ,
1691+ "default" : false
1692+ },
1693+ "go-version-pattern" : {
1694+ "description" : " Defines a pattern to validate `go` minimum version directive." ,
1695+ "type" : " string" ,
1696+ "default" : " "
16771697 }
16781698 }
16791699 },
Original file line number Diff line number Diff line change @@ -585,6 +585,10 @@ type GoModDirectivesSettings struct {
585585 ReplaceLocal bool `mapstructure:"replace-local"`
586586 ExcludeForbidden bool `mapstructure:"exclude-forbidden"`
587587 RetractAllowNoExplanation bool `mapstructure:"retract-allow-no-explanation"`
588+ ToolchainForbidden bool `mapstructure:"toolchain-forbidden"`
589+ ToolForbidden bool `mapstructure:"tool-forbidden"`
590+ GoDebugForbidden bool `mapstructure:"go-debug-forbidden"`
591+ GoVersionPattern string `mapstructure:"go-version-pattern"`
588592}
589593
590594type GoModGuardSettings struct {
Original file line number Diff line number Diff line change 11package gomoddirectives
22
33import (
4+ "regexp"
45 "sync"
56
7+ "github.com/golangci/golangci-lint/pkg/golinters/internal"
68 "github.com/ldez/gomoddirectives"
79 "golang.org/x/tools/go/analysis"
810
@@ -24,6 +26,18 @@ func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter {
2426 opts .ReplaceAllowList = settings .ReplaceAllowList
2527 opts .RetractAllowNoExplanation = settings .RetractAllowNoExplanation
2628 opts .ExcludeForbidden = settings .ExcludeForbidden
29+ opts .ToolchainForbidden = settings .ToolchainForbidden
30+ opts .ToolForbidden = settings .ToolForbidden
31+ opts .GoDebugForbidden = settings .GoDebugForbidden
32+
33+ if settings .GoVersionPattern != "" {
34+ exp , err := regexp .Compile (settings .GoVersionPattern )
35+ if err != nil {
36+ internal .LinterLogger .Fatalf ("%s: invalid Go version pattern: %v" , linterName , err )
37+ } else {
38+ opts .GoVersionPattern = exp
39+ }
40+ }
2741 }
2842
2943 analyzer := & analysis.Analyzer {
You can’t perform that action at this time.
0 commit comments