mvdan / gofumpt

A stricter gofmt
https://pkg.go.dev/mvdan.cc/gofumpt
BSD 3-Clause "New" or "Revised" License
3.15k stars 110 forks source link

Alias imported package to match the package name #305

Open artuross opened 3 weeks ago

artuross commented 3 weeks ago

When the import path doesn't match the package name, it's a good idea to alias the import to be more explicit.

Here's an example with github.com/testcontainers/testcontainers-go (which defines a package testcontainers):

import "github.com/testcontainers/testcontainers-go"

should be aliased to

import testcontainers "github.com/testcontainers/testcontainers-go"

Both imports are equivalent, because in both files, package can be accessed as testcontainers.

On the other hand, if the package is already aliased like in the following example, gofumpt should not change the alias:

import tc "github.com/testcontainers/testcontainers-go"