Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add gomodclean linter#5898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dmrioja wants to merge1 commit intogolangci:main
base:main
Choose a base branch
Loading
fromdmrioja:dmrioja/gomodclean
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions.golangci.next.reference.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,6 +62,7 @@ linters:
- godot
- godox
- goheader
- gomodclean
- gomoddirectives
- gomodguard
- goprintffuncname
Expand DownExpand Up@@ -172,6 +173,7 @@ linters:
- godot
- godox
- goheader
- gomodclean
- gomoddirectives
- gomodguard
- goprintffuncname
Expand Down
1 change: 1 addition & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@ require (
github.com/curioswitch/go-reassign v0.3.0
github.com/daixiang0/gci v0.13.6
github.com/denis-tingaikin/go-header v0.5.0
github.com/dmrioja/gomodclean v0.2.0
github.com/fatih/color v1.18.0
github.com/firefart/nonamedreturns v1.0.6
github.com/fzipp/gocyclo v0.6.0
Expand Down
2 changes: 2 additions & 0 deletionsgo.sum
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsjsonschema/golangci.next.jsonschema.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -764,6 +764,7 @@
"godox",
"err113",
"goheader",
"gomodclean",
"gomoddirectives",
"gomodguard",
"goprintffuncname",
Expand Down
55 changes: 55 additions & 0 deletionspkg/golinters/gomodclean/gomodclean.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
package gomodclean

import (
"sync"

gomodcleananalyzer "github.com/dmrioja/gomodclean/pkg/analyzer"

"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
"github.com/golangci/golangci-lint/v2/pkg/lint/linter"
"github.com/golangci/golangci-lint/v2/pkg/result"
)

const linterName = "gomodclean"

func New() *goanalysis.Linter {
var issues []*goanalysis.Issue
var once sync.Once

analyzer := &analysis.Analyzer{
Name: linterName,
Doc: "Linter to check dependencies are well structured inside your go.mod file.",
Run: goanalysis.DummyRun,
}

return goanalysis.
NewLinterFromAnalyzer(analyzer).
WithContextSetter(func(lintCtx *linter.Context) {
analyzer.Run = func(pass *analysis.Pass) (any, error) {
once.Do(func() {
results, err := gomodcleananalyzer.Analyze()
if err != nil {
lintCtx.Log.Warnf("running %s failed: %s: "+
"if you are not using go modules it is suggested to disable this linter", linterName, err)
return
}

for _, p := range results {
issues = append(issues, goanalysis.NewIssue(&result.Issue{
FromLinter: linterName,
Pos: p.Position,
Text: p.Text,
}, pass))
}
})

return nil, nil
}
}).
WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue {
return issues
}).
WithLoadMode(goanalysis.LoadModeSyntax)
}
11 changes: 11 additions & 0 deletionspkg/golinters/gomodclean/gomodclean_integration_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
package gomodclean

import (
"testing"

"github.com/golangci/golangci-lint/v2/test/testshared/integration"
)

func TestFromTestdata(t *testing.T) {
integration.RunTestdata(t)
}
7 changes: 7 additions & 0 deletionspkg/golinters/gomodclean/testdata/go.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
module gomodclean

go 1.24.2

require github.com/dmrioja/gomodclean v0.1.1-0.20250628101813-52ee7046c81a

require golang.org/x/mod v0.25.0 // indirect
12 changes: 12 additions & 0 deletionspkg/golinters/gomodclean/testdata/go.sum
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

15 changes: 15 additions & 0 deletionspkg/golinters/gomodclean/testdata/gomodclean.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Egomodclean
package testdata

import (
"log"

"github.com/dmrioja/gomodclean/pkg/analyzer"
)

// correctGoModFile imports some dependencies to build the tesdata go.mod file.
func correctGoModFile() { //nolint:unused
results, err := analyzer.Analyze()
log.Println(results)
log.Println(err)
}
5 changes: 5 additions & 0 deletionspkg/lint/lintersdb/builder_linter.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,7 @@ import (
"github.com/golangci/golangci-lint/v2/pkg/golinters/goheader"
"github.com/golangci/golangci-lint/v2/pkg/golinters/goimports"
"github.com/golangci/golangci-lint/v2/pkg/golinters/golines"
"github.com/golangci/golangci-lint/v2/pkg/golinters/gomodclean"
"github.com/golangci/golangci-lint/v2/pkg/golinters/gomoddirectives"
"github.com/golangci/golangci-lint/v2/pkg/golinters/gomodguard"
"github.com/golangci/golangci-lint/v2/pkg/golinters/goprintffuncname"
Expand DownExpand Up@@ -375,6 +376,10 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithSince("v1.22.0").
WithURL("https://github.com/tommy-muehle/go-mnd"),

linter.NewConfig(gomodclean.New()).
WithSince("v2.2.0").
WithURL("https://github.com/dmrioja/gomodclean"),

linter.NewConfig(gomoddirectives.New(&cfg.Linters.Settings.GoModDirectives)).
WithSince("v1.39.0").
WithURL("https://github.com/ldez/gomoddirectives"),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp