Skip to content

x/tools/gopls: modernize should remove unused imports #74559

Closed as duplicate of#72035
@silverwind

Description

@silverwind
package main

import (
	"sort"
)

func main() {
	foo := []string{}
	sort.Slice(foo, func(i, j int) bool { return foo[i] < foo[j] })
}

Running go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./... on this yields:

package main

import (
	"slices"
	"sort"
)

func main() {
	foo := []string{}
	slices.Sort(foo)
}

Which is invalid go because of compile error "sort" imported and not used. Instead, gopls should remove the unused sort import.

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.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions