-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dramatically reduce memory usage (#758)
Run all linters per package. It allows unloading package data when it's processed. It dramatically reduces memory (and CPU because of GC) usage. Relates: #337
- Loading branch information
Showing
74 changed files
with
2,488 additions
and
2,430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,52 @@ | ||
package golinters | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync" | ||
|
||
deadcodeAPI "github.com/golangci/go-misc/deadcode" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
"github.com/golangci/golangci-lint/pkg/lint/linter" | ||
"github.com/golangci/golangci-lint/pkg/result" | ||
) | ||
|
||
type Deadcode struct{} | ||
|
||
func (Deadcode) Name() string { | ||
return "deadcode" | ||
} | ||
|
||
func (Deadcode) Desc() string { | ||
return "Finds unused code" | ||
} | ||
|
||
func (d Deadcode) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) { | ||
issues, err := deadcodeAPI.Run(lintCtx.Program) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(issues) == 0 { | ||
return nil, nil | ||
} | ||
|
||
res := make([]result.Issue, 0, len(issues)) | ||
for _, i := range issues { | ||
res = append(res, result.Issue{ | ||
Pos: i.Pos, | ||
Text: fmt.Sprintf("%s is unused", formatCode(i.UnusedIdentName, lintCtx.Cfg)), | ||
FromLinter: d.Name(), | ||
}) | ||
func NewDeadcode() *goanalysis.Linter { | ||
const linterName = "deadcode" | ||
var mu sync.Mutex | ||
var resIssues []result.Issue | ||
|
||
analyzer := &analysis.Analyzer{ | ||
Name: goanalysis.TheOnlyAnalyzerName, | ||
Doc: goanalysis.TheOnlyanalyzerDoc, | ||
Run: func(pass *analysis.Pass) (interface{}, error) { | ||
prog := goanalysis.MakeFakeLoaderProgram(pass) | ||
issues, err := deadcodeAPI.Run(prog) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := make([]result.Issue, 0, len(issues)) | ||
for _, i := range issues { | ||
res = append(res, result.Issue{ | ||
Pos: i.Pos, | ||
Text: fmt.Sprintf("%s is unused", formatCode(i.UnusedIdentName, nil)), | ||
FromLinter: linterName, | ||
}) | ||
} | ||
mu.Lock() | ||
resIssues = append(resIssues, res...) | ||
mu.Unlock() | ||
|
||
return nil, nil | ||
}, | ||
} | ||
return res, nil | ||
return goanalysis.NewLinter( | ||
linterName, | ||
"Finds unused code", | ||
[]*analysis.Analyzer{analyzer}, | ||
nil, | ||
).WithIssuesReporter(func(*linter.Context) []result.Issue { | ||
return resIssues | ||
}).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.