go-import-lint

module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2021 License: MIT

README

go-import-lint

Version Build Status Go Report Card Coverage Status

Golang source code analyzer that checks imports order. It verifies that:

  • standard, current package, and vendor imports are separated by a line;
  • there are no blank lines between one import group;
  • there are no more than two lines.

Example of good imports order:

package main

import (
    // Standart imports.
    "fmt"
    "error"

    // Current package imports.
    "github.com/hedhyw/go-import-lint/internal/linter"
    "github.com/hedhyw/go-import-lint/internal/model"

    // External imports.
    "github.com/hedhyw/jsonscjson"
    "github.com/stretchr/testify/assert"

    // Unused imports.
    _ "github.com/lib/pq"
)

Features:

  • Checking the blank lines between standart, package and external imports.
  • Files discovering.
  • Support import aliases.
  • Getting package name from the go.mod.
  • Ignore vendor by default.
  • Ignore generated files.
  • Support comments offset.
  • 😠 Nolint comment // nolint:go-import-lint.
  • Check imports arrange.
  • Integrate with golangci-lint.

Installing:

go get github.com/hedhyw/go-import-lint/cmd/go-import-lint

Usage example:

Run:

go-import-lint

Usage of go-import-lint:
  -exclude value
        paths to exclude (default ./vendor, ./.git)
  -path value
        paths to lint (default ./...)
  -pkg string
        module package

Directories

Path Synopsis
cmd
internal
gomod
Package gomod helps to determinate package name from the go.mod file.
Package gomod helps to determinate package name from the go.mod file.
linter
Package linter contains core logic for the linter.
Package linter contains core logic for the linter.
model
Package model describes basic linter entities.
Package model describes basic linter entities.
walker
Package walker contains the walker that scans directories for golang files.
Package walker contains the walker that scans directories for golang files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL