go-import-lint

module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 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

// CGo import.
import "C"

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"
)

Installation

Go
go install github.com/hedhyw/go-import-lint/cmd/go-import-lint@latest

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