jslint

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

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 -

JavaScript catch parameter already defined

戏子无情 提交于 2019-12-02 18:14:16
I'm trying to understand why I'm getting the following error, not how to work around it. Passing the following code to JSLint or JSHint yields the error 'err' is already defined. /*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: true, windows: true, bitwise: true, newcap: true, strict: true, maxerr: 50, indent: 4 */ function xyzzy() { "use strict"; try { /*Step 1*/ } catch (err) { } try { /*Step 2*/ } catch (err) { } } The obvious assumption here is that catch behaves, or should behave, like a function. Thus, err is neither a

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

How to disable the Weird Condition check in JSLint?

这一生的挚爱 提交于 2019-12-02 17:19:46
问题 I have some code that maps keyboard keys to blocks of code of varying length, from something as simple as return false , to mainly 2-3 line snippets, to complex functions: var k = window.event.keycode; switch(true){ case(k === 9): // break; case(k === 13): // break; case(k === 38 && selectedRecord > 1): // break; } I'd rather not create an object with a list of functions and map it that way, because they're mainly short blocks of code and there is the odd complex case . Is there an option to

Adobe Brackets disable jslint but allow jshint

大兔子大兔子 提交于 2019-12-02 16:59:55
My basic question: In the Adobe Brackets editor how do I use jshint while turning off or disabling jslint? My tl;dr: When linting javascript in the Adobe Brackets editor I find that I get results for both jslint and jshint. While I have jshint configured to my liking I can never avoid the warning symbol that appears indicating I have failed to pass jslint so it always looks like there are problems with my linting. I only want to use jshint as the ability to globally configure it via the .jshintrc file is quite useful but I don't see a way to turn off jslint and still permit jshint. Anyone know

How to fix '$' was used before it was defined in both jslint and jshint using coding?

浪子不回头ぞ 提交于 2019-12-02 15:40:51
问题 I am using jQUery . And in jslint , I keep on '$' was used before it was defined. or document was used before it was defined. I know I can stop those from showing up by using /*jslint browser: true*/ /*global $, jQuery*/ But I wanted to actually fix this through coding if possible. So, I did like before. var $, document; $(document).ready(function () { "use strict"; However, now it says Two warnings 1 Redefinition of '$'. 1 Redefinition of 'document'. in jshint . Is there a coding that I can

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

别等时光非礼了梦想. 提交于 2019-12-02 14:29: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 .jshintrc file? (update: this post is from 2013 and obsolete now) I use JSHint + JSX. It shouldn't require

How to disable the Weird Condition check in JSLint?

天涯浪子 提交于 2019-12-02 10:20:51
I have some code that maps keyboard keys to blocks of code of varying length, from something as simple as return false , to mainly 2-3 line snippets, to complex functions: var k = window.event.keycode; switch(true){ case(k === 9): // break; case(k === 13): // break; case(k === 38 && selectedRecord > 1): // break; } I'd rather not create an object with a list of functions and map it that way, because they're mainly short blocks of code and there is the odd complex case . Is there an option to disable the check for switch(true) (as there are for other checks)? Related, but not a duplicate: Is a

How to fix '$' was used before it was defined in both jslint and jshint using coding?

…衆ロ難τιáo~ 提交于 2019-12-02 09:29:50
I am using jQUery . And in jslint , I keep on '$' was used before it was defined. or document was used before it was defined. I know I can stop those from showing up by using /*jslint browser: true*/ /*global $, jQuery*/ But I wanted to actually fix this through coding if possible. So, I did like before. var $, document; $(document).ready(function () { "use strict"; However, now it says Two warnings 1 Redefinition of '$'. 1 Redefinition of 'document'. in jshint . Is there a coding that I can use to please both jshint and jslint ? Please use jslint comments. The following suggestion uses a few