jslint

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

寵の児 提交于 2019-12-03 05:26:15
问题 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? 回答1: I use acorn: $ acorn --silent tests/files/js-error.js; echo $? Unexpected token (1:14) 1 $ acorn --silent tests

JavaScript catch parameter already defined

半世苍凉 提交于 2019-12-03 04:58:09
问题 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

Adobe Brackets disable jslint but allow jshint

点点圈 提交于 2019-12-03 04:31:03
问题 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

What is the JSLint approved way to convert a number to a string?

纵然是瞬间 提交于 2019-12-03 04:24:18
I've always converted numbers to strings by adding an empty string to them: var string = 1 + ''; However, JSLint complains of this method with Expected 'String' and instead saw ''''. , and it does look a little ugly. Is there a better way? I believe that the JSLint approved way is to call .toString() on the number: var stringified = 1..toString(); // Note the use of the double .. to ensure the the interpreter knows // that we are calling the toString method on a number -- // not courting a syntax error. // You could also theoretically call 1["toString"]; (Sorry, it possibly would've been

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

天涯浪子 提交于 2019-12-03 04:06:58
问题 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

Expressions in JavaScript Ternary Operator and JSLint

不问归期 提交于 2019-12-03 01:22:06
I recently received a comment on one of my blog posts about JSLint asking why JSLint threw an error with the following: s === "test" ? MyFunc() : MyFunc2(); The error generated was: "Expected an assignment or function call and instead saw an expression." Clearly JSLint is expecting an assignment here, somthing more like: var y = (s === "test") ? MyFunc() : MyFunc2(); But, I don't really see the problem with the first example. Is it really the case that ternary operators should only be used for assignments? I couldn't see anything on JSLint.com , nor was there anything apparent in the book

JavaScript: JSLint throws \"Read Only

跟風遠走 提交于 2019-12-03 01:19:07
My code: note: the Slider Object is declared but omitted in the snippet below for better readability "use strict"; /*global arrayContainer, SliderInstance, DomObjects */ arrayContainer = new Slider.constructArray(); SliderInstance = Object.beget(Slider); DomObjects = { animationContainer: document.getElementById('animationContainer'), buttonRight: document.getElementById('buttonRight'), buttonRightDots: document.getElementById('buttonRightDots'), ieEffectImg: document.getElementById('ie_effectIMG') }; This is what JSLint produces (and on the other two Objects SliderInstance and DomObjects)

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

Is there an offline version of JSLint for Windows?

只谈情不闲聊 提交于 2019-12-03 01:10:18
I would like to check my JavaScript files without going to JSLint web site. Is there a desktop version of this tool for Windows? Michael Burr From http://www.jslint.com/lint.html : The analysis is done by a script running on your machine. Your script is not sent over the network. It is also available as a Konfabulator widget . You can check a file by dragging it and dropping it on the widget. You can recheck the file by double-clicking the widget. It is also available in a WSH Command Line version. It is also available in a Rhino Command Line version. Or since JSLint is a JavaScript program

JavaScript: JSLint error “The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype”

北城余情 提交于 2019-12-02 20:15:27
I'm using the JSLint tool to ensure my JavaScript is "strict". I'm receiving the following error but don't understand how to fix it: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype For the following code: for (var i in keypairs) { ... } Anyone have any ideas how to fix this to that it's JavaScript "strict" and won't be flagged by JSLint Chris Baxter If keypairs is an array, then you should really iterate over the elements like: for(var i = 0; i < keypairs.length; i++) { ... } If keypairs is a hash, then JSLint is correctly recommending