reviser

package
v3.0.0-...-2c71b05 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StandardInput = "<standard-input>"
)

Variables

View Source
var (
	ErrPathIsNotDir = errors.New("path is not a directory")
)

Functions

func IsDir

func IsDir(path string) (string, bool)

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 WithSkipGeneratedFile

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"
	// 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"
	// 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

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

SourceDir to validate and fix import

func NewSourceDir

func NewSourceDir(projectName string, path string, isRecursive bool, excludes string) *SourceDir

func (*SourceDir) Find

func (d *SourceDir) Find(options ...SourceFileOption) (*UnformattedCollection, error)

Find collection of bad formatted paths

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, []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

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

type UnformattedCollection

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

func (*UnformattedCollection) List

func (c *UnformattedCollection) List() []string

func (*UnformattedCollection) String

func (c *UnformattedCollection) String() string

Jump to

Keyboard shortcuts

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