dev: rename function parameter i
to issue
(#4460)
This commit is contained in:
parent
f18e6c3700
commit
808c06d0cc
@ -13,9 +13,9 @@ type Issue struct {
|
||||
Pass *analysis.Pass
|
||||
}
|
||||
|
||||
func NewIssue(i *result.Issue, pass *analysis.Pass) Issue {
|
||||
func NewIssue(issue *result.Issue, pass *analysis.Pass) Issue {
|
||||
return Issue{
|
||||
Issue: *i,
|
||||
Issue: *issue,
|
||||
Pass: pass,
|
||||
}
|
||||
}
|
||||
|
@ -107,8 +107,8 @@ func (i UnusedCandidate) Details() string {
|
||||
|
||||
func (i UnusedCandidate) String() string { return toString(i) }
|
||||
|
||||
func toString(i Issue) string {
|
||||
return fmt.Sprintf("%s at %s", i.Details(), i.Position())
|
||||
func toString(issue Issue) string {
|
||||
return fmt.Sprintf("%s at %s", issue.Details(), issue.Position())
|
||||
}
|
||||
|
||||
type Issue interface {
|
||||
|
@ -52,15 +52,15 @@ func (p *Tab) Print(issues []result.Issue) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Tab) printIssue(i *result.Issue, w io.Writer) {
|
||||
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
||||
func (p *Tab) printIssue(issue *result.Issue, w io.Writer) {
|
||||
text := p.SprintfColored(color.FgRed, "%s", issue.Text)
|
||||
if p.printLinterName {
|
||||
text = fmt.Sprintf("%s\t%s", i.FromLinter, text)
|
||||
text = fmt.Sprintf("%s\t%s", issue.FromLinter, text)
|
||||
}
|
||||
|
||||
pos := p.SprintfColored(color.Bold, "%s:%d", i.FilePath(), i.Line())
|
||||
if i.Pos.Column != 0 {
|
||||
pos += fmt.Sprintf(":%d", i.Pos.Column)
|
||||
pos := p.SprintfColored(color.Bold, "%s:%d", issue.FilePath(), issue.Line())
|
||||
if issue.Pos.Column != 0 {
|
||||
pos += fmt.Sprintf(":%d", issue.Pos.Column)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%s\t%s\n", pos, text)
|
||||
|
@ -55,32 +55,32 @@ func (p *Text) Print(issues []result.Issue) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Text) printIssue(i *result.Issue) {
|
||||
text := p.SprintfColored(color.FgRed, "%s", strings.TrimSpace(i.Text))
|
||||
func (p *Text) printIssue(issue *result.Issue) {
|
||||
text := p.SprintfColored(color.FgRed, "%s", strings.TrimSpace(issue.Text))
|
||||
if p.printLinterName {
|
||||
text += fmt.Sprintf(" (%s)", i.FromLinter)
|
||||
text += fmt.Sprintf(" (%s)", issue.FromLinter)
|
||||
}
|
||||
pos := p.SprintfColored(color.Bold, "%s:%d", i.FilePath(), i.Line())
|
||||
if i.Pos.Column != 0 {
|
||||
pos += fmt.Sprintf(":%d", i.Pos.Column)
|
||||
pos := p.SprintfColored(color.Bold, "%s:%d", issue.FilePath(), issue.Line())
|
||||
if issue.Pos.Column != 0 {
|
||||
pos += fmt.Sprintf(":%d", issue.Pos.Column)
|
||||
}
|
||||
fmt.Fprintf(p.w, "%s: %s\n", pos, text)
|
||||
}
|
||||
|
||||
func (p *Text) printSourceCode(i *result.Issue) {
|
||||
for _, line := range i.SourceLines {
|
||||
func (p *Text) printSourceCode(issue *result.Issue) {
|
||||
for _, line := range issue.SourceLines {
|
||||
fmt.Fprintln(p.w, line)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Text) printUnderLinePointer(i *result.Issue) {
|
||||
func (p *Text) printUnderLinePointer(issue *result.Issue) {
|
||||
// if column == 0 it means column is unknown (e.g. for gosec)
|
||||
if len(i.SourceLines) != 1 || i.Pos.Column == 0 {
|
||||
if len(issue.SourceLines) != 1 || issue.Pos.Column == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
col0 := i.Pos.Column - 1
|
||||
line := i.SourceLines[0]
|
||||
col0 := issue.Pos.Column - 1
|
||||
line := issue.SourceLines[0]
|
||||
prefixRunes := make([]rune, 0, len(line))
|
||||
for j := 0; j < len(line) && j < col0; j++ {
|
||||
if line[j] == '\t' {
|
||||
|
@ -46,21 +46,21 @@ func isSpecialAutogeneratedFile(filePath string) bool {
|
||||
return filepath.Ext(fileName) != ".go"
|
||||
}
|
||||
|
||||
func (p *AutogeneratedExclude) shouldPassIssue(i *result.Issue) (bool, error) {
|
||||
if i.FromLinter == "typecheck" {
|
||||
func (p *AutogeneratedExclude) shouldPassIssue(issue *result.Issue) (bool, error) {
|
||||
if issue.FromLinter == "typecheck" {
|
||||
// don't hide typechecking errors in generated files: users expect to see why the project isn't compiling
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if filepath.Base(i.FilePath()) == "go.mod" {
|
||||
if filepath.Base(issue.FilePath()) == "go.mod" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if isSpecialAutogeneratedFile(i.FilePath()) {
|
||||
if isSpecialAutogeneratedFile(issue.FilePath()) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
fs, err := p.getOrCreateFileSummary(i)
|
||||
fs, err := p.getOrCreateFileSummary(issue)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -92,26 +92,26 @@ func isGeneratedFileByComment(doc string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *AutogeneratedExclude) getOrCreateFileSummary(i *result.Issue) (*ageFileSummary, error) {
|
||||
fs := p.fileSummaryCache[i.FilePath()]
|
||||
func (p *AutogeneratedExclude) getOrCreateFileSummary(issue *result.Issue) (*ageFileSummary, error) {
|
||||
fs := p.fileSummaryCache[issue.FilePath()]
|
||||
if fs != nil {
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
fs = &ageFileSummary{}
|
||||
p.fileSummaryCache[i.FilePath()] = fs
|
||||
p.fileSummaryCache[issue.FilePath()] = fs
|
||||
|
||||
if i.FilePath() == "" {
|
||||
if issue.FilePath() == "" {
|
||||
return nil, errors.New("no file path for issue")
|
||||
}
|
||||
|
||||
doc, err := getDoc(i.FilePath())
|
||||
doc, err := getDoc(issue.FilePath())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get doc of file %s: %w", i.FilePath(), err)
|
||||
return nil, fmt.Errorf("failed to get doc of file %s: %w", issue.FilePath(), err)
|
||||
}
|
||||
|
||||
fs.isGenerated = isGeneratedFileByComment(doc)
|
||||
autogenDebugf("file %q is generated: %t", i.FilePath(), fs.isGenerated)
|
||||
autogenDebugf("file %q is generated: %t", issue.FilePath(), fs.isGenerated)
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
|
@ -26,17 +26,17 @@ func (p Cgo) Name() string {
|
||||
}
|
||||
|
||||
func (p Cgo) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return filterIssuesErr(issues, func(i *result.Issue) (bool, error) {
|
||||
return filterIssuesErr(issues, func(issue *result.Issue) (bool, error) {
|
||||
// some linters (e.g. gosec, deadcode) return incorrect filepaths for cgo issues,
|
||||
// also cgo files have strange issues looking like false positives.
|
||||
|
||||
// cache dir contains all preprocessed files including cgo files
|
||||
|
||||
issueFilePath := i.FilePath()
|
||||
if !filepath.IsAbs(i.FilePath()) {
|
||||
absPath, err := filepath.Abs(i.FilePath())
|
||||
issueFilePath := issue.FilePath()
|
||||
if !filepath.IsAbs(issue.FilePath()) {
|
||||
absPath, err := filepath.Abs(issue.FilePath())
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to build abs path for %q: %w", i.FilePath(), err)
|
||||
return false, fmt.Errorf("failed to build abs path for %q: %w", issue.FilePath(), err)
|
||||
}
|
||||
issueFilePath = absPath
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (p Cgo) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if filepath.Base(i.FilePath()) == "_cgo_gotypes.go" {
|
||||
if filepath.Base(issue.FilePath()) == "_cgo_gotypes.go" {
|
||||
// skip cgo warning for go1.10
|
||||
return false, nil
|
||||
}
|
||||
|
@ -63,15 +63,15 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return nil, fmt.Errorf("can't prepare diff by revgrep: %w", err)
|
||||
}
|
||||
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
hunkPos, isNew := c.IsNewIssue(i)
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
hunkPos, isNew := c.IsNewIssue(issue)
|
||||
if !isNew {
|
||||
return nil
|
||||
}
|
||||
|
||||
newI := *i
|
||||
newI.HunkPos = hunkPos
|
||||
return &newI
|
||||
newIssue := *issue
|
||||
newIssue.HunkPos = hunkPos
|
||||
return &newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,8 @@ func (p Exclude) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
return !p.pattern.MatchString(i.Text)
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
return !p.pattern.MatchString(issue.Text)
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,10 @@ func (p ExcludeRules) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
if len(p.rules) == 0 {
|
||||
return issues, nil
|
||||
}
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
for _, rule := range p.rules {
|
||||
rule := rule
|
||||
if rule.match(i, p.files, p.log) {
|
||||
if rule.match(issue, p.files, p.log) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -102,29 +102,29 @@ func (p *FilenameUnadjuster) Name() string {
|
||||
}
|
||||
|
||||
func (p *FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
issueFilePath := i.FilePath()
|
||||
if !filepath.IsAbs(i.FilePath()) {
|
||||
absPath, err := filepath.Abs(i.FilePath())
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
issueFilePath := issue.FilePath()
|
||||
if !filepath.IsAbs(issue.FilePath()) {
|
||||
absPath, err := filepath.Abs(issue.FilePath())
|
||||
if err != nil {
|
||||
p.log.Warnf("failed to build abs path for %q: %s", i.FilePath(), err)
|
||||
return i
|
||||
p.log.Warnf("failed to build abs path for %q: %s", issue.FilePath(), err)
|
||||
return issue
|
||||
}
|
||||
issueFilePath = absPath
|
||||
}
|
||||
|
||||
mapper := p.m[issueFilePath]
|
||||
if mapper == nil {
|
||||
return i
|
||||
return issue
|
||||
}
|
||||
|
||||
newI := *i
|
||||
newI.Pos = mapper(i.Pos)
|
||||
if !p.loggedUnadjustments[i.Pos.Filename] {
|
||||
p.log.Infof("Unadjusted from %v to %v", i.Pos, newI.Pos)
|
||||
p.loggedUnadjustments[i.Pos.Filename] = true
|
||||
newIssue := *issue
|
||||
newIssue.Pos = mapper(issue.Pos)
|
||||
if !p.loggedUnadjustments[issue.Pos.Filename] {
|
||||
p.log.Infof("Unadjusted from %v to %v", issue.Pos, newIssue.Pos)
|
||||
p.loggedUnadjustments[issue.Pos.Filename] = true
|
||||
}
|
||||
return &newI
|
||||
return &newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -101,10 +101,10 @@ func NewIdentifierMarker() *IdentifierMarker {
|
||||
}
|
||||
|
||||
func (im IdentifierMarker) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
iCopy := *i
|
||||
iCopy.Text = im.markIdentifiers(iCopy.Text)
|
||||
return &iCopy
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
newIssue := *issue
|
||||
newIssue.Text = im.markIdentifiers(newIssue.Text)
|
||||
return &newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
|
||||
func filterIssues(issues []result.Issue, filter func(i *result.Issue) bool) []result.Issue {
|
||||
func filterIssues(issues []result.Issue, filter func(issue *result.Issue) bool) []result.Issue {
|
||||
retIssues := make([]result.Issue, 0, len(issues))
|
||||
for i := range issues {
|
||||
if filter(&issues[i]) {
|
||||
@ -17,7 +17,7 @@ func filterIssues(issues []result.Issue, filter func(i *result.Issue) bool) []re
|
||||
return retIssues
|
||||
}
|
||||
|
||||
func filterIssuesErr(issues []result.Issue, filter func(i *result.Issue) (bool, error)) ([]result.Issue, error) {
|
||||
func filterIssuesErr(issues []result.Issue, filter func(issue *result.Issue) (bool, error)) ([]result.Issue, error) {
|
||||
retIssues := make([]result.Issue, 0, len(issues))
|
||||
for i := range issues {
|
||||
ok, err := filter(&issues[i])
|
||||
@ -33,12 +33,12 @@ func filterIssuesErr(issues []result.Issue, filter func(i *result.Issue) (bool,
|
||||
return retIssues, nil
|
||||
}
|
||||
|
||||
func transformIssues(issues []result.Issue, transform func(i *result.Issue) *result.Issue) []result.Issue {
|
||||
func transformIssues(issues []result.Issue, transform func(issue *result.Issue) *result.Issue) []result.Issue {
|
||||
retIssues := make([]result.Issue, 0, len(issues))
|
||||
for i := range issues {
|
||||
newI := transform(&issues[i])
|
||||
if newI != nil {
|
||||
retIssues = append(retIssues, *newI)
|
||||
newIssue := transform(&issues[i])
|
||||
if newIssue != nil {
|
||||
retIssues = append(retIssues, *newIssue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,14 +33,14 @@ func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
if i.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
if issue.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
// we need to fix all issues at once => we need to return all of them
|
||||
return true
|
||||
}
|
||||
|
||||
p.lc[i.FromLinter]++ // always inc for stat
|
||||
return p.lc[i.FromLinter] <= p.limit
|
||||
p.lc[issue.FromLinter]++ // always inc for stat
|
||||
return p.lc[issue.FromLinter] <= p.limit
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -36,22 +36,22 @@ func (p *MaxPerFileFromLinter) Name() string {
|
||||
}
|
||||
|
||||
func (p *MaxPerFileFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
limit := p.maxPerFileFromLinterConfig[i.FromLinter]
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
limit := p.maxPerFileFromLinterConfig[issue.FromLinter]
|
||||
if limit == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
lm := p.flc[i.FilePath()]
|
||||
lm := p.flc[issue.FilePath()]
|
||||
if lm == nil {
|
||||
p.flc[i.FilePath()] = linterToCountMap{}
|
||||
p.flc[issue.FilePath()] = linterToCountMap{}
|
||||
}
|
||||
count := p.flc[i.FilePath()][i.FromLinter]
|
||||
count := p.flc[issue.FilePath()][issue.FromLinter]
|
||||
if count >= limit {
|
||||
return false
|
||||
}
|
||||
|
||||
p.flc[i.FilePath()][i.FromLinter]++
|
||||
p.flc[issue.FilePath()][issue.FromLinter]++
|
||||
return true
|
||||
}), nil
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
if i.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
if issue.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
// we need to fix all issues at once => we need to return all of them
|
||||
return true
|
||||
}
|
||||
|
||||
p.tc[i.Text]++ // always inc for stat
|
||||
return p.tc[i.Text] <= p.limit
|
||||
p.tc[issue.Text]++ // always inc for stat
|
||||
return p.tc[issue.Text] <= p.limit
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -97,16 +97,16 @@ func (p *Nolint) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return filterIssuesErr(issues, p.shouldPassIssue)
|
||||
}
|
||||
|
||||
func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
|
||||
fd := p.cache[i.FilePath()]
|
||||
func (p *Nolint) getOrCreateFileData(issue *result.Issue) (*fileData, error) {
|
||||
fd := p.cache[issue.FilePath()]
|
||||
if fd != nil {
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
fd = &fileData{}
|
||||
p.cache[i.FilePath()] = fd
|
||||
p.cache[issue.FilePath()] = fd
|
||||
|
||||
if i.FilePath() == "" {
|
||||
if issue.FilePath() == "" {
|
||||
return nil, errors.New("no file path for issue")
|
||||
}
|
||||
|
||||
@ -115,14 +115,14 @@ func (p *Nolint) getOrCreateFileData(i *result.Issue) (*fileData, error) {
|
||||
|
||||
// Don't use cached AST because they consume a lot of memory on large projects.
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, i.FilePath(), nil, parser.ParseComments)
|
||||
f, err := parser.ParseFile(fset, issue.FilePath(), nil, parser.ParseComments)
|
||||
if err != nil {
|
||||
// Don't report error because it's already must be reporter by typecheck or go/analysis.
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
fd.ignoredRanges = p.buildIgnoredRangesForFile(f, fset, i.FilePath())
|
||||
nolintDebugf("file %s: built nolint ranges are %+v", i.FilePath(), fd.ignoredRanges)
|
||||
fd.ignoredRanges = p.buildIgnoredRangesForFile(f, fset, issue.FilePath())
|
||||
nolintDebugf("file %s: built nolint ranges are %+v", issue.FilePath(), fd.ignoredRanges)
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
@ -148,28 +148,28 @@ func (p *Nolint) buildIgnoredRangesForFile(f *ast.File, fset *token.FileSet, fil
|
||||
return allRanges
|
||||
}
|
||||
|
||||
func (p *Nolint) shouldPassIssue(i *result.Issue) (bool, error) {
|
||||
nolintDebugf("got issue: %v", *i)
|
||||
if i.FromLinter == golinters.NoLintLintName && i.ExpectNoLint && i.ExpectedNoLintLinter != "" {
|
||||
func (p *Nolint) shouldPassIssue(issue *result.Issue) (bool, error) {
|
||||
nolintDebugf("got issue: %v", *issue)
|
||||
if issue.FromLinter == golinters.NoLintLintName && issue.ExpectNoLint && issue.ExpectedNoLintLinter != "" {
|
||||
// don't expect disabled linters to cover their nolint statements
|
||||
nolintDebugf("enabled linters: %v", p.enabledLinters)
|
||||
if p.enabledLinters[i.ExpectedNoLintLinter] == nil {
|
||||
if p.enabledLinters[issue.ExpectedNoLintLinter] == nil {
|
||||
return false, nil
|
||||
}
|
||||
nolintDebugf("checking that lint issue was used for %s: %v", i.ExpectedNoLintLinter, i)
|
||||
nolintDebugf("checking that lint issue was used for %s: %v", issue.ExpectedNoLintLinter, issue)
|
||||
}
|
||||
|
||||
fd, err := p.getOrCreateFileData(i)
|
||||
fd, err := p.getOrCreateFileData(issue)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, ir := range fd.ignoredRanges {
|
||||
if ir.doesMatch(i) {
|
||||
nolintDebugf("found ignored range for issue %v: %v", i, ir)
|
||||
ir.matchedIssueFromLinter[i.FromLinter] = true
|
||||
if ir.doesMatch(issue) {
|
||||
nolintDebugf("found ignored range for issue %v: %v", issue, ir)
|
||||
ir.matchedIssueFromLinter[issue.FromLinter] = true
|
||||
if ir.originalRange != nil {
|
||||
ir.originalRange.matchedIssueFromLinter[i.FromLinter] = true
|
||||
ir.originalRange.matchedIssueFromLinter[issue.FromLinter] = true
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
@ -29,19 +29,19 @@ func (p PathPrettifier) Name() string {
|
||||
}
|
||||
|
||||
func (p PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
if !filepath.IsAbs(i.FilePath()) {
|
||||
return i
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
if !filepath.IsAbs(issue.FilePath()) {
|
||||
return issue
|
||||
}
|
||||
|
||||
rel, err := fsutils.ShortestRelPath(i.FilePath(), "")
|
||||
rel, err := fsutils.ShortestRelPath(issue.FilePath(), "")
|
||||
if err != nil {
|
||||
return i
|
||||
return issue
|
||||
}
|
||||
|
||||
newI := i
|
||||
newI.Pos.Filename = rel
|
||||
return newI
|
||||
newIssue := issue
|
||||
newIssue.Pos.Filename = rel
|
||||
return newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,11 @@ func (p PathShortener) Name() string {
|
||||
}
|
||||
|
||||
func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
newI := i
|
||||
newI.Text = strings.ReplaceAll(newI.Text, p.wd+"/", "")
|
||||
newI.Text = strings.ReplaceAll(newI.Text, p.wd, "")
|
||||
return newI
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
newIssue := issue
|
||||
newIssue.Text = strings.ReplaceAll(newIssue.Text, p.wd+"/", "")
|
||||
newIssue.Text = strings.ReplaceAll(newIssue.Text, p.wd, "")
|
||||
return newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
if i.Severity != "" && !p.override {
|
||||
return i
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
if issue.Severity != "" && !p.override {
|
||||
return issue
|
||||
}
|
||||
|
||||
for _, rule := range p.rules {
|
||||
@ -77,15 +77,15 @@ func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
ruleSeverity = rule.severity
|
||||
}
|
||||
|
||||
if rule.match(i, p.files, p.log) {
|
||||
i.Severity = ruleSeverity
|
||||
return i
|
||||
if rule.match(issue, p.files, p.log) {
|
||||
issue.Severity = ruleSeverity
|
||||
return issue
|
||||
}
|
||||
}
|
||||
|
||||
i.Severity = p.defaultSeverity
|
||||
issue.Severity = p.defaultSeverity
|
||||
|
||||
return i
|
||||
return issue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -79,15 +79,15 @@ func (p *SkipDirs) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return filterIssues(issues, p.shouldPassIssue), nil
|
||||
}
|
||||
|
||||
func (p *SkipDirs) shouldPassIssue(i *result.Issue) bool {
|
||||
if filepath.IsAbs(i.FilePath()) {
|
||||
if !isSpecialAutogeneratedFile(i.FilePath()) {
|
||||
p.log.Warnf("Got abs path %s in skip dirs processor, it should be relative", i.FilePath())
|
||||
func (p *SkipDirs) shouldPassIssue(issue *result.Issue) bool {
|
||||
if filepath.IsAbs(issue.FilePath()) {
|
||||
if !isSpecialAutogeneratedFile(issue.FilePath()) {
|
||||
p.log.Warnf("Got abs path %s in skip dirs processor, it should be relative", issue.FilePath())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
issueRelDir := filepath.Dir(i.FilePath())
|
||||
issueRelDir := filepath.Dir(issue.FilePath())
|
||||
|
||||
if toPass, ok := p.skippedDirsCache[issueRelDir]; ok {
|
||||
if !toPass {
|
||||
|
@ -41,8 +41,8 @@ func (p SkipFiles) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
path := fsutils.WithPathPrefix(p.pathPrefix, i.FilePath())
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
path := fsutils.WithPathPrefix(p.pathPrefix, issue.FilePath())
|
||||
for _, pattern := range p.patterns {
|
||||
if pattern.MatchString(path) {
|
||||
return false
|
||||
|
@ -25,22 +25,22 @@ func (p SourceCode) Name() string {
|
||||
}
|
||||
|
||||
func (p SourceCode) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||
newI := *i
|
||||
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
|
||||
newIssue := *issue
|
||||
|
||||
lineRange := i.GetLineRange()
|
||||
lineRange := issue.GetLineRange()
|
||||
for lineNumber := lineRange.From; lineNumber <= lineRange.To; lineNumber++ {
|
||||
line, err := p.lineCache.GetLine(i.FilePath(), lineNumber)
|
||||
line, err := p.lineCache.GetLine(issue.FilePath(), lineNumber)
|
||||
if err != nil {
|
||||
p.log.Warnf("Failed to get line %d for file %s: %s",
|
||||
lineNumber, i.FilePath(), err)
|
||||
return i
|
||||
lineNumber, issue.FilePath(), err)
|
||||
return issue
|
||||
}
|
||||
|
||||
newI.SourceLines = append(newI.SourceLines, line)
|
||||
newIssue.SourceLines = append(newIssue.SourceLines, line)
|
||||
}
|
||||
|
||||
return &newI
|
||||
return &newIssue
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
@ -31,26 +31,26 @@ func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
return filterIssues(issues, func(i *result.Issue) bool {
|
||||
if i.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
return filterIssues(issues, func(issue *result.Issue) bool {
|
||||
if issue.Replacement != nil && p.cfg.Issues.NeedFix {
|
||||
// if issue will be auto-fixed we shouldn't collapse issues:
|
||||
// e.g. one line can contain 2 misspellings, they will be in 2 issues and misspell should fix both of them.
|
||||
return true
|
||||
}
|
||||
|
||||
lc := p.flc[i.FilePath()]
|
||||
lc := p.flc[issue.FilePath()]
|
||||
if lc == nil {
|
||||
lc = lineToCount{}
|
||||
p.flc[i.FilePath()] = lc
|
||||
p.flc[issue.FilePath()] = lc
|
||||
}
|
||||
|
||||
const limit = 1
|
||||
count := lc[i.Line()]
|
||||
count := lc[issue.Line()]
|
||||
if count == limit {
|
||||
return false
|
||||
}
|
||||
|
||||
lc[i.Line()]++
|
||||
lc[issue.Line()]++
|
||||
return true
|
||||
}), nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user