cockroach: github.com/cockroachdb/cockroach/pkg/testutils/lint/passes/descriptormarshal Index | Files

package descriptormarshal

import "github.com/cockroachdb/cockroach/pkg/testutils/lint/passes/descriptormarshal"

Package descriptormarshal defines an suite of Analyzers that detects correct setting of timestamps when unmarshaling table descriptors.

Index

Package Files

descriptor_marshal.go

Constants

const Doc = `check for correct unmarshaling of sqlbase descriptors`

Doc documents this pass.

Variables

var Analyzer = &analysis.Analyzer{
    Name:     "descriptormarshal",
    Doc:      Doc,
    Requires: []*analysis.Analyzer{inspect.Analyzer},
    Run: func(pass *analysis.Pass) (interface{}, error) {
        inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
        inspect.Preorder([]ast.Node{
            (*ast.CallExpr)(nil),
        }, func(n ast.Node) {
            call := n.(*ast.CallExpr)
            sel, ok := call.Fun.(*ast.SelectorExpr)
            if !ok {
                return
            }
            obj, ok := pass.TypesInfo.Uses[sel.Sel]
            if !ok {
                return
            }
            f, ok := obj.(*types.Func)
            if !ok {
                return
            }
            if f.Pkg() == nil || f.Pkg().Path() != descpbPkg || f.Name() != "GetTable" {
                return
            }
            if !isMethodForNamedType(f, "Descriptor") {
                return
            }
            containing := findContainingFunc(pass, n)
            if isAllowed(containing) {
                return
            }
            pass.Report(analysis.Diagnostic{
                Pos: n.Pos(),
                Message: fmt.Sprintf("Illegal call to Descriptor.GetTable() in %s, see Descriptor.Table()",
                    containing.Name()),
            })
        })
        return nil, nil
    },
}

Analyzer is a linter that ensures there are no calls to descpb.Descriptor.GetTable() except where appropriate.

Package descriptormarshal imports 7 packages (graph) and is imported by 1 packages. Updated 2020-08-12. Refresh now. Tools for package owners.