github.com/ferretdb/golangci-lint@v1.10.1/pkg/golinters/interfacer.go (about)

     1  package golinters
     2  
     3  import (
     4  	"context"
     5  
     6  	"mvdan.cc/interfacer/check"
     7  
     8  	"github.com/golangci/golangci-lint/pkg/lint/linter"
     9  	"github.com/golangci/golangci-lint/pkg/result"
    10  )
    11  
    12  type Interfacer struct{}
    13  
    14  func (Interfacer) Name() string {
    15  	return "interfacer"
    16  }
    17  
    18  func (Interfacer) Desc() string {
    19  	return "Linter that suggests narrower interface types"
    20  }
    21  
    22  func (lint Interfacer) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
    23  	c := new(check.Checker)
    24  	c.Program(lintCtx.Program)
    25  	c.ProgramSSA(lintCtx.SSAProgram)
    26  
    27  	issues, err := c.Check()
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	if len(issues) == 0 {
    32  		return nil, nil
    33  	}
    34  
    35  	res := make([]result.Issue, 0, len(issues))
    36  	for _, i := range issues {
    37  		pos := lintCtx.SSAProgram.Fset.Position(i.Pos())
    38  		res = append(res, result.Issue{
    39  			Pos:        pos,
    40  			Text:       markIdentifiers(i.Message()),
    41  			FromLinter: lint.Name(),
    42  		})
    43  	}
    44  
    45  	return res, nil
    46  }