 bf27481efd
			
		
	
	
		bf27481efd
		
			
		
	
	
	
	
		
			
			full diff: https://github.com/dominikh/go-tools/compare/2019.2.3...2020.1.3 Also updates tests to accomodate updated rules: --- FAIL: TestSourcesFromTestdataWithIssuesDir/staticcheck.go (0.43s) linters_test.go:137: [run --disable-all --print-issued-lines=false --print-linter-name=false --out-format=line-number --max-same-issues=10 -Estaticcheck --no-config testdata/staticcheck.go] linters_test.go:33: Error Trace: linters_test.go:33 linters_test.go:138 linters_test.go:53 Error: Received unexpected error: staticcheck.go:11: no match for `self-assignment of x to x` vs ["SA4006: this value of `x` is never used"] in: staticcheck.go:11:2: SA4006: this value of `x` is never used unmatched errors staticcheck.go:11:2: SA4006: this value of `x` is never used Test: TestSourcesFromTestdataWithIssuesDir/staticcheck.go Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
		
			
				
	
	
		
			90 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2013 The Go Authors. All rights reserved.
 | |
| // Use of this source code is governed by a BSD-style
 | |
| // license that can be found in the LICENSE file.
 | |
| 
 | |
| package ir
 | |
| 
 | |
| // This file defines a number of miscellaneous utility functions.
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"go/ast"
 | |
| 	"go/token"
 | |
| 	"go/types"
 | |
| 	"io"
 | |
| 	"os"
 | |
| 
 | |
| 	"golang.org/x/tools/go/ast/astutil"
 | |
| )
 | |
| 
 | |
| //// AST utilities
 | |
| 
 | |
| func unparen(e ast.Expr) ast.Expr { return astutil.Unparen(e) }
 | |
| 
 | |
| // isBlankIdent returns true iff e is an Ident with name "_".
 | |
| // They have no associated types.Object, and thus no type.
 | |
| //
 | |
| func isBlankIdent(e ast.Expr) bool {
 | |
| 	id, ok := e.(*ast.Ident)
 | |
| 	return ok && id.Name == "_"
 | |
| }
 | |
| 
 | |
| //// Type utilities.  Some of these belong in go/types.
 | |
| 
 | |
| // isPointer returns true for types whose underlying type is a pointer.
 | |
| func isPointer(typ types.Type) bool {
 | |
| 	_, ok := typ.Underlying().(*types.Pointer)
 | |
| 	return ok
 | |
| }
 | |
| 
 | |
| func isInterface(T types.Type) bool { return types.IsInterface(T) }
 | |
| 
 | |
| // deref returns a pointer's element type; otherwise it returns typ.
 | |
| func deref(typ types.Type) types.Type {
 | |
| 	if p, ok := typ.Underlying().(*types.Pointer); ok {
 | |
| 		return p.Elem()
 | |
| 	}
 | |
| 	return typ
 | |
| }
 | |
| 
 | |
| // recvType returns the receiver type of method obj.
 | |
| func recvType(obj *types.Func) types.Type {
 | |
| 	return obj.Type().(*types.Signature).Recv().Type()
 | |
| }
 | |
| 
 | |
| // logStack prints the formatted "start" message to stderr and
 | |
| // returns a closure that prints the corresponding "end" message.
 | |
| // Call using 'defer logStack(...)()' to show builder stack on panic.
 | |
| // Don't forget trailing parens!
 | |
| //
 | |
| func logStack(format string, args ...interface{}) func() {
 | |
| 	msg := fmt.Sprintf(format, args...)
 | |
| 	io.WriteString(os.Stderr, msg)
 | |
| 	io.WriteString(os.Stderr, "\n")
 | |
| 	return func() {
 | |
| 		io.WriteString(os.Stderr, msg)
 | |
| 		io.WriteString(os.Stderr, " end\n")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // newVar creates a 'var' for use in a types.Tuple.
 | |
| func newVar(name string, typ types.Type) *types.Var {
 | |
| 	return types.NewParam(token.NoPos, nil, name, typ)
 | |
| }
 | |
| 
 | |
| // anonVar creates an anonymous 'var' for use in a types.Tuple.
 | |
| func anonVar(typ types.Type) *types.Var {
 | |
| 	return newVar("", typ)
 | |
| }
 | |
| 
 | |
| var lenResults = types.NewTuple(anonVar(tInt))
 | |
| 
 | |
| // makeLen returns the len builtin specialized to type func(T)int.
 | |
| func makeLen(T types.Type) *Builtin {
 | |
| 	lenParams := types.NewTuple(anonVar(T))
 | |
| 	return &Builtin{
 | |
| 		name: "len",
 | |
| 		sig:  types.NewSignature(nil, lenParams, lenResults, false),
 | |
| 	}
 | |
| }
 |