feat: custom printer ast
parent
a341a91279
commit
065e5ec321
|
@ -200,6 +200,7 @@ func (ft *Formatter) formatImports(
|
||||||
// Parse ast
|
// Parse ast
|
||||||
fset := token.NewFileSet()
|
fset := token.NewFileSet()
|
||||||
|
|
||||||
|
// Copy from gofumpt
|
||||||
parserMode := parser.Mode(0)
|
parserMode := parser.Mode(0)
|
||||||
parserMode |= parser.ParseComments
|
parserMode |= parser.ParseComments
|
||||||
parserMode |= parser.SkipObjectResolution
|
parserMode |= parser.SkipObjectResolution
|
||||||
|
@ -276,8 +277,16 @@ func (ft *Formatter) formatImports(
|
||||||
// Print formatted bytes from formatted ast
|
// Print formatted bytes from formatted ast
|
||||||
var formattedBytes []byte
|
var formattedBytes []byte
|
||||||
formattedBuffer := bytes.NewBuffer(formattedBytes)
|
formattedBuffer := bytes.NewBuffer(formattedBytes)
|
||||||
if err := printer.Fprint(formattedBuffer, fset, astFile); err != nil {
|
|
||||||
return nil, err
|
// Copy from goimports
|
||||||
|
printerMode := printer.UseSpaces
|
||||||
|
printerMode |= printer.TabIndent
|
||||||
|
printerCfg := &printer.Config{
|
||||||
|
Mode: printerMode,
|
||||||
|
Tabwidth: 8,
|
||||||
|
}
|
||||||
|
if err := printerCfg.Fprint(formattedBuffer, fset, astFile); err != nil {
|
||||||
|
return nil, fmt.Errorf("printer: failed to fprint: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return formattedBuffer.Bytes(), nil
|
return formattedBuffer.Bytes(), nil
|
||||||
|
|
Loading…
Reference in New Issue