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:
1355
1355
gomoddirectives :
1356
1356
# Allow local `replace` directives.
1357
1357
# Default: false
1358
- replace-local : false
1358
+ replace-local : true
1359
1359
# List of allowed `replace` directives.
1360
1360
# Default: []
1361
1361
replace-allow-list :
1362
1362
- launchpad.net/gocheck
1363
1363
# Allow to not explain why the version has been retracted in the `retract` directives.
1364
1364
# Default: false
1365
- retract-allow-no-explanation : false
1365
+ retract-allow-no-explanation : true
1366
1366
# Forbid the use of the `exclude` directives.
1367
1367
# 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)?'
1369
1381
1370
1382
gomodguard :
1371
1383
allowed :
Original file line number Diff line number Diff line change 1668
1668
"retract-allow-no-explanation" : {
1669
1669
"description" : " Allow to not explain why the version has been retracted in the `retract` directives." ,
1670
1670
"type" : " boolean" ,
1671
- "default" : true
1671
+ "default" : false
1672
1672
},
1673
1673
"exclude-forbidden" : {
1674
1674
"description" : " Forbid the use of the `exclude` directives." ,
1675
1675
"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" : " "
1677
1697
}
1678
1698
}
1679
1699
},
Original file line number Diff line number Diff line change @@ -585,6 +585,10 @@ type GoModDirectivesSettings struct {
585
585
ReplaceLocal bool `mapstructure:"replace-local"`
586
586
ExcludeForbidden bool `mapstructure:"exclude-forbidden"`
587
587
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"`
588
592
}
589
593
590
594
type GoModGuardSettings struct {
Original file line number Diff line number Diff line change 1
1
package gomoddirectives
2
2
3
3
import (
4
+ "regexp"
4
5
"sync"
5
6
7
+ "github.com/golangci/golangci-lint/pkg/golinters/internal"
6
8
"github.com/ldez/gomoddirectives"
7
9
"golang.org/x/tools/go/analysis"
8
10
@@ -24,6 +26,18 @@ func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter {
24
26
opts .ReplaceAllowList = settings .ReplaceAllowList
25
27
opts .RetractAllowNoExplanation = settings .RetractAllowNoExplanation
26
28
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
+ }
27
41
}
28
42
29
43
analyzer := & analysis.Analyzer {
You can’t perform that action at this time.
0 commit comments