8000 stylecheck: check for the LHS of a declaration containing a redundant type · Issue #551 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

stylecheck: check for the LHS of a declaration containing a redundant type #551

Closed

Description

@cespare

Follow-up from #542.

Golint has a check for the uneeded type in code like this:

var b *bytes.Buffer = bytes.NewBufferString("asdf")
should omit type *bytes.Buffer from declaration of var b; it will be inferred from the right-hand side

Staticcheck should add a "code that isn't really doing anything" check for this.

Activity

  1. changed the title [-]staticcheck: add an SA4??? check for the LHS of a declaration containing a redundant type[/-] [+]stylecheck: check for the LHS of a declaration containing a redundant type[/+] on Jul 29, 2019
  2. added and removed
    needs-triageNewly filed issue that needs triage
    on Jul 29, 2019
  3. dominikh commented on Jul 29, 2019

    @dominikh
    Owner

    It's really more of a style rule, not a matter of correctness.

  4. cespare commented on Jul 29, 2019

    @cespare
    Author

    Oh, I see. The SA4??? checks are about "code which isn't really doing anything, so maybe you made a mistake and intended for it to do something"?

  5. dominikh commented on Jul 29, 2019

    @dominikh
    Owner

    That is correct.

  6. cespare commented on May 10, 2021

    @cespare
    Author

    Since golint is being deprecated/removed we're getting rid of it in our org. FWIW I think this is the only useful check we're losing which isn't covered by staticcheck.

  7. dominikh commented on May 14, 2021

    @dominikh
    Owner

    We'll add two versions of the check: one in stylecheck and one in quickfix.

    The one in stylecheck will be disabled by default, but can be opted into. It will have the following exceptions to reduce false/noisy positives:

    // It does not flag variables under the following conditions, to reduce the number of false positives:
    // - global variables – these often specify types to aid godoc
    // - files that use cgo – the cgo code generation may turn conversions into declarations, and we don't want to flag redundant conversions in this check
    //
    // It does not flag variables under the following conditions, unless flagHelpfulTypes is true, to reduce the number of noisy positives:
    // - packages that import syscall or unsafe – these sometimes use this form of assignment to make sure types are as expected
    // - variables named the blank identifier – a pattern used to confirm the types of variables
    // - named untyped constants on the rhs – the explicitness might aid readability
    

    This is essentially a better version of what you had in golint.

    The one in quickfix will be enabled by default, but only be used inside gopls. It will not underline code or emit warnings, but it will simply grey out redundant types and offer to remove them. It does not have the last 3 exceptions. It will result in a user experience like the following:
    image

  8. dominikh commented on May 14, 2021

    @dominikh
    Owner

    However, this check is probably another one for #938.

  9. cespare commented on May 19, 2021

    @cespare
    Author

    Awesome, thanks!

  10. added a commit that references this issue on Apr 8, 2024
    331bcca
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