reviser

package
v0.0.0-...-ecfc07e Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 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 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 NewSourceDir

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

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

Jump to

Keyboard shortcuts

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