Skip to content

ST1019: allow ignoring underscore imports #1688

@rittneje

Description

@rittneje

We sometimes need to import a package for its side effects. For example:

import (
    _ "github.com/mattn/go-sqlite3"
)

However, let's say we now need to directly reference the imported package.

import (
    _ "github.com/mattn/go-sqlite3"
    sqlite3 "github.com/mattn/go-sqlite3"
)

// use sqlite3 here

In this situation, staticcheck will flag the duplicate import (ST1019). But removing the underscore import would be dangerous, since if the direct use of the package is later removed, goimports will remove the import and now we have a problem.

Since this is the only legitimate reason to have duplicate imports that I can think of, it would be nice if staticcheck had some flag to ignore underscore imports for ST1019.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionWe have to decide if this check is feasible and desirablenoisy-positive

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions