Skip to content

Commit

Permalink
internal/cmd/deadcode: omit package/func keywords in default output
Browse files Browse the repository at this point in the history
...and don't quote the package path.

Updates golang/go#63501

Change-Id: Ic4f52bf74d7ddd185f2179deed55118971bfa7ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/540218
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
adonovan committed Nov 7, 2023
1 parent 118c362 commit 2638d66
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ func main() {
for _, fn := range pkg.Funcs {
if !seen {
seen = true
fmt.Printf("package %q\n", pkg.Path)
fmt.Println(pkg.Path)
}
fmt.Printf("\tfunc %s\n", fn.RelName)
fmt.Printf("\t%s\n", fn.RelName)
}
if seen {
fmt.Println()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deadcode/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ With the -format=template flag, the command executes the specified template
on each Package record. So, this template produces a result similar to the
default format:
-format='{{printf "package %q\n" .Path}}{{range .Funcs}}{{println "\tfunc " .RelName}}{{end}}{{println}}'
-format='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .RelName}}{{end}}{{println}}'
And this template shows only the list of source positions of dead functions:
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/deadcode/testdata/basic.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

deadcode -filter= example.com

want "func (T).Goodbye"
!want "func (T).Hello"
want "func unreferenced"
want "(T).Goodbye"
!want "(T).Hello"
want "unreferenced"

want "func Scanf"
want "func Printf"
!want "func Println"
want "Scanf"
want "Printf"
!want "Println"

-- go.mod --
module example.com
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/deadcode/testdata/filterflag.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

deadcode -filter=other.net example.com

want `package "other.net"`
want `func Dead`
!want `func Live`
want `other.net`
want `Dead`
!want `Live`

!want `package "example.com"`
!want `func unreferenced`
!want `example.com`
!want `unreferenced`

-- go.work --
use example.com
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/deadcode/testdata/testflag.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

deadcode -test -filter=example.com example.com/p

want "func Dead"
!want "func Live1"
!want "func Live2"
want "Dead"
!want "Live1"
!want "Live2"

want "func ExampleDead"
!want "func ExampleLive"
want "ExampleDead"
!want "ExampleLive"

-- go.mod --
module example.com
Expand Down

0 comments on commit 2638d66

Please sign in to comment.