segmentio / golines

A golang formatter that fixes long lines
MIT License
903 stars 56 forks source link

refactor: Create shorten package #88

Open gabe565 opened 1 year ago

gabe565 commented 1 year ago

Description

Refactor codebase to add a shorten package. This allows other projects to use this library and closes #34.

Some notes:

Unfortunately, this PR required some major refactoring and will create merge conflicts with any other open PRs.

Let me know if you have any suggestions!

Example: Usage in another project

main.go ```go package main import ( "fmt" "github.com/segmentio/golines/shorten" ) var code = `package main var myMap = map[string]string{"key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4", "key5", "value5"} ` func main() { shortener := shorten.New() out, err := shortener.Shorten([]byte(code)) if err != nil { panic(err) } fmt.Print(string(out)) } ```

Todo

mdwhatcott commented 5 months ago

I was just looking for a code-shortener-as-a-library and found this project, which is just what I was hoping for! My usecase includes code generation and I was hoping for a library rather than a command. Anything holding up this PR from being merged?

yipal commented 3 weeks ago

I would also love to see this merged.

gabe565 commented 3 weeks ago

This repo seems pretty inactive, but I can rebase this PR if there's a chance it'll be merged! It might be worth it to investigate gofumpt at this point. Looks like it'll split long lines if the env GOFUMPT_SPLIT_LONG_LINES=on is set