jslint

What side effects does the keyword 'new' have in JavaScript?

六眼飞鱼酱① 提交于 2019-12-03 15:04:57
问题 I'm working on a plug-in for jQuery and I'm getting this JSLint error: Problem at line 80 character 45: Do not use 'new' for side effects. (new jQuery.fasterTrim(this, options)); I haven't had much luck finding info on this JSLint error or on any side effects that new might have. I've tried Googling for "Do not use 'new' for side effects." and got 0 results. Binging gives me 2 results but they both just reference the JSLint source. Hopefully this question will change that. :-) Update #1: Here

How to rectify “Document was used before it was defined” using Jslint

馋奶兔 提交于 2019-12-03 14:43:17
问题 I get the following error in jsLint : 'document' was used before it was defined. Line that causes the error: document.cookie = name + "=" + value + expires + "; path=/"; I get why this happens, but I would like my code to be compliant. How do I resolve this? Thanks. 回答1: Place /*jslint browser:true */ in the beginning of the body of your function. Or, alternatively, you may use /*global document: false */ JSLint is for the checking of any javascript code, and the document global object does

Expressions in JavaScript Ternary Operator and JSLint

风格不统一 提交于 2019-12-03 10:52:07
问题 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

Unexpected 'continue'

China☆狼群 提交于 2019-12-03 10:46:26
I have: while (i < l) { if (one === two) { continue; } i++; } But JSLint says: Problem at line 1 character 20: Unexpected 'continue'. if (one === two) { continue; } What mistake did I make? How should my code really look? From the JSLint docs : continue Statement Avoid use of the continue statement. It tends to obscure the control flow of the function. So take it out entirely if you want to conform to the conventions that JSLint follows. What JSLint actually tries to say is to invert the if so you can eliminate the continue: while (i < 1) { if (one !== two) { i += 1; } } Furthermore, don't use

How do I change Eclipse to use spaces instead of tabs in Javascript editor?

不羁岁月 提交于 2019-12-03 09:47:55
I use the Eclipse JavaScript plugin, I have my text editor settings to "insert spaces as tabs" this works fine until I select a block of code and tab it or shift tab it, run JSLint and AARGghh! "Mixed spaces and tabs." is there something I am missing, is this possible? Hauke Ingmar Schmidt I am not exactly sure where you set the editor property "insert spaces as tabs". To set the tab policy you need to go to Window > Preferences > Javascript > Code Style > Formatter , create a new profile, edit it and set the Tab policy to "spaces only". Now when using the tab key spaces are inserted. 来源:

How do I install JSLint on Ubuntu? [closed]

不打扰是莪最后的温柔 提交于 2019-12-03 08:17:18
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . How do I install JSLint on Ubuntu? I downloaded the source jsl-0.3.0-src.tar.gz from http://www.javascriptlint.com/download.htm and then extracted it to a dir called jsl-0.3.0 on my Desktop. I then moved it to /usr/local/bin which I have read is my PATH. I also want to mention that I have Rhino 1.7 installed

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-03 06:36:54
问题 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 回答1: If keypairs is an array, then you should really iterate over the elements like: for(var i = 0;

Dealing with duplicate declaration warning for loop variables

[亡魂溺海] 提交于 2019-12-03 06:28:33
问题 Consider the following code: for (var i=0; i<100; i++) { // your code here } // some other code here for (var i=0; i<500; i++) { // custom code here } Any decent lint tool (jslint, jshint or built in IDE) will tell warning - duplicate declaration of variable i . This can be solved by using variable with another name ( k , j ) or moving declaration to the top: var i; // iterator for (i=0; i<100; i++) {} for (i=0; i<500; i++) {} I am not fond of both variants - I don't make declarations at the

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

我与影子孤独终老i 提交于 2019-12-03 06:27:46
问题 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

How to rectify “Document was used before it was defined” using Jslint

↘锁芯ラ 提交于 2019-12-03 05:29:05
I get the following error in jsLint : 'document' was used before it was defined. Line that causes the error: document.cookie = name + "=" + value + expires + "; path=/"; I get why this happens, but I would like my code to be compliant. How do I resolve this? Thanks. penartur Place /*jslint browser:true */ in the beginning of the body of your function. Or, alternatively, you may use /*global document: false */ JSLint is for the checking of any javascript code, and the document global object does not exists everywhere, so you have to manually tell JSLint that your code is aimed to be executed in