jslint

JSLint message: Unused variables

大憨熊 提交于 2019-11-27 11:25:16
问题 what can I do if JSLint complains about "i" being an unused variable in such a scenario: var items = "<option selected></option>"; $.each(data, function (i, item) { items += "<option value='" + item.Value + "'>" + item.Text + "</option>"; }); (i, item) is the required order of parameters and I'm only using "item". Is there any other solution than tolerating unused variables or rewriting the $.each to use the index, both solutions which I would prefer not to do? Thanks in advance. Update: I

Solution for JSLint errors

泪湿孤枕 提交于 2019-11-27 09:52:03
问题 I have started using JSLint. I checked my code and I am getting this errors: Problem at line 92 character 7: Move the invocation into the parens that contain the function. })(); Problem at line 92 character 7: Wrap the entire immediate function invocation in parens. })(); How To Fix this errors? 回答1: I believe this means you should move the function calling parens inside the wrapping parens (function() { /* code */ })() The two last parens that execute the function are the problem. This is

JSLint with multiple files

走远了吗. 提交于 2019-11-27 07:34:18
问题 JSLint works fine for just one JavaScript file. Recently, I've started breaking my program into several pieces. I don't want to be stringing the pieces each time I use JSLint to check my code. What is the standard solution to deal with multiples files with JSLint? 回答1: There is a version of JSLint (node-JSLint) (command line) that allows you to check multiple files at once. Follow link for download at GitHub: https://github.com/reid/node-jslint The following examples of calling via the

JSLint: control comments (selective ignore)

白昼怎懂夜的黑 提交于 2019-11-27 07:23:25
Does JSLint have anything like JavaScript Lint's control comments (e.g. /*jsl:fallthru*/ ) to make it ignore certain passages? napoleonss Put /*ignore jslint start*/ before and /*ignore jslint end*/ after the code to be ignored. Ex: function ignore(){ /*ignore jslint start*/ var x; var y; /*ignore jslint end*/ } Or export JsLint settings, define your IgnoreErrorStart/ IgnoreErrorEnd symbols and import. Edit Some folks may confuse this answer with JSHint. In that case, use these: /*jshint ignore:start*/ <!-- code in here --> /*jshint ignore:end*/ Taken from https://stackoverflow.com/a/26012357

JSLint: Using a function before it's defined error

倾然丶 夕夏残阳落幕 提交于 2019-11-27 07:02:25
I'm using JSLint to verify most of my external Javascript files, but the largest amount of errors I'm getting is from functions being used before they're defined. Is this really an issue I should worry about ? It seems Firefox, IE7 and Chrome don't care. Functions like the popular init() (which I use often) normally stick at the top as that makes sense to me (I like to pretend it's analogous to main() ) will, according to JSLint, need to be pushed to the bottom of the file. Steve Harrison If you declare functions using the function keyword, you can use them before they're declared. However, if

JSLint: was used before it was defined

半世苍凉 提交于 2019-11-27 06:56:28
Hi I have the 3 javascript files. jquery.js utility.js file1.js In file1.js I have jQuery.noConflict() jQuery(document).ready(function($) { // .... }); I get an error 'jQuery' was used before it was defined. and 'document' was used before it was defined. How do I safely get rid of this warning. If I do var document = document || {}; then in my utility.js if it is used, it would be null in IE and ok in firefox. What is the best solution to this? From the documentation JSLint also recognizes a /*global */ directive that can indicate to JSLint that variables used in this file were defined in

JSLint, else and Expected exactly one space between '}' and 'else' error

半世苍凉 提交于 2019-11-27 06:43:25
问题 Why JSLint report in code: function cos(a) { var b = 0; if (a) { b = 1; } else { b = 2; } return b; } error: Problem at line 6 character 5: Expected exactly one space between '}' and 'else'. This error can be turned off by disabling Tolerate messy white space option of JSLint. Or in other words -- why syntax: } else { is better then ... } else { ... Google also uses syntax with } else { form. But I don't understand why. Google mentioned ''implicit semicolon insertion'', but in context of

JSLint says “missing radix parameter”; what should I do?

我只是一个虾纸丫 提交于 2019-11-27 05:54:53
I ran JSLint on this JavaScript code and it said: Problem at line 32 character 30: Missing radix parameter. This is the code in question: imageIndex = parseInt(id.substring(id.length - 1))-1; What is wrong here? Jayendra It always a good practice to pass radix with parseInt - parseInt(string, radix) For decimal - parseInt(id.substring(id.length - 1), 10) If the radix parameter is omitted, JavaScript assumes the following: If the string begins with "0x", the radix is 16 (hexadecimal) If the string begins with "0", the radix is 8 (octal). This feature is deprecated If the string begins with any

JSLint error: Move all 'var' declarations to the top of the function

假装没事ソ 提交于 2019-11-27 04:08:48
JSLint site updated, and I cannot check JS scripts anymore. For me, this warning is not critical, and I don't want to go through thousands of lines to fix this, I want to find more critical problems. Does anybody know how to turn off this error, or use legacy JSLint? UPDATE Example: function doSomethingWithNodes(nodes){ this.doSomething(); for (var i = 0; i < nodes.length; ++i){ this.doSomethingElse(nodes[i]); } doSomething(); // want to find this problem } jslint.com output: Error: Problem at line 4 character 8: Move all 'var' declarations to the top of the function. for (var i = 0; i < nodes

Why should you not use Number as a constructor? [duplicate]

一个人想着一个人 提交于 2019-11-27 04:04:55
This question already has an answer here: Why to avoid creating objects in JavaScript? 2 answers I entered this statement in JSLint: var number = new Number(3); And received the following message: Do not use Number as a constructor. Why is that? The statement is creating a number object, not a primitive value, so I don't see why using new is a problem. EDIT: Thanks for all the responses. They've got me thinking further, so I posted a follow-up question here . In addition to breaking === and typeof returning "object", using the Number constructor also changes the way the value is used in