Categorygithub.com/MarioCarrion/nit
modulepackage
0.6.5
Repository: https://github.com/mariocarrion/nit.git
Documentation: pkg.go.dev

# README

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 (>= 1.13): go get github.com/MarioCarrion/nit/cmd/[email protected], for installing v0.6.0 for example; see the releases for other versions.
  • Using it as a dependency with the tools.go paradigm:
// +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

# Packages

No description provided by the author

# Functions

NewBreakComments returns all the valid break-like comments.
NewFileSectionTransition returns a new transition corresponding to the received value.
NewFileSectionTransition returns a new transition corresponding to the received value.
NewFuncDeclFileSection returns a new State that matches the decl type.
NewFuncsValidator returns a correctly initialized FuncsValidator.
NewGenDeclFileSection returns a new State that matches the decl type.
NewImportsSection returns the value representing the corresponding Imports section.
NewImportsSectionMachine returns a new ImportsSectionMachine with the initial state as `start`.
NewImportsTransition returns a new transition corresponding to the received value.
NewImportsValidator returns a new instalce of ImporstValidator with the local path prefix set.
NewMethodsValidator returns a correctly initialized MethodsValidator.
NewTypesValidator returns a correctly initialized TypesValidator.

# Constants

FileSectionConsts defines the `const` state.
FileSectionFuncs defines the `func` state.
FIXME kill.
SectionMethods defines the `method` state.
FileSectionTypes defines the `type` state.
FileSectionVars defines the `var` state.
ImportsSectionExternal represents the External Packages `imports` section.
ImportsSectionLocal represents the local Packages `imports` section.
ImportsSectionStd represents the Standard Library Packages `imports` section.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author