jslint

Any tool to automatically fix simple JSLint issues? [closed]

北城余情 提交于 2019-11-28 19:50:01
问题 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 2 years ago . I've run JSLint for the first time on a rather lengthy file, and I have a lot of errors like expected exactly 1 space between "function" and "(" or unexpected ' ' . I didn't realize this was important at all anywhere I learned about javascript and now fixing each one of these rather simple things by hand seems

Is it possible to validate my jQuery JavaScript with JSLint?

≡放荡痞女 提交于 2019-11-28 18:54:26
问题 I wanted to check my JavaScript with JSLint. I am also using jQuery and JSLint seems to be very unhappy about jQuery. So, if I have this code: $(document).ready{ $("a").click(function() { // foo }); }); I am getting a few JSLint messages: Error: Problem at line 1 character 1: '$' was used before it was defined. $(document).ready{ ... I had a look at the options but I couldn't figure out how to tell JSLint that this is ok. If I had only one jQuery call in my code I could just ignore the JSLint

JSLint message: Unused variables

心不动则不痛 提交于 2019-11-28 18:30:38
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 appreciate all the suggestions but this code is simply an example to show you what I mean and I'm

What is the correct way to check if a global variable exists?

白昼怎懂夜的黑 提交于 2019-11-28 18:29:39
问题 JSLint is not passing this as a valid code: /* global someVar: false */ if (typeof someVar === "undefined") { var someVar = "hi!"; } What is the correct way? 回答1: /*global window */ if (window.someVar === undefined) { window.someVar = 123456; } if (!window.hasOwnProperty('someVar')) { window.someVar = 123456; } 回答2: /** * @param {string} nameOfVariable */ function globalExists(nameOfVariable) { return nameOfVariable in window } It doesn't matter whether you created a global variable with var

What is the reason behind JSLint saying there are “too many var statements”

*爱你&永不变心* 提交于 2019-11-28 17:43:00
JSLint (with the onevar flag turned on) is flagging some javascript code that I have with the following: Problem at line 5 character 15: Too many var statements. I am happy to fix these errors, but I'd like to know, am I doing it for performance or because it is just a bad practice and has a greater potential to introduce bugs in my javascript code. What is the reason behind the onevar flag? I did look at the JSLint docs for the var keyword but it doesn't specifically talk about why multiple var statements in the same function are bad. Here is an attempt at an example. Explain how the code

Solution for JSLint errors

陌路散爱 提交于 2019-11-28 16:42:22
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? 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 how jslint wants it to look like: (function() { /* code */ }()) I found a good explanation here: http://james

How do you use vim's quickfix feature?

自作多情 提交于 2019-11-28 13:21:27
问题 I'm a pretty new Vim user and I've found that its learning curve is quite steep (at least for me). I just installed this vim script for JavaScriptLint error checking, which shows errors in vim's quickfix window once I save a buffer. However, I don't know what to do next.. How do I 'scroll' through all the errors? How do I close the quickfix 'window'? How do I get it to check for errors after I've made changes to my code? I've looked at the vim quickfix docs but the amount of commands are

jslint error: Unexpected 'in'. Compare with undefined, or use the hasOwnProperty

好久不见. 提交于 2019-11-28 13:16:35
I have the following javascript function that fails a jslint check function hasActiveX() { return ('ActiveXObject' in window); } jslint error Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead. should I just live with the jslint error, or is there a better way to determine ActiveXObject? I could not find a jslint flag to skip this check? I think JSLint is asking you to try: function hasActiveX() { return window.hasOwnProperty('ActiveXObject'); } Or the other suggestion of comparing against "undefined": return (typeof(window.ActiveXObject) != "undefined");

JSLint with multiple files

我的梦境 提交于 2019-11-28 13:16:11
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? Nery Jr 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 command line: JSLint app.js JSLint lib / lib worker.js / server.js # Multiple files JSLint - white -

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

社会主义新天地 提交于 2019-11-28 12:04:37
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 opening { , not closing one. Can Javascript insert semicolon after closing } of if block even if next token