importx

package
v0.0.0-...-b28e12a Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGroup

func InitGroup(s string) error

InitGroup initializes the groupSort rule with the given string. The string should be a comma-separated list of valid group names. If an invalid group name is encountered, it returns an error.

func Sort

func Sort(filename string, sorter Sorter) ([]byte, error)

Sort reads the go.mod file in the same directory as the given file to determine the module path. The sorted imports will be written back to the file. If sorter implements io.Writer, the formatted file will be written to it instead of being written back to the file. If sorter is nil, use the default.

Types

type ImportPath

type ImportPath struct {
	// contains filtered or unexported fields
}

ImportPath represents an import path with its name, value, use status, module path, and comment group.

func (ImportPath) PackageType

func (ip ImportPath) PackageType() string

PackageType returns the package type of the import path.

type ImportSorter

type ImportSorter struct{}

ImportSorter provides functionality to sort import paths in Go files.

func NewImportSorter

func NewImportSorter() *ImportSorter

NewImportSorter creates a new instance of ImportSorter with the given options.

func (*ImportSorter) Group

func (i *ImportSorter) Group(list []ImportPath) [][]ImportPath

Group groups the import paths by package type and sorts them according to the groupSort rule. It returns a 2D slice where each slice contains import paths of the same package type.

func (*ImportSorter) Sort

func (i *ImportSorter) Sort(list []ImportPath) []ImportPath

Sort sorts the import paths in the given list and returns the sorted list. It uses the go/ast and go/token packages to parse and sort the imports.

type Sorter

type Sorter interface {
	Group(list []ImportPath) [][]ImportPath
	Sort(list []ImportPath) []ImportPath
}

Sorter is the interface that wraps the basic Group and Sort method.

Jump to

Keyboard shortcuts

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