8000 Detect useless anonymous functions · Issue #1681 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

Detect useless anonymous functions #1681

Open

Description

@dsnet

Consider this rewrite:

- slices.EqualFunc(c.Peers, o.Peers, func(a, b Peer) bool { return a.Equal(b) })
+ slices.EqualFunc(c.Peers, o.Peers, Peer.Equal)

The former used an unnecessary anonymous function that could instead directly used the method expression.

This is rewrite is relatively trivial to statically detect where you have function of N input arguments and M output arguments and the body includes a single return expression calling a method on the first argument with N-1 input arguments.

I considered filing this in the golang/go issue tracker as a go/vet finding, but it's not a correctness bug, but rather a cleanliness "bug" that might be suited for staticcheck (where "simplicity" is listed one of the goals).

Activity

  1. dominikh commented on Oct 7, 2025

    @dominikh
    Owner

    Related: #123

  2. added and removed
    needs-triageNewly filed issue that needs triage
    on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0