Giter VIP home page Giter VIP logo

Comments (5)

mvdan avatar mvdan commented on May 10, 2024

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.

helmus avatar helmus commented on May 10, 2024

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.

mvdan avatar mvdan commented on May 10, 2024

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.

helmus avatar helmus commented on May 10, 2024

from unparam.

mvdan avatar mvdan commented on May 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.