Comments (5)
Hm. You could call it a false negative, but the tool is pretty conservative when a function's signature is fixed by the code. I would say this is working as intended. Imagine:
http.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello world!")
})
If we implement your idea, this would be a warning, because r
is unused. However, having to rename the request would be cumbersome and make the code less consistent with other http handler funcs:
http.HandleFunc(func(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintln(w, "Hello world!")
})
The aim of the tool is not to flag parameters which could lose their names - the aim is to find parameters that could be removed entirely. That's pretty well summarised by "unused", I think. In a way, your parameter is used - to satisfy a function signature.
from unparam.
I see your point. However I would argue that parameter names are actually not part of the function signature. The signature is defined by the types only. If the variable is not used I really prefer _ or omitting since it documents that the function is not using it. Hope that argument makes sense
from unparam.
Yeah, that makes sense, but that feels like personal preference more than anything. A linter that tells you what parameters could be named _
could exist, but that linter isn't unparam, because it does something quite different :)
from unparam.
from unparam.
I would say not. The feature you want is pretty easy to write as a separate linter, so it doesn't really benefit from being here.
from unparam.
Related Issues (20)
- goreleaser: error: unknown long flag '--snapshot', try --help HOT 2
- mvdan.cc certificate expired HOT 3
- main package has no godoc HOT 1
- Possible to skip directories through flag? HOT 1
- False positive on implementing interface HOT 4
- Allow setting of tests struct field on the Checker type HOT 1
- Support Go 1.17 slice-to-array conversion HOT 5
- proposal: don't group exported and unexported methods of an interface together?
- fails on itself at tip HOT 1
- panics when encountering generics HOT 2
- panic: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident HOT 3
- disable warnings on funcs which use go:linkname
- An option to ignore parameters starting with the underscore (e.g., `_name`)? HOT 2
- panic analysing generic function with struct param with generic field types HOT 5
- Bump golang.org/x/tools to v0.7.0 (as minimum) and make new tag HOT 2
- Allow enable on constructors like `NewXXX`
- Refactor to use go/analysis HOT 1
- panic: unexpected receiver AST node: *ast.ParenExpr
- Release or version tag plan HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unparam.