Skip to content

Commit

Permalink
dev: rename function parameter i to issue (#4460)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Mar 5, 2024
1 parent f18e6c3 commit 808c06d
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 145 deletions.
4 changes: 2 additions & 2 deletions pkg/golinters/goanalysis/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/golinters/nolintlint/nolintlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/printers/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions pkg/printers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down
24 changes: 12 additions & 12 deletions pkg/result/processors/autogenerated_exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/result/processors/cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/result/processors/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/result/processors/exclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/result/processors/exclude_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/result/processors/filename_unadjuster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/result/processors/identifier_marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/result/processors/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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])
Expand All @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/result/processors/max_from_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/result/processors/max_per_file_from_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/result/processors/max_same_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 808c06d

Please sign in to comment.