github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/pkg/golinters/nxboundary.go (about)

     1  package golinters
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/vanstinator/nxboundary"
     8  	"golang.org/x/tools/go/analysis"
     9  
    10  	"github.com/vanstinator/golangci-lint/pkg/config"
    11  	"github.com/vanstinator/golangci-lint/pkg/golinters/goanalysis"
    12  	"github.com/vanstinator/golangci-lint/pkg/lint/linter"
    13  )
    14  
    15  func NewNxBoundary(settings *config.NxBoundarySettings) *goanalysis.Linter {
    16  	analyzer := nxboundary.NewAnalyzer()
    17  
    18  	return goanalysis.NewLinter(
    19  		analyzer.Name,
    20  		analyzer.Doc,
    21  		[]*analysis.Analyzer{analyzer},
    22  		nil,
    23  	).WithContextSetter(func(lintCtx *linter.Context) {
    24  		if settings == nil {
    25  			return
    26  		}
    27  		if len(settings.AllowedTags) == 0 {
    28  			lintCtx.Log.Infof("nxboundary settings found, but no allowedTags listed. List aliases under alias: key.") //nolint:misspell
    29  		}
    30  
    31  		for key, value := range settings.AllowedTags {
    32  			err := analyzer.Flags.Set("allowedTags", fmt.Sprintf("%s|%s", key, strings.Join(value, ",")))
    33  			if err != nil {
    34  				lintCtx.Log.Errorf("failed to parse configuration: %v", err)
    35  			}
    36  		}
    37  	}).WithLoadMode(goanalysis.LoadModeSyntax)
    38  }