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

Assume jQuery (or assume $) #16

Closed
jlbruno opened this issue Feb 18, 2011 · 20 comments
Closed

Assume jQuery (or assume $) #16

jlbruno opened this issue Feb 18, 2011 · 20 comments

Comments

@jlbruno
Copy link

jlbruno commented Feb 18, 2011

I'd love to see an option to assume jQuery (or another library using $) is available.

Chances are good that code being run through JSHint might use the $ function that has been defined in another file somewhere, and it would be nice to have it as an option to turn off the errors from $ being undefined.

@mikeh
Copy link

mikeh commented Feb 18, 2011

Ideally I would like to see a more generic solution such as a comma-separated list of pre-defined global variables (i.e. you can't assume "jQuery" or "$" for jQuery in no conflict mode, YAHOO, etc.). JSLint supports this via the text box right at the bottom of the options panel.

@GarrettS
Copy link

Assume jQUery would require syncing to jQUery versions. Would a user-defined global identifiers table fit your needs?

@jlbruno
Copy link
Author

jlbruno commented Feb 18, 2011

I would think so, yes. As long as I don't run my code through and get back 30 errors that $ isn't defined. I would think any global vars from other libraries would have the same issue.

@valueof
Copy link
Member

valueof commented Feb 19, 2011

mikeh, you can add pre-defined globals using /_global ... */ syntax. So, for jQuery it will be /_global $, jQuery */

GarrettS, does jQuery exposes anything but $ and jQuery to the global scope? And those two variables don't change from version to version.

I agree about adding jQuery globals as an environment.

@GarrettS
Copy link

THe behavior of jQuery changes from versions. And so if jQuery isn't expected to be anything other than a global function, then why limit the feature of "add a global function" to be hardwired as "add a global function named jQuery"? I really can't see why it the feature needs to be tied to jQuery. And why not allow the user to add any number of global identifiers?

@valueof
Copy link
Member

valueof commented Feb 19, 2011

You can already add any number of global identifiers using the /*global ... */ syntax. Environment options are just shortcuts for commonly used globals so that you don't have to write /*global jQuery, $ */ in every single file. So, assuming browser and jQuery environments, for example, will let JSHint know that jQuery and window are pre-defined globals but will report if you make a typo and try to execute jquery.

@valueof
Copy link
Member

valueof commented Feb 19, 2011

Also, the option is going to be opt-in so it won't affect anybody by default.

@GarrettS
Copy link

If the goal is to warn user about problems in code, then warning about the usage of a global identifier jQuery would go much further towards that goal.

@paulirish
Copy link
Member

In general, I'd say it's up to the user to define their globals at the top.

If the browser environment is selected, we could reveal a few checkboxes for jQuery, Dojo, YUI, that augment the globals line.. but.. I think the onus should be on the user to account for their globals.

@jlbruno
Copy link
Author

jlbruno commented Feb 19, 2011

Anton and Paul, I think you guys are on the right track. A few options for the most common libraries would be nice.

Paul, what syntax would we use to define our globals at the top of our files?

@valueof
Copy link
Member

valueof commented Feb 19, 2011

As I described above, you can already use /*global global1, global2, ... */ syntax to describe globals.

@jlbruno
Copy link
Author

jlbruno commented Feb 19, 2011

ah, gotcha, sorry. I think your comment here is spot on though:
#16 (comment)

having the option to turn those on as environment options would be sweet as to not have to put it in every file.

@valueof
Copy link
Member

valueof commented Feb 20, 2011

Added jQuery predefined globals (closed by f3b6594)

@valueof
Copy link
Member

valueof commented Feb 20, 2011

Implemented in f3b6594.

@baryluk
Copy link

baryluk commented Dec 28, 2011

This option (user supplied list of assumed global variables) is still not available on web page jshint.com :(

@valueof
Copy link
Member

valueof commented Dec 28, 2011

It is there: http://cl.ly/3t1a3U122x1l1m0B0r2m

@baryluk
Copy link

baryluk commented Dec 28, 2011

Oh, sorry. I was actually concerned about possibility of user-supplied list of global identifier. Original jslint.com have a input field, which allow you to add any assumed global variabled. It is missing at jshint.com.

@valueof
Copy link
Member

valueof commented Dec 31, 2011

You can provide the list of globals by putting /*global var1:false, var2:false */. I try to keep jshint.com as simple as possible.

jugglinmike pushed a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014
danielctull pushed a commit to danielctull-forks/jshint that referenced this issue Jan 14, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants