This commit is contained in:
parent
09fceca2f9
commit
40e5379eb3
11 changed files with 250 additions and 2 deletions
29
cmds/golines/format.go
Normal file
29
cmds/golines/format.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golangci/golines/shorten"
|
||||
)
|
||||
|
||||
func formatSource(source string, maxLen int) (output []byte, err error) {
|
||||
// Dependency panics must not escape the JS callback and terminate the WASM runtime.
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
output = nil
|
||||
err = fmt.Errorf("golines could not format this input (internal panic: %v). Ensure the input is a complete Go file, including a package declaration", recovered)
|
||||
}
|
||||
}()
|
||||
|
||||
tabLen := 4
|
||||
if maxLen < 80 {
|
||||
tabLen = 2
|
||||
}
|
||||
return shorten.NewShortener(&shorten.Config{
|
||||
MaxLen: maxLen,
|
||||
TabLen: tabLen,
|
||||
ShortenComments: true,
|
||||
ReformatTags: true,
|
||||
ChainSplitDots: true,
|
||||
}).Process([]byte(source))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue