Skip to content

Commit d7ef4c3

Browse files
committed
First commit
0 parents  commit d7ef4c3

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2017, Daniel Martí. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of the copyright holder nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# unparam

main.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) 2017, Daniel Martí <[email protected]>
2+
// See LICENSE for licensing information
3+
4+
package main
5+
6+
import (
7+
"flag"
8+
"fmt"
9+
"go/types"
10+
"os"
11+
12+
"golang.org/x/tools/go/loader"
13+
"golang.org/x/tools/go/ssa/ssautil"
14+
15+
"github.com/kisielk/gotool"
16+
)
17+
18+
func main() {
19+
flag.Parse()
20+
if err := unusedParams(flag.Args()); err != nil {
21+
fmt.Fprintln(os.Stderr, err)
22+
os.Exit(1)
23+
}
24+
}
25+
26+
func unusedParams(args []string) error {
27+
paths := gotool.ImportPaths(args)
28+
var conf loader.Config
29+
_, err := conf.FromArgs(paths, false)
30+
if err != nil {
31+
return err
32+
}
33+
iprog, err := conf.Load()
34+
if err != nil {
35+
return err
36+
}
37+
pkgs := make(map[*types.Package]bool)
38+
for _, pinfo := range iprog.InitialPackages() {
39+
pkgs[pinfo.Pkg] = true
40+
}
41+
42+
prog := ssautil.CreateProgram(iprog, 0)
43+
44+
prog.Build()
45+
for fn := range ssautil.AllFunctions(prog) {
46+
if fn.Pkg == nil || !pkgs[fn.Pkg.Pkg] {
47+
continue
48+
}
49+
fmt.Println(fn)
50+
}
51+
return nil
52+
}

0 commit comments

Comments
 (0)