Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/homuler/goimports-wasabi
goimports fork, which works deterministically, keeping as many comments as possible.
https://github.com/homuler/goimports-wasabi
go goimports
Last synced: about 2 months ago
JSON representation
goimports fork, which works deterministically, keeping as many comments as possible.
- Host: GitHub
- URL: https://github.com/homuler/goimports-wasabi
- Owner: homuler
- License: bsd-3-clause
- Created: 2022-10-10T09:48:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-23T09:33:47.000Z (about 2 years ago)
- Last Synced: 2024-06-20T16:49:59.503Z (7 months ago)
- Topics: go, goimports
- Language: Go
- Homepage:
- Size: 464 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goimports-wasabi
[![Run Tests](https://github.com/homuler/goimports-wasabi/actions/workflows/test.yml/badge.svg)](https://github.com/homuler/goimports-wasabi/actions/workflows/test.yml)
This is a fork of [`goimports`](https://pkg.go.dev/golang.org/x/tools/cmd/goimports), inspired by [the `gosimports` project](https://github.com/rinchsan/gosimports).
`goimports-wasabi` also tries to solve [the import grouping/ordering problem](https://github.com/golang/go/issues/20818), but in a different way.## Overview
`goimports` and `gosimports` have the following issues (as of 2022/11).
- `goimports` doesn't sort import specs deterministically.
- `goimports` doesn't treat comments associated with import specs properly.
- `goimports` doesn't work well for artificial inputs.
- `gosimports` removes comments associated with import specs.`goimports-wasabi` is designed to work deterministically with any valid input, leaving as many comments as possible in the (supposedly) correct place.
## Installation
```sh
go install github.com/homuler/goimports-wasabi@latest
```## Examples
### Grouping/Ordering Problem
#### Input
```go
import (
// doc comment for fmt
"fmt"/*
* block comments
*/// doc comment for foo
"github.com/homuler/foo"
"context"
// footer comment (maybe for context)"strings" // line comment for strings
b "github.com/homuler/bar"
_ "runtime/pprof" // line comment for pprof
)
```#### Output
```go
import (
"context"
// footer comment (maybe for context)// doc comment for fmt
"fmt"
_ "runtime/pprof" // line comment for pprof
"strings" // line comment for strings/*
* block comments
*/b "github.com/homuler/bar"
// doc comment for foo
"github.com/homuler/foo"
)
```goimports
```go
import (
// doc comment for fmt
"fmt"/*
* block comments
*/// doc comment for foo
"context""github.com/homuler/foo"
// footer comment (maybe for context)
"strings" // line comment for strings
b "github.com/homuler/bar"
_ "runtime/pprof" // line comment for pprof
)
```### Merging Problem
#### Input
```go
// doc comment for fmt
import "fmt"// doc comment for context
import "context"// doc comment
import (
// doc comment for errors
"errors"
)
```#### Output
`goimports-wasabi`
```go
// doc comment
import (
// doc comment for context
"context"
// doc comment for errors
"errors"
// doc comment for fmt
"fmt"
)
```goimports
```go
// doc comment for fmt
import (
"context"
"errors"
"fmt"
)// doc comment for context
// doc comment
// doc comment for errors
```### Unusual Input
#### Input
```go
import ("fmt";"fmt";"context";"github.com/homuler/foo")
```#### Output
`goimports-wasabi -format-only`
```go
import (
"context"
"fmt""github.com/homuler/foo"
)
```goimports -format-only
```go
panic: invalid line number 2 (should be < 2)
```## License
[BSD-3-Clause](https://github.com/homuler/goimports-wasabi/blob/main/LICENSE)
Copyright (c) 2009 The Go Authors. All rights reserved.