tsenart / deadcode Goto Github PK
View Code? Open in Web Editor NEWStandalone repo of deadcode package from http://github.com/remyoudompheng/go-misc
License: Other
Standalone repo of deadcode package from http://github.com/remyoudompheng/go-misc
License: Other
The current snippet gives warning warning: some is unused
.
package p
import "fmt"
func some(s string, n int) {
fmt.Println(s)
// n is unused
}
However, if the function is exported, then there is no warning.
No warning:
package p
import "fmt"
func Some(s string, n int) {
fmt.Println(s)
// n is unused
}
thanks for ripping this out.
go-style package wildcards would be nice.
$ deadcode ./...
deadcode: not a directory: ./...
In my abundant free time, I'll try to make a PR.
regards,
n
Example: https://gist.github.com/BenLubar/851d3de63699f50e76ef0f866a0049a3
Since deadcode probably isn't going to be able to parse cgo very easily, it's best to just assume that every function with //export exactFunctionName
on the line before it is used if any Go file in the package imports the C
package.
If you have an unused constant which is tagged with // nolint: deadcode a warning is still generated
package main
import (
"fmt"
)
const (
Valid = iota
Invalid // nolint: deadcode
Another
)
func SetState(s int) {
switch s {
case Valid:
fmt.Println("valid")
default:
fmt.Println("unknown state %v", s)
}
}
gometalinter.v1 --disable-all --enable deadcode --debug .
DEBUG: PATH=/data/go/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin:/usr/local/go/bin:/data/go/bin:/data/go/bin
DEBUG: GOPATH=/data/go
DEBUG: GOBIN=/data/go/bin
DEBUG: linting path .
DEBUG: linting with deadcode: deadcode {path} (on .)
DEBUG: executing /data/go/bin/deadcode ["."]
DEBUG: warning: deadcode . returned exit status 2
DEBUG: deadcode hits 2: ^deadcode: (?P<path>.*?\.go):(?P<line>\d+):(?P<col>\d+):\s*(?P<message>.*)$
DEBUG: nolint: parsing job.go for directives
DEBUG: deadcode linter took 11.886236ms
DEBUG: nolint: parsing job.go took 226.93µs
job.go:7:1:warning: Invalid is unused (deadcode)
job.go:12:1:warning: SetState is unused (deadcode)
DEBUG: total elapsed time 22.532206ms
Ignore the fact that SetState is unused, that's just a side effect of the simplified example.
The issue is caused by the fact that deadcode is reporting the issue for line 7 when in fact it should report line 9.
deadcode
deadcode: oauth_helpers.go:70:1: validateJWS is unusedgrep validateJWS *
oauth_helpers.go:// validateJWS gets the access token
oauth_helpers.go:func validateJWS(accessToken string) []byte {
test_cases_test.go: claims := unmarshalJWT(validateJWS(access))
test_cases_test.go: claims := unmarshalJWT(validateJWS(string(validateJWE(access))))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.