feat: ignore empty imports
parent
5209660b88
commit
b17a39b0dd
|
@ -32,6 +32,7 @@ var (
|
||||||
ErrNotGoFile = errors.New("not go file")
|
ErrNotGoFile = errors.New("not go file")
|
||||||
ErrGoGeneratedFile = errors.New("go generated file")
|
ErrGoGeneratedFile = errors.New("go generated file")
|
||||||
ErrAlreadyFormatted = errors.New("already formatted")
|
ErrAlreadyFormatted = errors.New("already formatted")
|
||||||
|
ErrEmptyImport = errors.New("empty import")
|
||||||
ErrGoModNotExist = errors.New("go mod not exist")
|
ErrGoModNotExist = errors.New("go mod not exist")
|
||||||
ErrGoModEmptyModule = errors.New("go mod empty module")
|
ErrGoModEmptyModule = errors.New("go mod empty module")
|
||||||
)
|
)
|
||||||
|
@ -201,16 +202,11 @@ func (ft *Formatter) formatFile(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy from goimports, gofumpt, goimports-reviser
|
// Copy from goimports, gofumpt, goimports-reviser.
|
||||||
// First parse ast
|
// First parse ast.
|
||||||
//
|
// Then group imports.
|
||||||
// # Then group imports
|
// Then format imports.
|
||||||
//
|
// Then print.
|
||||||
// # Then format imports
|
|
||||||
//
|
|
||||||
// # Then update ast decls
|
|
||||||
//
|
|
||||||
// Then print ast
|
|
||||||
func (ft *Formatter) formatImports(
|
func (ft *Formatter) formatImports(
|
||||||
path string,
|
path string,
|
||||||
pathBytes []byte,
|
pathBytes []byte,
|
||||||
|
@ -238,6 +234,9 @@ func (ft *Formatter) formatImports(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decorator: failed to parse file [%s]: %w", path, err)
|
return nil, fmt.Errorf("decorator: failed to parse file [%s]: %w", path, err)
|
||||||
}
|
}
|
||||||
|
if len(dstFile.Imports) == 0 {
|
||||||
|
return nil, ErrEmptyImport
|
||||||
|
}
|
||||||
ft.logDSTImportSpecs("formatImports: dstImportSpecs", dstFile.Imports)
|
ft.logDSTImportSpecs("formatImports: dstImportSpecs", dstFile.Imports)
|
||||||
|
|
||||||
groupedDSTImportSpecs, err := ft.groupDSTImportSpecs(
|
groupedDSTImportSpecs, err := ft.groupDSTImportSpecs(
|
||||||
|
@ -406,5 +405,6 @@ func (ft *Formatter) moduleName(path string) (string, error) {
|
||||||
func (ft *Formatter) isIgnoreError(err error) bool {
|
func (ft *Formatter) isIgnoreError(err error) bool {
|
||||||
return errors.Is(err, ErrNotGoFile) ||
|
return errors.Is(err, ErrNotGoFile) ||
|
||||||
errors.Is(err, ErrGoGeneratedFile) ||
|
errors.Is(err, ErrGoGeneratedFile) ||
|
||||||
errors.Is(err, ErrAlreadyFormatted)
|
errors.Is(err, ErrAlreadyFormatted) ||
|
||||||
|
errors.Is(err, ErrEmptyImport)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue