-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
analyzers.go
50 lines (43 loc) · 1.91 KB
/
analyzers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2019 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
// Package forbiddenmethod defines an suite of Analyzers that
// detects correct setting of timestamps when unmarshaling table
// descriptors.
package forbiddenmethod
import "golang.org/x/tools/go/analysis"
var descriptorMarshalOptions = Options{
PassName: "descriptormarshal",
Doc: `check for correct unmarshaling of descpb descriptors`,
Package: "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb",
Type: "Descriptor",
Method: "GetTable",
Hint: "see descpb.TableFromDescriptor()",
}
var grpcClientConnCloseOptions = Options{
PassName: "grpcconnclose",
Doc: `prevent calls to (grpc.ClientConn).Close`,
Package: "google.golang.org/grpc",
Type: "ClientConn",
Method: "Close",
Hint: "must elide the call to Close() if the ClientConn is from an *rpc.Context. " +
"Do `grpcConn.Close() // nolint:grpcconnclose` when the conn does not come from an rpc.Context.",
}
// DescriptorMarshalAnalyzer checks for correct unmarshaling of descpb
// descriptors by disallowing calls to (descpb.Descriptor).GetTable().
var DescriptorMarshalAnalyzer = Analyzer(descriptorMarshalOptions)
// GRPCClientConnCloseAnalyzer checks for calls to (*grpc.ClientConn).Close.
// We mostly pull these objects from *rpc.Context, which manages their lifecycle.
// Errant calls to Close() disrupt the connection for all users.
var GRPCClientConnCloseAnalyzer = Analyzer(grpcClientConnCloseOptions)
// Analyzers are all of the Analyzers defined in this package.
var Analyzers = []*analysis.Analyzer{
DescriptorMarshalAnalyzer,
GRPCClientConnCloseAnalyzer,
}