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

unparam does not support build tags #22

Closed
benpaxton-hf opened this issue Jan 17, 2018 · 7 comments
Closed

unparam does not support build tags #22

benpaxton-hf opened this issue Jan 17, 2018 · 7 comments
Assignees

Comments

@benpaxton-hf
Copy link

unparam currently doesn't support build tags, which means packages which require a non-implicit build tag can't be linted, e.g.:

main.go

package main

import (
	"./sub"
	"fmt"
)

func main() {
	fmt.Printf("Hello, %s!\n", sub.Get())
}

sub/sub_a.go

//+build a

package sub

func Get() string {
	return "world"
}

sub/sub_b.go

//+build b

package sub

func Get() string {
	return "everyone"
}

sub/sub.go

package sub

// some shared code
$ ls
main.go  sub
$ unparam .
.../main.go:9:29: Get not declared by package sub
couldn't load packages due to errors: .
$ go run -tags a main.go 
Hello, world!
$ go run -tags b main.go 
Hello, everyone!
@mvdan
Copy link
Owner

mvdan commented Jan 17, 2018

Good point - this needs to be added.

Ideally, there would be a way to check all tag combinations without having to multiply the amount of work. I have no idea how to do that, though.

@mvdan mvdan self-assigned this Jan 17, 2018
@benpaxton-hf
Copy link
Author

Checking all tag combinations is probably impossible without knowing what they mean - in my example case, for example, a b and !a !b are not valid - only a !b and !a b are valid tag combinations.

If unparam -tags a . worked, though, it'd be easy to use external tools to enumerate valid tag combinations and lint each, e.g.

lint-unparam:
    unparam -tags a .
    unparam -tags b .

@dmitshur
Copy link
Contributor

In case this is helpful, see https://github.com/mdempsky/unconvert/pull/27/files for an example of how this can be implemented.

@mvdan
Copy link
Owner

mvdan commented Jan 17, 2018

@shurcooL thanks, that just saved me a good ten minutes of furious head-scratching.

@mvdan
Copy link
Owner

mvdan commented Jan 17, 2018

Also, jesus, the help output is bad:

 $ unparam -h
usage: unparam [flags] [package ...]
  -debug
        debug prints
  -exported
        inspect exported functions
  -tags build tags
        a list of build tags to consider satisfied during the build. For more information about build tags, see the description of build constraints in the documentation for the go/build package
  -tests
        include tests (default true)

I've filed golang/go#23464 about this.

@dmitshur
Copy link
Contributor

dmitshur commented Feb 9, 2018

FYI, according to https://speakerdeck.com/campoy/the-state-of-go-1-dot-10?slide=23, there have been some improvements to the flags package in Go 1.10 to make its output more readable.

Also, friendly ping on resolving this issue. I would've liked to use it today:

$ unparam -tags=dev ./...
flag provided but not defined: -tags

@mvdan
Copy link
Owner

mvdan commented Feb 10, 2018

Thanks for the ping - I got sidetracked on this.

@mvdan mvdan closed this as completed in 12f6a00 Feb 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants