Skip to content
Opinionated code organization linter for Go (lang)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
cmd/nit
testdata
vendor/github.com
.gitignore
.go-version
.golangci.yml
.goreleaser.yml
Dockerfile
Gopkg.lock
Gopkg.toml
LICENSE
README.md
break_comments.go
break_comments_test.go
code.png
consts.go
consts_test.go
file_sections.go
file_sections_test.go
funcs.go
funcs_test.go
go.mod
go.sum
imports.go
imports_test.go
methods.go
methods_test.go
nit_test.go
nitpicking.go
nitpicking_test.go
sorted_names_validator.go
tools.json
types.go
types_test.go
vars.go
vars_test.go

README.md

nit

Go Report Card Circle CI coverage

nit is an opinionated Code Organization linter for Go.

It defines a collection of rules to determine how each Go file should be organized internally.

Rules

  1. imports is the first section
    • Requires parenthesized declaration,
    • One maximum, and
    • Separated in 3 blocks: standard, external and same package (local).
  2. type is the second section
    • Requires parenthesized declaration,
    • Section must be sorted: exported first, then unexported; and
    • Supports //- comment for separating groups
  3. const is the third section
    • Requires parenthesized declaration,
    • Multiple allowed, and
    • Section must be sorted: exported first, then unexported.
  4. var is the fourth section
    • Requires parenthesized declaration, and
    • Section must be sorted: exported first, then unexported.
  5. func is the fifth section
    • Must be sorted, exported first, then unexported, and
    • Supports //- comment for separating groups.
  6. func method, is the sixth section
    • Must be sorted by type, exported first, then unexported; and
    • Supports //- comment for separating groups.

Fancy State Machine explaining the rules above:

code

Installing

  • Using go (< 11.1): go install github.com/MarioCarrion/nit/cmd/nit or download a precompiled release.
  • Using go (>= 1.11): GO111MODULE=on go get github.com/MarioCarrion/nit/cmd/nit@v0.6.0, for installing v0.6.0 for example; see the releases for other versions.
  • Using retool: retool add github.com/MarioCarrion/nit/cmd/nit v0.5.0, for installing v0.5.0 for example; see the releases for other versions.

Using

After installing you can use:

nit -pkg <base local package> $(go list ./...)

Please use nit -h for other available arguments.

Development

  • Go < 1.11: requires dep, you can use retool for installing that dependency.
  • Go >= 1.11: GO111MODULE=on go mod download
  • goenv is used for versioning Go.
You can’t perform that action at this time.