Command splint

Install: go get stathat.com/c/splint

splint is a little Go application to analyze Go source files. It finds any functions that are too long or have too many parameters or results.

These are typical signs that a function is doing too much. We find `splint` to be a helpful tool for detecting potential problem areas in our code, areas that should be refactored. We tolerate long functions and functions with long parameter/result lists when they are needed, but generally try to keep them short.

Usage

To use splint, give it any number of Go source files on the command line.

To check just a single file:

splint blobd.go

To check a few files:

splint hdisckback.go histod.go histostore.go

To check an entire source tree (with zsh):

splint **/*.go

If **/*.go isn't supported by your shell, you can do:

find . -name "*.go" -exec splint {} \;

By default, splint will inform you of any functions that are more than 30 statements long, have more than five parameters, or have more than five results.

You can change these values with command line flags. -s sets the statement count threshold, -p sets the parameter count threshold, and -r sets the result count threshold.

Check for all functions with more than 50 statements, 10 parameters, 7 results:

splint -s=50 -p=10 -r=7 **/*.go

Example output

Here's what splint outputs when run against itself:

$ splint -s=5 splint.go

splint.go
function statementCount too long: 12
function outputFilename too long: 8
function checkFuncLength too long: 10
function checkParamCount too long: 10
function checkResultCount too long: 10
function examineDecls too long: 8
function Parse too long: 8
function main too long: 24

Number of functions above statement threshold: 8
Number of functions above param threshold: 0
Number of functions above result threshold: 0

splint can also output JSON, which makes it easy to integrate with other systems, like a continuous integration server. Run splint with the -j flag for JSON output:

air:~/git/external/splint> splint -s=5 -j splint.go
{
	"Statement": [
		{
			"Filename": "splint.go",
			"Function": "statementCount",
			"Count": 12
		},
		{
			"Filename": "splint.go",
			"Function": "outputFilename",
			"Count": 8
		},
		{
			"Filename": "splint.go",
			"Function": "checkFuncLength",
			"Count": 10
		},
		{
			"Filename": "splint.go",
			"Function": "checkParamCount",
			"Count": 10
		},
		{
			"Filename": "splint.go",
			"Function": "checkResultCount",
			"Count": 10
		},
		{
			"Filename": "splint.go",
			"Function": "examineDecls",
			"Count": 8
		},
		{
			"Filename": "splint.go",
			"Function": "Parse",
			"Count": 8
		},
		{
			"Filename": "splint.go",
			"Function": "main",
			"Count": 24
		}
	],
	"Param": null,
	"Result": null,
	"NumAboveStatementThreshold": 8,
	"NumAboveParamThreshold": 0,
	"NumAboveResultThreshold": 0
}