descriptormarshal

package
v0.0.0-...-1dc08c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

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

Doc documents this pass.

Variables

View Source
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() != sqlbasePkg || 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 sqlbase.Descriptor.GetTable() except where appropriate.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL