Documentation ¶
Index ¶
- func FixupDefaultImportAlias(pkgTypeInfo map[string]*astTypes.Package) func(s *ast.ImportSpec)
- func FixupEmbedPackage(s *ast.ImportSpec)
- func FixupNoOp(_ *ast.ImportSpec)
- func New(opts ...Option) types.ImportTransform
- type GroupMatcher
- type Option
- func WithCustomLocalGroupMatcher(lookup GroupMatcher) Option
- func WithCustomStdlibMatcher(lookup GroupMatcher) Option
- func WithLocalPrefixGroup(prefixes []string) Option
- func WithNoDotGroupEnabled(enable bool) Option
- func WithSideEffectGroupEnabled(enable bool) Option
- func WithSpecFixups(fixups ...SpecFixup) Option
- type SpecFixup
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 ¶
WithLocalPrefixGroup enables an extra local group of imports to differentiate between third party and project import based on import path prefixes.
func WithNoDotGroupEnabled ¶
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 ¶
WithSideEffectGroupEnabled enables an extra side effect group for imports that are imported purely for side effects.
func WithSpecFixups ¶
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.