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.15 6// +build go1.15 7 8package hooks 9 10import ( 11 "golang.org/x/tools/internal/lsp/protocol" 12 "golang.org/x/tools/internal/lsp/source" 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 20func updateAnalyzers(options *source.Options) { 21 mapSeverity := func(severity lint.Severity) protocol.DiagnosticSeverity { 22 switch severity { 23 case lint.SeverityError: 24 return protocol.SeverityError 25 case lint.SeverityDeprecated: 26 // TODO(dh): in LSP, deprecated is a tag, not a severity. 27 // We'll want to support this once we enable SA5011. 28 return protocol.SeverityWarning 29 case lint.SeverityWarning: 30 return protocol.SeverityWarning 31 case lint.SeverityInfo: 32 return protocol.SeverityInformation 33 case lint.SeverityHint: 34 return protocol.SeverityHint 35 default: 36 return protocol.SeverityWarning 37 } 38 } 39 add := func(analyzers []*lint.Analyzer, skip map[string]struct{}) { 40 for _, a := range analyzers { 41 if _, ok := skip[a.Analyzer.Name]; ok { 42 continue 43 } 44 45 enabled := !a.Doc.NonDefault 46 options.AddStaticcheckAnalyzer(a.Analyzer, enabled, mapSeverity(a.Doc.Severity)) 47 } 48 } 49 50 add(simple.Analyzers, nil) 51 add(staticcheck.Analyzers, map[string]struct{}{ 52 // This check conflicts with the vet printf check (golang/go#34494). 53 "SA5009": {}, 54 // This check relies on facts from dependencies, which 55 // we don't currently compute. 56 "SA5011": {}, 57 }) 58 add(stylecheck.Analyzers, nil) 59 add(quickfix.Analyzers, nil) 60} 61