MarioCarrion / nit

Opinionated code organization linter for Go projects.
MIT License
19 stars 0 forks source link
go golang golang-tools lint linter linting nitpick styleguide

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

Fancy State Machine explaining the rules above:

code

Installing

// +build tools

package tools

import (
    _ "github.com/MarioCarrion/nit/cmd/nit"
)

Using

After installing you can use:

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

Please use nit -h for other available arguments.

Development requirements

Go >= 1.14.0