Git Product home page Git Product logo

Comments (18)

mikeh avatar mikeh commented on June 23, 2024

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.

from jshint.

GarrettS avatar GarrettS commented on June 23, 2024

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

from jshint.

jlbruno avatar jlbruno commented on June 23, 2024

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.

from jshint.

valueof avatar valueof commented on June 23, 2024

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.

from jshint.

GarrettS avatar GarrettS commented on June 23, 2024

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?

from jshint.

valueof avatar valueof commented on June 23, 2024

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.

from jshint.

valueof avatar valueof commented on June 23, 2024

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

from jshint.

GarrettS avatar GarrettS commented on June 23, 2024

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.

from jshint.

paulirish avatar paulirish commented on June 23, 2024

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.

from jshint.

jlbruno avatar jlbruno commented on June 23, 2024

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?

from jshint.

valueof avatar valueof commented on June 23, 2024

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

from jshint.

jlbruno avatar jlbruno commented on June 23, 2024

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.

from jshint.

valueof avatar valueof commented on June 23, 2024

Added jQuery predefined globals (closed by f3b6594)

from jshint.

valueof avatar valueof commented on June 23, 2024

Implemented in f3b6594.

from jshint.

baryluk avatar baryluk commented on June 23, 2024

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

from jshint.

valueof avatar valueof commented on June 23, 2024

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

from jshint.

baryluk avatar baryluk commented on June 23, 2024

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.

from jshint.

valueof avatar valueof commented on June 23, 2024

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

from jshint.

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.