Skip to content

x/tools/cmd/goimports: put std, cmd packages in separate blocks #38735

@jayconrod

Description

@jayconrod

This came up in CL 228378 and many others. If we delete all the imports from src/cmd/go/internal/modload/modfile.go then run goimports, we should see cmd imports in a separate group from std imports:

import (
	"fmt"
	"io/ioutil"
	"path/filepath"

	"cmd/go/internal/base"
	"cmd/go/internal/cfg"
	"cmd/go/internal/modfetch"

	"golang.org/x/mod/modfile"
	"golang.org/x/mod/module"
	"golang.org/x/mod/semver"
)

Instead, all the std and cmd imports are grouped together.

import (
	"cmd/go/internal/base"
	"cmd/go/internal/cfg"
	"cmd/go/internal/modfetch"
	"fmt"
	"io/ioutil"
	"path/filepath"

	"golang.org/x/mod/modfile"
	"golang.org/x/mod/module"
	"golang.org/x/mod/semver"
)

goimports does the right thing if at least one cmd import is already in a separate group. It combines the groups when adding the first std or cmd import though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions