jslint

JSLint “out of scope” error due to function ordering?

最后都变了- 提交于 2019-12-19 18:57:09
问题 JSLint seems to be picky about function ordering. This passes fine: function a() { 'use strict'; return 1; } function b() { 'use strict'; a(); } While this gives an 'a' is out of scope error message: function b() { 'use strict'; a(); } function a() { 'use strict'; return 1; } Is this by design? Should I care? How can it be avoided in larger (more complex) cases, where it might not always be possible to give the functions a clear order? 回答1: JSLint/JSHint expect you to define functions before

Don't make functions within a loop. - jslint error

。_饼干妹妹 提交于 2019-12-19 08:57:06
问题 I am getting this jslint error Don't make functions within a loop. I can't change the javascript that is causing this issue - however I cant, due to restrictions from modifying it. So, I want to turn this validation to check for this error off in a particular javascript file. Is this possible to do for this js error? 回答1: No, that valildation check is not optional. A possible workaround: // simple closure scoping i to the function. for(var i = 0; i < 10; i++) { (function (index) { console.log

How to set 'use strict' globally with JSLint

大憨熊 提交于 2019-12-19 05:44:50
问题 I'm new to javascript and am trying to validate through JSLint. Where should I put "use strict" to use it globally and validate? This gives me error "Unexpected expression 'use strict' in statement position.": "use strict"; console.log('doing js in head-section'); function helloWorld() { console.log('called function helloWorld()'); alert('Hello World from a JS function showing an alert!'); } function helloMyNumber() { console.log('called function helloMyNumber()'); var max = 42; var

how to fix jslint The '&&' subexpression should be wrapped in parens error

风格不统一 提交于 2019-12-19 03:42:25
问题 I put everything in parentheses but code below still throws error in jslint: Problem at line 5 character 104: The '&&' subexpression should be wrapped in parens. if ((typeof (c1) === 'string') && (typeof (c2) === 'string') && (c1 !== n... How to fix ? "use strict"; function t() { var c1, c2; if (((typeof (c1)) === 'string') && ((typeof (c2)) === 'string') && (c1 !== null) && (c2 !== null) && ((c1.trim()) === '') || ((c2.trim()) !== '')) { return; } } 回答1: It's complaining about the form if(a

'debugger' command and JSLint

我们两清 提交于 2019-12-19 01:45:51
问题 Google Chrome supports debugger command as a tool to setup a breakpoint in code. How can I hide warnings for the following code in JSLint: /*globals $, console, */ /*jslint browser:true, white: true */ function test() { "use strict"; debugger; // JSLint reports the "Unexpected 'debugger'" error } 回答1: JSLint has an explicit option to tolerate debugger statements, called debug : debug : true if debugger statements should be allowed. You can specify this option via your jslint directive: /

Expected an assignment or function call and instead saw an expression

孤人 提交于 2019-12-18 10:48:38
问题 I'm totally cool with this JSLint error. How can I tolerate it? Is there a flag or checkbox for it? You get it when you do stuff like: v && arr.push(v); as opposed to: if (v) { arr.push(v); } Both do the same exact thing. If you put: window.test = function(v) { 'use strict'; var arr = []; if (v) { arr.push(v); } return arr; }; into the minifier it minifies down to this anyway: window.test=function(a){var b=[];a&&b.push(a);return b}; 回答1: I don't think JSLint has an option to turn that off.

Maven plugins to analyze javascript code quality

余生长醉 提交于 2019-12-18 10:42:59
问题 Javascript code can be tough to maintain. I am looking for tools that will help me ensure a reasonable quality level. So far I have found JsUNit, a very nice unit test framework for javascript. Tests can be run automatically from ant on any browser available. I have not found yet some javascript equivalent of PMD, checkstyle, Findbug... Do you know any static code analysis tool for javascript ? 回答1: This is an old thread, but if you're interested in running Jasmine for BDD testing in your

JSLint error: Expected 'ignore' and instead saw 'ex'

馋奶兔 提交于 2019-12-18 05:35:10
问题 I use JSLint all the time, but just today, I came across an error that I've never seen before. With the following code, I got the error shown below: try { document.execCommand('BackgroundImageCache', false, true); } catch (ex) {} Error: Expected 'ignore' and instead saw 'ex'. } catch (ex) {} So I changed my code to the following, and the error went away: try { document.execCommand('BackgroundImageCache', false, true); } catch (ignore) {} I can't find any explanation on the Internet regarding

JSLint error: Expected 'ignore' and instead saw 'ex'

人盡茶涼 提交于 2019-12-18 05:35:02
问题 I use JSLint all the time, but just today, I came across an error that I've never seen before. With the following code, I got the error shown below: try { document.execCommand('BackgroundImageCache', false, true); } catch (ex) {} Error: Expected 'ignore' and instead saw 'ex'. } catch (ex) {} So I changed my code to the following, and the error went away: try { document.execCommand('BackgroundImageCache', false, true); } catch (ignore) {} I can't find any explanation on the Internet regarding

How to tell JSLint / JSHint what global variables are already defined

女生的网名这么多〃 提交于 2019-12-17 17:42:30
问题 In my project we have some global variables that work as containers: MyProject.MyFreature.someFunction = function() { ... } So then I use that script across the site and JSLint / JSHint complains about that: 'MyProject' is not defined I know that I can go to every JavaScript file and add the comment /*global MyProject*/ on top of it. But I'm looking a way to define that comment in some sort of config file so I don't have to go file by file adding this comment. Some kind on option in the