Skip to content
Branch: master
Commits on Mar 10, 2019
  1. CI: test on Go 1.12

    mvdan committed Mar 10, 2019
Commits on Feb 13, 2019
  1. bump dependency versions

    mvdan committed Feb 13, 2019
Commits on Feb 9, 2019
  1. fix up another false negative in testdata

    mvdan committed Feb 9, 2019
    In the go/ast search, look for just "_ = par", and not any mention of a
    parameter like "par = someVal".
  2. fix a minor false negative in callExtract

    mvdan committed Feb 9, 2019
    Gets rid of a testdata TODO. While at it, fix another, which was just
    due to how go/ssa works.
  3. check: replace last use of callgraph

    mvdan committed Feb 9, 2019
    Both the "result is never used" and "parameter always receives const"
    checks only worked for local calls really, as we can't know how
    dependent packages call exported functions of the current package.
    As such, we don't really need a deep callgraph. Looking at the direct
    static calls is practically the same. I was still expecting to see a few
    new false positives in the testing corpus, but none have appeared.
    For now, leave the new code as simple as it is. We can make it smarter
    if we do find false positives.
  4. rewrite "called in return" code without callgraph

    mvdan committed Feb 9, 2019
    Another big chunk of unparam that can be implemented in pure go/ssa. We
    only have one piece left.
    This one was tricky, as it required keeping track of which parts of
    signatures cannot be changed in a more precise way.
    In the process, we uncovered some new false positives due to the removal
    of callgraph. Those were fixed with go/ssa, and more regression tests
    were added.
    On the plus side, the newer code is more precise when it comes to false
    negatives, so five more correct warnings are now detected in the main Go
Commits on Jan 31, 2019
  1. rewrite foo(bar()) code to work without callgraph

    mvdan committed Jan 31, 2019
    While at it, make the code more maintainable and robust.
  2. replace more callgraph code with plain SSA

    mvdan committed Jan 31, 2019
    The ones that required attention were functions used for phis, globals,
    collection elements, and as return results.
Commits on Jan 30, 2019
  1. testdata: consistently use tabs

    mvdan committed Jan 30, 2019
    I hadn't noticed this yet, embarassingly enough.
  2. work properly with method wrapper functions

    mvdan committed Jan 30, 2019
    When we see an instruction using a method wrapper, we are interested in
    the method being wrapped, not the wrapper itself. Make findFunction
    fetch the function being wrapped.
    This fixes the false positive in the added test case. Before, we didn't
    see that FooType.checkRedirect was being used as a field, as the Store
    instruction only used the method wrapper from the method value line
  3. properly record which methods implement interfaces

    mvdan committed Jan 30, 2019
    Fixes a test failure, a test TODO, and makes our algorithm more robust
    against false positives.
  4. testdata: add more regression tests

    mvdan committed Jan 30, 2019
    We weren't covering one edge case, where a method is used to implement
    an interface which is only potentially called from within an imported
