Code Monkey home page Code Monkey logo

dont's Introduction

This is just an idea I've been kicking around...

Don't: template-based, decentralized static analysis for Go

dont is a static analysis tool. It complements go vet, staticcheck, and regular tests.

To use dont, write a template. It looks like a regular function and describes something you shouldn't do:

// If you attempt to Close a file when opening it failed, the Close call will panic.
func DontCloseFileWhenOpenFailed(path string) {
	f, err := os.Open(path)
	defer f.Close()
	if err != nil {
		return
	}
}

Then invoke dont on the package containing your template and any packages you want to check:

$ dont path/to/template/package my/code/...

You can also include the templates that ship with dont:

$ dont github.com/josharian/dont/builtin/... path/to/my/templates/... my/code/...

You can also include any templates that have been included in any packages you depend on:

$ dont -deps my/code/...

Don't, vet, staticcheck, tests

vet and staticcheck contain careful, hand-written static analysis checks. They're great, but they're hard to extend without effort or background knowledge. They're also centralized.

dont is uncentralized. You can easily add your own templates with minimal ramp-up, and no need to ask anyone's permission.

dont checks are generally less powerful and general than vet and staticcheck tests, but in a great many cases that suffices. And they are easier to add, to maintain, and to reason about. dont complements vet and staticcheck.

dont also augments regular tests. Regular tests help your package function correctly. dont helps others use your package correctly. dont functions should sit alongside tests and examples and serve as enforceable documentation.

Status

I've written a few dont functions to convince myself that I like how they look and that they are expressive enough.

The actual matching engine remains to be written. :) I expect it to be non-trivial.

https://github.com/mvdan/gogrep might be a useful source of inspiration.

Looks like https://codelingo.io/ might be doing something somewhat similar.

License

BSD. Not that there's much here. :)

dont's People

Contributors

josharian avatar

Watchers

 avatar

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.