Giter VIP home page Giter VIP logo

dogsled's Introduction

dogsled Build Status

dogsled is a Go static analysis tool to find assignments/declarations with too many blank identifiers (e.g. x, _, _, _ := f()). Its name was inspired from this reddit post.

Installation

go get -u github.com/alexkohler/dogsled/cmd/dogsled

Usage

Similar to other Go static analysis tools (such as golint, go vet), dogsled can be invoked with one or more filenames, directories, or packages named by its import path. dogsled also supports the ... wildcard. By default, it will search for assignment with more than two blank identifiers.

dogsled [flags] files/directories/packages

Flags

  • -tests (default true) - Include test files in analysis
  • -n (default 2) - Maximum number of blank identifiers allowed in an assignment statement
  • -set_exit_status (default false) - Set exit status to 1 if any issues are found

Example

Some examples from the Go standard library

$ dogsled go/src/...
go/src/crypto/elliptic/elliptic_test.go:553: declaration has 3 blank identifiers: priv, _, _, _ := GenerateKey(p256,go/src/image/names.go:46: declaration has 3 blank identifiers: _, _, _, a := c.C.RGBA()
go/src/image/color/color.go:232: declaration has 3 blank identifiers: _, _, _, a := c.RGBA()
go/src/image/color/color.go:240: declaration has 3 blank identifiers: _, _, _, a := c.RGBA()
go/src/internal/cpu/cpu_x86.go:67: declaration has 3 blank identifiers: maxID, _, _, _ := cpuid(0, 0)
go/src/internal/cpu/cpu_x86.go:100: declaration has 3 blank identifiers: _, ebx7, _, _ := cpuid(7, 0)
go/src/math/big/natconv_test.go:286: declaration has 3 blank identifiers: x, _, _, _ = x.scan(strings.NewReader(pi),go/src/reflect/value.go:172: declaration has 3 blank identifiers: pc, _, _, _ := runtime.Caller(2)
go/src/reflect/makefunc.go:62: declaration has 4 blank identifiers: _, _, _, stack, _ := funcLayout(t, nil)
go/src/reflect/makefunc.go:113: declaration has 4 blank identifiers: _, _, _, stack, _ := funcLayout(funcType, nil)
go/src/runtime/softfloat64.go:309: declaration has 4 blank identifiers: _, _, _, _ = fi, fn, gi, gn
go/src/runtime/symtab_test.go:54: declaration has 3 blank identifiers: _, _, line, _ := runtime.Caller(1)
go/src/syscall/syscall_unix_test.go:182: declaration has 3 blank identifiers: _, oobn, _, _, err := uc.ReadMsgUnixgo/src/time/time.go:498: declaration has 3 blank identifiers: year, _, _, _ := t.date(false)
go/src/time/time.go:504: declaration has 3 blank identifiers: _, month, _, _ := t.date(true)
go/src/time/time.go:510: declaration has 3 blank identifiers: _, _, day, _ := t.date(true)
go/src/time/time.go:624: declaration has 3 blank identifiers: _, _, _, yday := t.date(false)

Contributing

Please open an issue and/or a PR for any features/bugs.

Other static analysis tools

If you've enjoyed dogsled, take a look at my other static anaylsis tools!

  • prealloc - Finds slice declarations that could potentially be preallocated.
  • nakedret - Finds naked returns.
  • identypo - Finds typos in variable names, function names, constants, and more!
  • unimport - Finds unnecessary import aliases.

dogsled's People

Contributors

alexkohler avatar bcicen avatar brackendawson avatar ericcornelissen avatar ping-localhost avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dogsled's Issues

unavoidable dogsled for functions outside your control

It's unclear to me how you're supposed to fix this linter error when you're calling a function you don't control, for example, the standard library. The following gives a path to the file of the calling code:

_, self, _, _ := runtime.Caller(0)

I can't edit the runtime package.

Presumably, the intention of this linter is to warn when people have written functions like runtime.Caller and should return a struct instead. So the linter should perhaps only warn when the called function is within the same module/repository. At the least, a list of known exclusions in the standard library would be good.

Unavoidable failure

I encountered a problem while using dogsled to check my source code. I use tview in my project, which has an API that returns the coordinates and height and width of the rectangle where the UI element is located. Such APIs are common in UI libraries. But my code only needs to know the height, so I have to write this code:

	_, _, _, height := ui.pages.GetRect()

But at this time dogsled told me that this was wrong. But I can’t really assign them to some variables, because I really do n’t need them!

So what should I do?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.