Commits on Jan 24, 2019
  1. default to -tests=false

    mvdan committed Jan 24, 2019
    First, this makes the tool way faster, as most developers write tests
    within the same package. This greatly slows down package loading, as we
    must load each package twice.
    If golang/go#29258 is ever accepted and
    implemented, that cost might be reduced.
    Second, most warnings within test files are not very useful. Even if
    most aren't false positives, it's common for developers to not care as
    much about test code quality.
    Finally, loading the tests can lead to different results, as test files
    can also use the functions which may or may not give warnings. More
    often than not, the developer cares about how non-test functions are
    used from within non-test code.
    For all these reasons, disable test loading by default. It can still be
    enabled manually.
  2. skip all funcs that are converted to interfaces

    mvdan committed Jan 24, 2019
    Not just because they're being stored to a field with an interface type.
    This also covers map[string]interface{}, for example, which can be
    common in test code.
  3. avoid false positives with implements assertions

    mvdan committed Jan 24, 2019
    It's common to write global declarations like:
    	var _ SomeInterface = (*SomeNamed)(nil)
    This way, one ensures that SomeNamed will always implement SomeInterface
    in the future. However, unparam could still suggest changes to the
    methods in SomeNamed, which could break this assertion.
    For now, just skip the entire named type in that case. In the future, we
    can only skip those methods which are necessary to implement the
  4. work around confusing crash in std

    mvdan committed Jan 24, 2019
    Seems to have started happening since I pulled the last Go master
    Nothing seems obviously wrong with my code, and it only happens 50% of
    the time. Might be a bug in the ssa or callgraph packages.
    A very weird corner case though, so for now, just work around the panic.
  5. refactor funcUsedAs field store logic

    mvdan committed Jan 24, 2019
    It's simpler if we look for Store instructions instead, and we don't
    need to look at referrers.
  6. testdata: fix the impl.txt test script

    mvdan committed Jan 24, 2019
    This test was failing, which we weren't noticing as we expected empty
    Add a simple warning case, and make the package typecheck again.
  7. remove the -tags flag

    mvdan committed Jan 24, 2019
    go/packages does not support loading with a number of tags; at least not
    right now. The flag did nothing, so remove it for now.
    A likely solution for those requiring the flag:
    	GOFLAGS=-tags=foo,bar unparam ./...
    This commit is technically a breaking change, but the flag had been
    broken for months. And I presume that all users are pinning a specific
    version of unparam.
  8. ignore funcs which undergo type changes

    mvdan committed Jan 24, 2019
    Like in the previous commits, these often lead to false positives.
    Fixes #37.
  9. remove the ability to select a callgraph algorithm

    mvdan committed Jan 24, 2019
    We'll soon remove callgraph entirely, as it doesn't do all we need and
    requires analysing entire programs all at once.
    As a step in that direction, stop exposing callgraph options to the
  10. never warn on funcs used as interfaces

    mvdan committed Jan 24, 2019
    These often lead to false positives, as the interface value is often
    called via type switches, reflection, or other methods.
    As before, don't rely on callgraph for this. It doesn't deal well with
    that kind of runtime type conversion.
    We had a few test cases which were "correct positives", but looking at
    them again, they don't seem particularly useful or stable. Better to be
    on the safe side and not warn on those.
    Fixes #23.
  11. don't flag funcs passed as params via closures

    mvdan committed Jan 24, 2019
    Like in the previous case involving fields, do this with a bit of SSA
    code instead of relying on callgraph. The trick here was to go past
    Fixes #36.
  12. don't flag funcs used as fields

    mvdan committed Jan 24, 2019
    These very often lead to false positives, as fields tend to have a
    function signature type which is hard to change. Moreover, it's hard to
    track where the field will end up being used.
    The callgraph package isn't of much help here, so implement this with
    go/ssa only.
    Fixes #35.
Commits on Jan 21, 2019
  1. convert the rest of the tests to scripts

    mvdan committed Jan 21, 2019
  2. add first test script

    mvdan committed Jan 21, 2019
    testscripts will let us write independent but simple tests for each of
    the corner cases. At the cost of a few extra files, we'll make the tests
    much easier to maintain and much more reliable.
  3. update x/tools version

    mvdan committed Jan 21, 2019
    And simplify the CI script.
Commits on Dec 1, 2018
  1. mod: update x/tools, tidy

    mvdan committed Dec 1, 2018
  2. check: make "_ = param" mean the parameter is used

    mvdan committed Dec 1, 2018
    This kind of idiom is already used to make the compiler's "declared but
    not used" error go away, so it should get rid of our tool's warning too.
    A bit trickier than it should be, since that kind of statement is
    dropped by go/ssa.
    Fixes #32.
Commits on Oct 21, 2018
  1. check: revert to using packages.LoadSyntax

    mvdan committed Oct 21, 2018
    As Alan Donovan points out, LoadAllSyntax is not required after all if
    one only needs the syntax, types, and SSA for the direct set of
    That's exactly our use case, so use that. This means we can avoid
    re-loading all the dependencies from source each time, which can greatly
    speed up the tool on large projects.
Commits on Oct 20, 2018
  1. set exit code according to found warnings

    sni authored and mvdan committed Oct 18, 2018
    Setting the exit > 0 if there are some warnings makes it easier to use
    in automated tests.
Commits on Oct 12, 2018
  1. CI: temporarily drop Go 1.10

    mvdan committed Oct 12, 2018
    At least until we figure out why 'go list' behaves in a weird way in
    GOPATH mode. Go 1.10 doesn't have a module-aware mode like 1.11, so we
    don't have an easy workaround at the moment.
    See golang/go#28155.
Commits on Oct 11, 2018
  1. check: use the LoadAllSyntax mode

    mvdan committed Oct 10, 2018
    This is required to build the SSA program out of go/packages' output.
    Also modify the manyReturns test case, as runtime/pprof contains an
    interface that matches that signature, thus making the conservative
    callgraph algorithm add a call edge.
Commits on Oct 10, 2018
Commits on Oct 9, 2018
  1. CI: drop Go 1.9, add 1.11

    mvdan committed Oct 9, 2018
    And fix a GO111MODULE typo.
You can’t perform that action at this time.