Documentation
¶
Index ¶
- Constants
- Variables
- func IsDir(path string) (string, bool)
- func WithCodeFormatting(f *SourceFile) error
- func WithGeneratedFilesFormatting(f *SourceFile) error
- func WithRemovingUnusedImports(f *SourceFile) error
- func WithUsingAliasForVersionSuffix(f *SourceFile) error
- type ImportsOrder
- type ImportsOrders
- type SourceDir
- type SourceFile
- type SourceFileOption
- type SourceFileOptions
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 WithGeneratedFilesFormatting ¶
func WithGeneratedFilesFormatting(f *SourceFile) error
WithGeneratedFilesFormatting will format generated files.
func WithRemovingUnusedImports ¶
func WithRemovingUnusedImports(f *SourceFile) error
WithRemovingUnusedImports is an option to remove unused imports
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" // CompanyImportsOrder is packages that belong to the same organization CompanyImportsOrder ImportsOrder = "company" // ProjectImportsOrder is packages that are inside the current project ProjectImportsOrder ImportsOrder = "project" // GeneralImportsOrder is packages that are outside. In other words it is general purpose libraries GeneralImportsOrder ImportsOrder = "general" )
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 ¶
type SourceDir struct {
// contains filtered or unexported fields
}
SourceDir to validate and fix import
func (*SourceDir) Fix ¶
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, bool, error)
Fix is for revise imports and format the code
type SourceFileOption ¶
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 ¶
type SourceFileOptions []SourceFileOption
SourceFileOptions is a slice of executing options