Comments (18)
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.
Assume jQUery would require syncing to jQUery versions. Would a user-defined global identifiers table fit your needs?
from jshint.
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.
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.
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.
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.
Also, the option is going to be opt-in so it won't affect anybody by default.
from jshint.
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.
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.
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.
As I described above, you can already use /*global global1, global2, ... */
syntax to describe globals.
from jshint.
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.
Added jQuery predefined globals (closed by f3b6594)
from jshint.
Implemented in f3b6594.
from jshint.
This option (user supplied list of assumed global variables) is still not available on web page jshint.com :(
from jshint.
It is there: http://cl.ly/3t1a3U122x1l1m0B0r2m
from jshint.
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.
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)
- Getting errors while adding as dev-dependancy HOT 1
- JSHint doesn't recognize bitwise operators like & | >> etc... HOT 2
- is there any kind of way to get the console log outputs using this tool? HOT 1
- can i customize the error messages generated by JSHINT? is there any locale files i can override? HOT 1
- Not work in VS Code's Terminal HOT 1
- 'fetch' is not defined. (W117) - Although it is a base feature of Node 18 (although experimental) HOT 3
- Error: JSHINT is not defined HOT 2
- False error on static property HOT 1
- W080 incorrect message for initializing const with undefined HOT 2
- jshint doesn't expect regexp literals in one-liners following if/while/for conditions, and also else HOT 3
- `jshint` breaks on experimental feature `import * as file_json from 'file.json' assert { 'type': 'json' };` HOT 11
- JShint in VScode HOT 1
- If variable is assigned but never used it should cause warning HOT 1
- esversion beyond 11 HOT 2
- Generate error on specific object properties HOT 1
- jshint 2.13.6 is not warning me about mixing tabs and spaces HOT 1
- No warnings about undefined variable when doing typeof yyy
- VSCode HOT 1
- Jshint doest trigger hint when access non exist property of an object HOT 1
- "Invalid regular expression" when /s flag is used on long RegExps
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 jshint.