github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/golinters/util.go (about)

     1  package golinters
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"golang.org/x/tools/go/analysis"
     9  
    10  	"github.com/golangci/golangci-lint/pkg/config"
    11  )
    12  
    13  func formatCode(code string, _ *config.Config) string {
    14  	if strings.Contains(code, "`") {
    15  		return code // TODO: properly escape or remove
    16  	}
    17  
    18  	return fmt.Sprintf("`%s`", code)
    19  }
    20  
    21  func formatCodeBlock(code string, _ *config.Config) string {
    22  	if strings.Contains(code, "`") {
    23  		return code // TODO: properly escape or remove
    24  	}
    25  
    26  	return fmt.Sprintf("```\n%s\n```", code)
    27  }
    28  
    29  func getFileNames(pass *analysis.Pass) []string {
    30  	var fileNames []string
    31  	for _, f := range pass.Files {
    32  		fileName := pass.Fset.PositionFor(f.Pos(), true).Filename
    33  		ext := filepath.Ext(fileName)
    34  		if ext != "" && ext != ".go" {
    35  			// position has been adjusted to a non-go file, revert to original file
    36  			fileName = pass.Fset.PositionFor(f.Pos(), false).Filename
    37  		}
    38  		fileNames = append(fileNames, fileName)
    39  	}
    40  	return fileNames
    41  }