dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.18k stars 378 forks source link

stylecheck: recommend import grouppings #426

Open ainar-g opened 5 years ago

ainar-g commented 5 years ago

It's not uncommon to see imports like this in a project:

import (
    "a"
    "bitbucket.org/c/c"
    "github.com/d/d"
    "github.com/e/e"
    "bitbucket.org/f/f"
    "b"
)

Which should really be

import (
    "a"
    "b"

    "bitbucket.org/c/c"
    "bitbucket.org/f/f"

    "github.com/d/d"
    "github.com/e/e"
)

In fact, even the official Style Guide says so. I think that this is stylecheck-worthy.

ainar-g commented 5 years ago

While we're at it, we could probably also mark cases where people use `raw strings` instead of "usual strings" in imports.

fortytw2 commented 5 years ago

I feel like this would be a really good candidate for an autofix tool, but there aren't any of those in go-tools yet, I think?

ainar-g commented 5 years ago

@fortytw2 gofmt and goimports kind of do that. They sort imports alphabetically and put stdlib imports into a group of their own, but they don't further divide external imports into hostname groups.