Skip to content

x/tools/internal/refactor/inline: choose better local names for renaming imports #74965

@gavinkflam

Description

@gavinkflam

Part of #63352

The current mechanism takes the last segment of the package path and appends a numeric suffix (if needed) to ensure uniqueness. This produces low-quality local names such path2, format3 and strings5.

I propose to add strategies (2) and (3), as illustrated below, to generate better names. These follow common practices for package aliasing and result in more meaningful names.

  1. Try PkgName (unchanged).
  2. Try PkgName + "pkg". For example, path becomes pathpkg.
  3. Prepend preceding path segments until the name is unique or no all segments have been used. For example, golang.org/x/tools/internal/astutil becomes internalastutil, toolsinternalastutil, xtoolsinternalastutil, or golangorgxtoolsinternalastutil. Adding a length limit might be a good idea.
  4. Appending a numeric suffix (unchanged). For example, path becomes path1, path2, ...

I'd love to implement these myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolProposalIssues describing a requested change to a Go tool or command-line program.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