Skip to content

Commit 082a2c7

Browse files
committed
chore: update implementation
1 parent 04b6723 commit 082a2c7

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

.golangci.next.reference.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,9 @@ linters-settings:
13691369
# Forbid the use of the `toolchain` directive.
13701370
# Default: false
13711371
toolchain-forbidden: true
1372+
# Defines a pattern to validate `toolchain` directive.
1373+
# Default: '' (no match)
1374+
toolchain-pattern: 'go1\.23\.\d+$'
13721375
# Forbid the use of the `tool` directives.
13731376
# Default: false
13741377
tool-forbidden: true

jsonschema/golangci.next.jsonschema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,10 @@
16801680
"type": "boolean",
16811681
"default": false
16821682
},
1683+
"toolchain-pattern": {
1684+
"description": "Defines a pattern to validate `toolchain` directive.",
1685+
"type": "string",
1686+
},
16831687
"tool-forbidden": {
16841688
"description": "Forbid the use of the `tool` directives.",
16851689
"type": "boolean",

pkg/config/linters_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ type GoModDirectivesSettings struct {
586586
ExcludeForbidden bool `mapstructure:"exclude-forbidden"`
587587
RetractAllowNoExplanation bool `mapstructure:"retract-allow-no-explanation"`
588588
ToolchainForbidden bool `mapstructure:"toolchain-forbidden"`
589+
ToolchainPattern string `mapstructure:"toolchain-pattern"`
589590
ToolForbidden bool `mapstructure:"tool-forbidden"`
590591
GoDebugForbidden bool `mapstructure:"go-debug-forbidden"`
591592
GoVersionPattern string `mapstructure:"go-version-pattern"`

pkg/golinters/gomoddirectives/gomoddirectives.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter {
3030
opts.ToolForbidden = settings.ToolForbidden
3131
opts.GoDebugForbidden = settings.GoDebugForbidden
3232

33+
if settings.ToolchainPattern != "" {
34+
exp, err := regexp.Compile(settings.ToolchainPattern)
35+
if err != nil {
36+
internal.LinterLogger.Fatalf("%s: invalid toolchain pattern: %v", linterName, err)
37+
} else {
38+
opts.ToolchainPattern = exp
39+
}
40+
}
41+
3342
if settings.GoVersionPattern != "" {
3443
exp, err := regexp.Compile(settings.GoVersionPattern)
3544
if err != nil {

0 commit comments

Comments
 (0)