github.com/alecthomas/golangci-lint@v1.4.2-0.20180609094924-581a3564ff68/pkg/golinters/ineffassign.go (about)

     1  package golinters
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/golangci/golangci-lint/pkg/lint/linter"
     8  	"github.com/golangci/golangci-lint/pkg/result"
     9  	ineffassignAPI "github.com/golangci/ineffassign"
    10  )
    11  
    12  type Ineffassign struct{}
    13  
    14  func (Ineffassign) Name() string {
    15  	return "ineffassign"
    16  }
    17  
    18  func (Ineffassign) Desc() string {
    19  	return "Detects when assignments to existing variables are not used"
    20  }
    21  
    22  func (lint Ineffassign) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
    23  	issues := ineffassignAPI.Run(lintCtx.Paths.Files)
    24  	if len(issues) == 0 {
    25  		return nil, nil
    26  	}
    27  
    28  	res := make([]result.Issue, 0, len(issues))
    29  	for _, i := range issues {
    30  		res = append(res, result.Issue{
    31  			Pos:        i.Pos,
    32  			Text:       fmt.Sprintf("ineffectual assignment to %s", formatCode(i.IdentName, lintCtx.Cfg)),
    33  			FromLinter: lint.Name(),
    34  		})
    35  	}
    36  	return res, nil
    37  }