Documentation ¶
Index ¶
- Constants
- Variables
- func IsDir(path string) (string, bool)
- func WithCodeFormatting(f *SourceFile) error
- func WithRemovingUnusedImports(f *SourceFile) error
- func WithSeparatedNamedImports(f *SourceFile) error
- func WithSkipGeneratedFile(f *SourceFile) error
- func WithUsingAliasForVersionSuffix(f *SourceFile) error
- type ImportsOrder
- type ImportsOrders
- type SourceDir
- type SourceFile
- type SourceFileOption
- type SourceFileOptions
- type UnformattedCollection
Constants ¶
const (
StandardInput = "<standard-input>"
)
Variables ¶
var (
ErrPathIsNotDir = errors.New("path is not a directory")
)
Functions ¶
func WithCodeFormatting ¶
func WithCodeFormatting(f *SourceFile) error
WithCodeFormatting use to format the code
func WithRemovingUnusedImports ¶
func WithRemovingUnusedImports(f *SourceFile) error
WithRemovingUnusedImports is an option to remove unused imports
func WithSeparatedNamedImports ¶ added in v3.8.0
func WithSeparatedNamedImports(f *SourceFile) error
func WithSkipGeneratedFile ¶ added in v3.3.0
func WithSkipGeneratedFile(f *SourceFile) error
WithSkipGeneratedFile will skip formatting and imports sorting for auto-generated file which starts with comment on first line: `// Code generated`
func WithUsingAliasForVersionSuffix ¶
func WithUsingAliasForVersionSuffix(f *SourceFile) error
WithUsingAliasForVersionSuffix is an option to set explicit package name in imports
Types ¶
type ImportsOrder ¶
type ImportsOrder string
ImportsOrder represents the name of import order
const ( // StdImportsOrder is std libs, e.g. fmt, errors, strings... StdImportsOrder ImportsOrder = "std" NamedStdImportsOrder ImportsOrder = "namedStd" // CompanyImportsOrder is packages that belong to the same organization CompanyImportsOrder ImportsOrder = "company" NamedCompanyImportsOrder ImportsOrder = "namedCompany" // ProjectImportsOrder is packages that are inside the current project ProjectImportsOrder ImportsOrder = "project" NamedProjectImportsOrder ImportsOrder = "namedProject" // GeneralImportsOrder is packages that are outside. In other words it is general purpose libraries GeneralImportsOrder ImportsOrder = "general" NamedGeneralImportsOrder ImportsOrder = "namedGeneral" // BlankedImportsOrder is separate group for "_" imports BlankedImportsOrder ImportsOrder = "blanked" // DottedImportsOrder is separate group for "." imports DottedImportsOrder ImportsOrder = "dotted" )
type ImportsOrders ¶
type ImportsOrders []ImportsOrder
ImportsOrders alias to []ImportsOrder
func StringToImportsOrders ¶
func StringToImportsOrders(s string) (ImportsOrders, error)
StringToImportsOrders will convert string, like "std,general,company,project" to ImportsOrder array type. Default value for empty string is "std,general,company,project"
type SourceDir ¶ added in v3.1.0
type SourceDir struct {
// contains filtered or unexported fields
}
SourceDir to validate and fix import
func NewSourceDir ¶ added in v3.1.0
func (*SourceDir) Find ¶ added in v3.6.0
func (d *SourceDir) Find(options ...SourceFileOption) (*UnformattedCollection, error)
Find collection of bad formatted paths
func (*SourceDir) Fix ¶ added in v3.1.0
func (d *SourceDir) Fix(options ...SourceFileOption) error
type SourceFile ¶
type SourceFile struct {
// contains filtered or unexported fields
}
SourceFile main struct for fixing an existing code
func NewSourceFile ¶
func NewSourceFile(projectName, filePath string) *SourceFile
NewSourceFile constructor
func (*SourceFile) Fix ¶
func (f *SourceFile) Fix(options ...SourceFileOption) ([]byte, []byte, bool, error)
Fix is for revise imports and format the code. Returns formated content, original content, true if formatted content is different from original and error.
type SourceFileOption ¶ added in v3.1.0
type SourceFileOption func(f *SourceFile) error
SourceFileOption is an int alias for options
func WithCompanyPackagePrefixes ¶
func WithCompanyPackagePrefixes(s string) SourceFileOption
WithCompanyPackagePrefixes option for 3d group(by default), like inter-org or company package prefixes
func WithImportsOrder ¶
func WithImportsOrder(orders []ImportsOrder) SourceFileOption
WithImportsOrder will sort by needed order. Default order is "std,general,company,project"
type SourceFileOptions ¶ added in v3.1.0
type SourceFileOptions []SourceFileOption
SourceFileOptions is a slice of executing options
type UnformattedCollection ¶ added in v3.6.0
type UnformattedCollection struct {
// contains filtered or unexported fields
}
func (*UnformattedCollection) List ¶ added in v3.6.0
func (c *UnformattedCollection) List() []string
func (*UnformattedCollection) String ¶ added in v3.6.0
func (c *UnformattedCollection) String() string