Skip to content

Commit 3fdbcfb

Browse files
committed
gomodreplace -> gomoddirectives
1 parent aa47c27 commit 3fdbcfb

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

.golangci.example.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,16 @@ linters-settings:
449449
servingv1: knative.dev/serving/pkg/apis/serving/v1
450450
# using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package
451451
autoscalingv1alpha1: knative.dev/serving/pkg/apis/autoscaling/v1alpha1
452-
gomodreplace:
452+
gomoddirectives:
453453
# Allow local `replace` directives. Default is false.
454-
local: false
454+
replace-local: false
455455
# List of allowed `replace` directives. Default is empty.
456-
allow-list:
456+
replace-allow-list:
457457
- launchpad.net/gocheck
458+
# Allow to not explain why the version has been retracted in the `retract` directives. Default is false.
459+
retract-allow-no-explanation: false
460+
# Forbid the use of the `exclude` directives. Default is false.
461+
exclude-forbidden: false
458462

459463
# The custom section can be used to define linter plugins to be loaded at runtime. See README doc
460464
# for more info.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ require (
4141
github.com/kulti/thelper v0.4.0
4242
github.com/kunwardeep/paralleltest v1.0.2
4343
github.com/kyoh86/exportloopref v0.1.8
44-
github.com/ldez/gomodreplace v0.2.0
44+
github.com/ldez/gomoddirectives v0.1.0
4545
github.com/maratori/testpackage v1.0.1
4646
github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0
4747
github.com/mattn/go-colorable v0.1.8

go.sum

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

pkg/config/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ type LintersSettings struct {
276276
Predeclared PredeclaredSettings
277277
Cyclop Cyclop
278278
ImportAs ImportAsSettings
279-
GoModReplace GoModReplaceSettings
279+
GoModDirectives GoModDirectivesSettings
280280

281281
Custom map[string]CustomLinterSettings
282282
}
@@ -465,9 +465,11 @@ type Cyclop struct {
465465

466466
type ImportAsSettings map[string]string
467467

468-
type GoModReplaceSettings struct {
469-
AllowList []string `mapstructure:"allow-list"`
470-
Local bool `mapstructure:"local"`
468+
type GoModDirectivesSettings struct {
469+
ReplaceAllowList []string `mapstructure:"replace-allow-list"`
470+
ReplaceLocal bool `mapstructure:"replace-local"`
471+
ExcludeForbidden bool `mapstructure:"exclude-forbidden"`
472+
RetractAllowNoExplanation bool `mapstructure:"retract-allow-no-explanation"`
471473
}
472474

473475
var defaultLintersSettings = LintersSettings{

pkg/golinters/gomodreplace.go renamed to pkg/golinters/gomoddirectives.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ package golinters
33
import (
44
"sync"
55

6-
"github.com/golangci/golangci-lint/pkg/config"
7-
"github.com/ldez/gomodreplace"
6+
"github.com/ldez/gomoddirectives"
87
"golang.org/x/tools/go/analysis"
98

9+
"github.com/golangci/golangci-lint/pkg/config"
1010
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
1111
"github.com/golangci/golangci-lint/pkg/lint/linter"
1212
"github.com/golangci/golangci-lint/pkg/result"
1313
)
1414

15-
const goModReplaceName = "gomodreplace"
15+
const goModDirectivesName = "gomoddirectives"
1616

17-
// NewGoModReplace returns a new gomodreplace linter.
18-
func NewGoModReplace(settings *config.GoModReplaceSettings) *goanalysis.Linter {
17+
// NewGoModDirectives returns a new gomoddirectives linter.
18+
func NewGoModDirectives(settings *config.GoModDirectivesSettings) *goanalysis.Linter {
1919
var issues []goanalysis.Issue
2020
var mu sync.Mutex
2121

22-
var opts gomodreplace.Options
22+
var opts gomoddirectives.Options
2323
if settings != nil {
24-
opts.AllowLocal = settings.Local
25-
opts.AllowList = settings.AllowList
24+
opts.ReplaceAllowLocal = settings.ReplaceLocal
25+
opts.ReplaceAllowList = settings.ReplaceAllowList
26+
opts.RetractAllowNoExplanation = settings.RetractAllowNoExplanation
27+
opts.ExcludeForbidden = settings.ExcludeForbidden
2628
}
2729

2830
analyzer := &analysis.Analyzer{
@@ -31,24 +33,24 @@ func NewGoModReplace(settings *config.GoModReplaceSettings) *goanalysis.Linter {
3133
}
3234

3335
return goanalysis.NewLinter(
34-
goModReplaceName,
35-
"Manage the use of replace directives in go.mod.",
36+
goModDirectivesName,
37+
"Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.",
3638
[]*analysis.Analyzer{analyzer},
3739
nil,
3840
).WithContextSetter(func(lintCtx *linter.Context) {
3941
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
40-
results, err := gomodreplace.Analyze(opts)
42+
results, err := gomoddirectives.Analyze(opts)
4143
if err != nil {
4244
lintCtx.Log.Warnf("running %s failed: %s: "+
43-
"if you are not using go modules it is suggested to disable this linter", goModReplaceName, err)
45+
"if you are not using go modules it is suggested to disable this linter", goModDirectivesName, err)
4446
return nil, nil
4547
}
4648

4749
mu.Lock()
4850

4951
for _, p := range results {
5052
issues = append(issues, goanalysis.NewIssue(&result.Issue{
51-
FromLinter: goModReplaceName,
53+
FromLinter: goModDirectivesName,
5254
Pos: p.Start,
5355
Text: p.Reason,
5456
}, pass))

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
100100
var reviveCfg *config.ReviveSettings
101101
var cyclopCfg *config.Cyclop
102102
var importAsCfg *config.ImportAsSettings
103-
var goModReplaceCfg *config.GoModReplaceSettings
103+
var goModDirectivesCfg *config.GoModDirectivesSettings
104104
if m.cfg != nil {
105105
govetCfg = &m.cfg.LintersSettings.Govet
106106
testpackageCfg = &m.cfg.LintersSettings.Testpackage
@@ -113,7 +113,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
113113
reviveCfg = &m.cfg.LintersSettings.Revive
114114
cyclopCfg = &m.cfg.LintersSettings.Cyclop
115115
importAsCfg = &m.cfg.LintersSettings.ImportAs
116-
goModReplaceCfg = &m.cfg.LintersSettings.GoModReplace
116+
goModDirectivesCfg = &m.cfg.LintersSettings.GoModDirectives
117117
}
118118
const megacheckName = "megacheck"
119119
lcs := []*linter.Config{
@@ -396,10 +396,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
396396
WithPresets(linter.PresetStyle).
397397
WithLoadForGoAnalysis().
398398
WithURL("https://github.com/gostaticanalysis/forcetypeassert"),
399-
linter.NewConfig(golinters.NewGoModReplace(goModReplaceCfg)).
399+
linter.NewConfig(golinters.NewGoModDirectives(goModDirectivesCfg)).
400400
WithPresets(linter.PresetStyle).
401401
WithLoadForGoAnalysis().
402-
WithURL("https://github.com/ldez/gomodreplace"),
402+
WithURL("https://github.com/ldez/gomoddirectives"),
403403

404404
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
405405
linter.NewConfig(golinters.NewNoLintLint()).

0 commit comments

Comments
 (0)