golang.org/x/tools/gopls@v0.15.3/internal/hooks/analysis_120.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.20
     6  // +build go1.20
     7  
     8  package hooks
     9  
    10  import (
    11  	"golang.org/x/tools/gopls/internal/protocol"
    12  	"golang.org/x/tools/gopls/internal/settings"
    13  	"honnef.co/go/tools/analysis/lint"
    14  	"honnef.co/go/tools/quickfix"
    15  	"honnef.co/go/tools/simple"
    16  	"honnef.co/go/tools/staticcheck"
    17  	"honnef.co/go/tools/stylecheck"
    18  )
    19  
    20  func updateAnalyzers(options *settings.Options) {
    21  	options.StaticcheckSupported = true
    22  
    23  	mapSeverity := func(severity lint.Severity) protocol.DiagnosticSeverity {
    24  		switch severity {
    25  		case lint.SeverityError:
    26  			return protocol.SeverityError
    27  		case lint.SeverityDeprecated:
    28  			// TODO(dh): in LSP, deprecated is a tag, not a severity.
    29  			//   We'll want to support this once we enable SA5011.
    30  			return protocol.SeverityWarning
    31  		case lint.SeverityWarning:
    32  			return protocol.SeverityWarning
    33  		case lint.SeverityInfo:
    34  			return protocol.SeverityInformation
    35  		case lint.SeverityHint:
    36  			return protocol.SeverityHint
    37  		default:
    38  			return protocol.SeverityWarning
    39  		}
    40  	}
    41  	add := func(analyzers []*lint.Analyzer, skip map[string]struct{}) {
    42  		for _, a := range analyzers {
    43  			if _, ok := skip[a.Analyzer.Name]; ok {
    44  				continue
    45  			}
    46  
    47  			enabled := !a.Doc.NonDefault
    48  			options.AddStaticcheckAnalyzer(a.Analyzer, enabled, mapSeverity(a.Doc.Severity))
    49  		}
    50  	}
    51  
    52  	add(simple.Analyzers, nil)
    53  	add(staticcheck.Analyzers, map[string]struct{}{
    54  		// This check conflicts with the vet printf check (golang/go#34494).
    55  		"SA5009": {},
    56  		// This check relies on facts from dependencies, which
    57  		// we don't currently compute.
    58  		"SA5011": {},
    59  	})
    60  	add(stylecheck.Analyzers, nil)
    61  	add(quickfix.Analyzers, nil)
    62  }