Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false-positive from 'unused' #585

Merged
merged 4 commits into from Sep 9, 2019

Commits on Jun 23, 2019

  1. Add failing testcase for false-positive from 'unused'

    This false-positive is not present in the upstream stand-alone 'unused'
    2019.1.1 program that golangci-lint uses.
    LukeShu committed Jun 23, 2019
    Copy the full SHA
    8ba24d0 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    a07dfde View commit details
    Browse the repository at this point in the history
  3. Fix the 'unused' false-positive

    pkg/lint.ContextLoader.filterPackages() did two things:
     1. It removed synthetic "testmain" packages (packages with .Name=="main"
        and .PkgPath ending with ".test")
     2. It removed pruned subsumed copies of packages; if a package with files
        "a.go" and "a_test.go", it results in packages.Load giving us two
        packages:
          - ID=".../a" GoFiles=[a.go]
          - ID=".../a [.../a.test]" GoFiles=[a.go a_test.go]
        The first package is subsumed in the second, and leaving it around
        results in duplicated work, and confuses the 'deadcode' linter.
    
    However, the 'unused' linter relies on both the ".../a" and
    ".../a [.../a.test]" packages being present.  Pruning them causes it to
    panic in some situations, which lead to this workaround:
    golangci/go-tools@af6baa5
    
    While that workaround got it to not panic, it causes incorrect results.
    
    So, split filterPackages() in to two functions: filterTestMainPackages()
    and filterDuplicatePackages().  The linter.Context.Packages list only
    gets filterTestMainPackages() called on it, while linter.Context.Program
    and linter.Context.SSAProgram get both filters applied.
    
    With the source of the panic fixed, roll back a few now-unnecessary
    commits in go-tools.
    LukeShu committed Jun 23, 2019
    Copy the full SHA
    479ce87 View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2019

  1. Copy the full SHA
    de4f858 View commit details
    Browse the repository at this point in the history