jshint

Getting Facebook's react.js library JSX syntax to play nicely with jslint?

微笑、不失礼 提交于 2019-12-03 01:15:42
问题 I am playing around with the Facebook's react.js library. I am trying to use their JSX syntax which describes creating a view in the following way. /** @jsx React.DOM */ var HelloMessage = React.createClass({ render: function() { return <div>{'Hello ' + this.props.name}</div>; } }); React.renderComponent(<HelloMessage name="John" />, mountNode); JSLint obviously does not like this ("expected an identifier and instead saw ' <';" - JavaScript syntax error), so how do I get around this in my

How to tell JSHint to ignore all undefined variables in one file?

元气小坏坏 提交于 2019-12-03 01:02:28
In Karma tests, there are a lot of global variables and functions, which JSHint complains about (it is integrated into my editor). How can I tell JSHint to ignore all undefined variables in this one specific file? I would expect /* jshint undef: false */ to turn off these warning, but it doesn't. James Allardice The correct way to tell JSHint about globals is to use the globals directive. For example: /*globals globalFunction, anotherGlobal, oneMore */ This will prevent "{a} is not defined" warnings when JSHint encounters any of the listed identifiers. Alternatively, if you really want to

Why is Jshint saying “variable already defined” in this if statement?

我们两清 提交于 2019-12-02 21:01:55
I have this code: if ( something is true ) { var someVar = true; } else { var someVar = false; } JsHint is saying that "someVar was already defined" on the else statement part. Why is this and how do I fix it? Thanks JS variables do not have block scope, they have "function" scope (or sometimes global). The declaration (but not the assignment) is "hoisted" to the top of the function. jshint is warning you that you have two such declarations - your code is equivalent to: var someVar; var someVar; // warning! if (something) { someVar = true; } else { someVar = false; } This is due to hoisting.

Disable JSHint warning: Expected an assignment or function call and instead saw an expression [duplicate]

可紊 提交于 2019-12-02 20:14:24
This question already has an answer here: Expected an assignment or function call and instead saw an expression 4 answers Why does jshint not recognize an assignment as an expression? 8 answers I have the following line: imageUrl && (data.imageUrl = imageUrl); For this line, JSHint complains: Expected an assignment or function call and instead saw an expression. I understand the warning, but I want to disable it. I can’t find the way how to do it. Any idea? If it really is just that one line imageUrl && (data.imageUrl = imageUrl); // jshint ignore:line I am a fan of writing code so it doesn't

Is it bad practice to use the same variable name in multiple for-loops?

做~自己de王妃 提交于 2019-12-02 19:55:00
I was just linting some JavaScript code using JSHint. In the code I have two for-loops both used like this: for (var i = 0; i < somevalue; i++) { ... } So both for-loops use the var i for iteration. Now JSHint shows me an error for the second for-loop: "'i' is already defined". I can't say that this isn't true (because it obviously is) but I always thought this wouldn't matter as the var i is only used in that specific place. Is it bad practice to use for-loops this way? Should I use a different variable for each for-loop in my code like //for-loop 1 for (var i = 0; ...; i++) { ... } //for

AngularJS controllers and “use strict”

為{幸葍}努か 提交于 2019-12-02 18:56:39
I recently started using JSHint and it is requiring me to use the function form of "use strict". Since then, AngularJS throws an error: "Error: Argument 'webAddressController' is not a function, got undefined" When I remove the function form of "use strict" the controller loads fine. Controller: (function () { "use strict"; function webAddressController($scope, $rootScope, web_address_service) { // Do things } }()); Does anyone have any insight on what's going on here? Ben Lesh First off, I want to state the pkozlowski really knows his stuff at Angular, but this actually isn't as much of an

How to set jshint/jsxhint “esnext” option in Atom

我与影子孤独终老i 提交于 2019-12-02 18:50:15
I am using Atom's linter , react , and linter-jshint / linter-jsxhint . In my JSX files, I keep getting the warning Warning: 'import' is only available in ES6 (use esnext option). (W119) That's pretty straightforward. I did some searching, and found that this can be set under the jshintConfig option in package.json (when using NPM). My project uses NPM and I have a package.json . I added: "jshintConfig": { "esnext": true } After that, I did a reload but the warnings persist. I also modified my linter-jshint / linter-jsxhint config in Atom ( config.cson ) with: "linter-jshint": harmony: true

How can I check JavaScript code for syntax errors ONLY from the command line?

元气小坏坏 提交于 2019-12-02 18:45:52
JavaScript programs can be checked for errors in IDEs or using online web apps but I'm looking for a way to detect syntax errors alone . I've tried JSLint and JSHint and looked at their options but I haven't been able to find a combination that would exclude warnings and just shows the syntax errors . How do I check JavaScript code for syntax errors only from the command line? cweiske I use acorn : $ acorn --silent tests/files/js-error.js; echo $? Unexpected token (1:14) 1 $ acorn --silent tests/files/js-ok.js; echo $? 0 Install via: npm -g install acorn . The solution is to enable jshint's -

How to suppress “{variable} is better written in dot notation.”

為{幸葍}努か 提交于 2019-12-02 18:41:33
Is there an option to and/or how do I suppress errors like the following? 175,14:['tracker'] is better written in dot notation. TomFuertes If it's a feature and not a bug, place this at the top of your file. /*jshint sub:true*/ If it's a bug, you should refactor your code foo['tracker'] = bar // from this... foo.tracker = bar; // to this! Good post on the reasons here: https://stackoverflow.com/a/2001410/94668 In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax . The identifier of this warning is W069 . This means you can tell JSHint to not issue

Where can I find a list of JSHint numeric error codes?

孤者浪人 提交于 2019-12-02 17:26:07
I'm using JSHint for Visual Studio. It's not uncommon for JSHint to issue a warning about an issue that I know it safe to ignore. I have been putting // ignore jslint on the relevant line, but I see that we can also ignore specific error codes. From the 1.0.0 rc1 release notes : This version adds a unique numeric code to every warning and error message produced by JSHint. That means that you can now ignore any warning produced by JSHint even when there is no corresponding option for it. You can do that using the special minus (-) operator. For example, here’s how you ignore all messages about