Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally warn about anonymous functions #1081

Open
Raynos opened this issue May 13, 2013 · 18 comments
Open

Optionally warn about anonymous functions #1081

Raynos opened this issue May 13, 2013 · 18 comments

Comments

@Raynos
Copy link
Contributor

Raynos commented May 13, 2013

When using anonymous functions instead of named function expressions or function declarations it will make stacktraces and code less readable

It would be nice if jshint could warn about them.

@daniellmb
Copy link

+1 I'd like to see this added as well, naming helps with everything from debugging stack traces, to reports on cyclomatic complexity. Lots of benefits with no cost, since any good minifier/compiler is smart enough to remove the name.

var hello = function hello(){
  alert('world');
};

Gets minified to:

var hello=function(){alert("world")};

@valueof
Copy link
Member

valueof commented May 21, 2013

Sounds like a good thing.

@valueof
Copy link
Member

valueof commented May 21, 2013

Although, SpiderMonkey is now capable of figuring out the name of anonymous functions in some cases.

@serenitus
Copy link

+1 here too.

@moeriki
Copy link

moeriki commented Nov 6, 2013

I really would like to see this as well.

@smhg
Copy link

smhg commented Dec 9, 2013

👍 indeed, for stack traces (with TraceKit).

@bvaughn
Copy link

bvaughn commented Mar 12, 2014

+1

2 similar comments
@wojtiku
Copy link

wojtiku commented Apr 10, 2014

+1

@hughes
Copy link

hughes commented Apr 29, 2014

+1

hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option adds the requirement that all function be named.
Anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option adds the requirement that all function be named.
Anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option adds the requirement that all function be named.
Anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option adds the requirement that all function be named.
Anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option adds the requirement that all function be named.
Anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option allows anonymous (unnamed) functions.
If false, anonymous functions will raise a warning (W126).
hughes added a commit to hughes/jshint that referenced this issue Apr 29, 2014
This option allows anonymous (unnamed) functions.
If false, anonymous functions will raise a warning (W126).
@Gvozd
Copy link

Gvozd commented Jun 25, 2014

+1

@valueof valueof added P2 and removed P2 labels Jul 6, 2014
@mgechev
Copy link

mgechev commented Jul 31, 2014

+1

@parautenbach
Copy link

This issue was closed on June 10, and v2.5.2 released on July 5, but I can't seem to use this option. Was it included in the release? It does not seem like the pull request has been merged (yet).

@michael-benin-CN
Copy link

Also having the same issue as @parautenbach

@josebalius
Copy link

+1 would love to use this

@3rd-Eden
Copy link

+1 I was just wondering the same thing. I would to have this directly in to JSHint instead of having to rely on other tools.

@jugglinmike
Copy link
Member

This sounds more like a code style feature, making it out-of-scope for JSHint. I might be wrong since @rwaldron recently tagged it as a proposal for JSHint 3. If it is out of scope, then I'd direct commenters to the JSCS project for its disallowanonymousfunctions option.

But before you go abolishing anonymous functions from your code for debugging purposes, I recommend you look into the function name inference behavior of ES6. In compliant environments, even function expressions will be assigned a useful name attribute. You can read more about that here: https://bocoup.com/weblog/whats-in-a-function-name/

@beautifulcoder
Copy link

So are we getting the anonymous function check or not? I feel named functions add clarity to code, therefore is not just code style. Much like maxcomplexity and maxparams.

@hughes
Copy link

hughes commented Dec 2, 2016

@beautifulcoder the rule exists in eslint, so it might be worth transitioning your project to use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests