๐โโ๏ธ See more ...
rinchsan / gosimports Goto Github PK
View Code? Open in Web Editor NEWalias goimports='gosimports'
Home Page: https://pkg.go.dev/github.com/rinchsan/gosimports
License: BSD 3-Clause "New" or "Revised" License
alias goimports='gosimports'
Home Page: https://pkg.go.dev/github.com/rinchsan/gosimports
License: BSD 3-Clause "New" or "Revised" License
๐โโ๏ธ See more ...
I'm writing a Go code generator, and I'd love to be able to apply gosimports after generation, before writing the actual file, so I'm holding a []byte
-- for some reason using imports.Process
takes a loooooooong time.
Thanks for putting together this utility!
I believe I found a bug with how gosimports
removes unused imports. If the package name doesn't match the name of the directory a package is imported from, gosimports
will mistakenly think it is unused and remove it.
Example:
File being imported:
// project/foo/test.go
package foobar // NOTE: package name is "foobar", but directory is "foo"
func Test() { ... }
Source file:
package server
import (
"fmt"
"github.com/mycompany/repo/foo/foo"
)
func main() {
fmt.Printf("Hello world")
foobar.Test()
}
gosimports
will incorrectly remove this import:
package server
import (
"fmt"
)
func main() {
fmt.Printf("Hello world")
foobar.Test()
}
However, if I manually name the import, gosimports
will keep the import as desired.
package server
import (
"fmt"
foobar "github.com/mycompany/project/foo/foo"
)
func main() {
fmt.Printf("Hello world")
foobar.Test()
}
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
}
const helloWorld = `
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
}
gets reformated to
package main
import (
"fmt"
)
func main() {
fmt.Println("hello world")
}
const helloWorld = `
package main
import (
)
func main() {
fmt.Println("hello world")
}
There the import is now broken.
When importing the same module under different aliases and when the second import has a comment with a right-paren, the second import is duplicated.
Input file:
package foo
import (
"fmt"
blah "fmt" // ) fun
)
func something() {
fmt.Println(`hi`)
blah.Println(`hi`)
}
Actual output:
package foo
import (
"fmt"
blah "fmt" // ) fun
blah "fmt" // ) fun
)
func something() {
fmt.Println(`hi`)
blah.Println(`hi`)
}
This is a pretty degenerate case! We're triggering this only because we have a tool in our repo that detects imports aliased under different names and gosimports is formatting its test file.
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
@rinchsan Would you be open to adding support for s390x
and ppc64le
?
s390x
refers to the mainframe architecture on Linux or common referred to Linux on Z. While ppc64le
refers to the Power architecture. Both architectures are made by IBM, even though some of it is open source.
From my experience both s390x and ppc64le both have great support in GO and usually cross compile without issue.
I believe the .goreleaser.yml
would need to be update to look something like:
project_name: gosimports
changelog:
skip: true
builds:
- id: gosimports
main: ./cmd/gosimports/
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- s390x
- ppc64le
ignore:
- goos: darwin
goarch: s390x
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: s390x
- goos: windows
goarch: ppc64le
brews:
- name: gosimports
tap:
owner: rinchsan
name: homebrew-tap
url_template: "https://github.com/rinchsan/gosimports/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: goreleaserbot
email: [email protected]
folder: Formula
homepage: "https://pkg.go.dev/github.com/rinchsan/gosimports/cmd/gosimports"
description: Command gosimports updates your Go import lines, adding missing ones, removing unreferenced ones, and removing redundant blank lines.
test: |
system "#{bin}/gosimports --help"
install: |
bin.install "gosimports"
Happy to test and validate s390x
and ppc64le
support as I have access to the hardware. If there are not issues, I would be happy to open a PR.
@rinchsan Let me know if you are open to the idea!
It would be nice to know which version of gosimports I am using.
Expect something like:
> gosimports -version
v0.1.5
Original:
import (
"time"
"github.com/pkg/errors"
elasticV5 "gopkg.in/olivere/elastic.v5"
"internal/go/repo/logs"
)
Expected:
@@ -11,9 +11,8 @@ import (
"time"
"github.com/pkg/errors"
elasticV5 "gopkg.in/olivere/elastic.v5"
"internal/go/repo/logs"
)
Actual:
@@ -11,9 +11,8 @@ import (
"time"
"github.com/pkg/errors"
- elasticV5 "gopkg.in/olivere/elastic.v5"
-
"internal/go/repo/logs"
+ elasticV5 "gopkg.in/olivere/elastic.v5"
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.