amalgomated

package
v0.0.0-...-64567a0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

importalias

importalias is a check that verifies that import aliases in a project are used consistently. It verifies that, if a given package is imported using an alias, then all aliases for that import are consistent across the project.

Usage

importalias uses its current working directory as the project root. If no arguments are provided, it is invoked on all of the go packages it can find in the current working directory and its subdirectories. If arguments are provided, they are interpreted as packages relative to the working directory, and only the specified packages will be checked.

By default, the output of the check is standard Go check output format. The program operates as follows:

  • Finds all imports and all aliases that are used for imports.
  • If a package is imported using multiple different aliases, the alias that is most commonly used to import the package is considered the "correct" import.
    • If there is a tie for the most commonly used alias, it is assumed that there is no consensus for the alias.
  • Any line that imports a package using an alias that is not the most common one (or an alias for which there is no consensus) is treated as an error. The file and line number is printed, along with a suggestion for how the alias should be renamed.

The -v or --verbose flag can be used to print an overview of all of the imports in the project that are imported using multiple aliases. The output is organized by import and lists all of the aliases used for the import (in order of most commonly used) and the files and locations in the files in which the imports occur.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmalgomatedMain

func AmalgomatedMain()

Types

type AliasStatus

type AliasStatus struct {
	// true if this alias is the only alias used for a package or is the most common alias used for a package.
	OK bool
	// recommendation for how to fix the issue if OK is false.
	Recommendation string
}

type ImportAlias

type ImportAlias struct {
	ImportPath string
	Alias      string
	Pos        token.Position
}

type ImportAliasInfo

type ImportAliasInfo struct {
	ImportPath string
	Alias      string
	// file -> line information for import in the file
	Occurrences map[string]token.Position
}

type ProjectImportInfo

type ProjectImportInfo interface {
	// AddImportAliasesFromFile adds all of the import alias information from the given file.
	AddImportAliasesFromFile(filename string) error

	// ImportsWithMultipleAliases returns a map from an imported package path to all of the aliases to import the package.
	// The aliases are sorted by the number of uses of that alias.
	ImportsToAliases() map[string][]ImportAliasInfo

	// FilesToImportAliases returns a map from each file in the project to all of the alias imports in the file.
	FilesToImportAliases() map[string][]ImportAlias

	// GetAliasStatus returns the AliasStatus for the given alias used to import the package with the provided path.
	GetAliasStatus(alias, importPath string) AliasStatus
}

func NewProjectImportInfo

func NewProjectImportInfo() ProjectImportInfo

Jump to

Keyboard shortcuts

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