autogroup

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixupDefaultImportAlias

func FixupDefaultImportAlias(pkgTypeInfo map[string]*astTypes.Package) func(s *ast.ImportSpec)

FixupDefaultImportAlias ensures import alias is added to imports if last component of path does not match package name.

func FixupEmbedPackage

func FixupEmbedPackage(s *ast.ImportSpec)

FixupEmbedPackage ensures side effect only embed package has a comment to avoid getting flagged by linters.

func FixupNoOp

func FixupNoOp(_ *ast.ImportSpec)

func New

func New(opts ...Option) types.ImportTransform

Types

type GroupMatcher

type GroupMatcher func(spec *ast.ImportSpec, path string) bool

GroupMatcher is a function that determines group membership.

type Option

type Option func(conf *config)

Option represents configurable option for autogroup transform.

func WithCustomLocalGroupMatcher

func WithCustomLocalGroupMatcher(lookup GroupMatcher) Option

WithCustomLocalGroupMatcher allows overriding local group matcher if prefix based lookup is not flexible enough.

func WithCustomStdlibMatcher

func WithCustomStdlibMatcher(lookup GroupMatcher) Option

WithCustomStdlibMatcher allows overriding stdlib matcher.

Stdlib lookup is messy and is a moving target with new Go releases. This is your escape hatch if built in lookup is not working for you to make sure that this library is still usable in the future.

func WithLocalPrefixGroup

func WithLocalPrefixGroup(prefixes []string) Option

WithLocalPrefixGroup enables an extra local group of imports to differentiate between third party and project import based on import path prefixes.

func WithNoDotGroupEnabled

func WithNoDotGroupEnabled(enable bool) Option

WithNoDotGroupEnabled enables an extra group for imports that are not StdLib and do not have dots in first path component. Most typically this is useful for differentiating auto-generated imports.

func WithSideEffectGroupEnabled

func WithSideEffectGroupEnabled(enable bool) Option

WithSideEffectGroupEnabled enables an extra side effect group for imports that are imported purely for side effects.

func WithSpecFixups

func WithSpecFixups(fixups ...SpecFixup) Option

WithSpecFixups configures rules for adjusting import specs.

Examples:

  • FixupDefaultImportAlias - ensure import alias is added if last component of path does not match package name.
  • FixupEmbedPackage - ensure a comment is added to side effect import of embed package to appease linters.

type SpecFixup

type SpecFixup func(s *ast.ImportSpec)

SpecFixup is a function that modifies an ImportSpec in place. Allows adding aliases and comments.

func DefaultSpecFixups

func DefaultSpecFixups(pkgTypeInfo map[string]*astTypes.Package) []SpecFixup

Jump to

Keyboard shortcuts

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