jslint

jslint Import global variables from another file

时间秒杀一切 提交于 2019-12-01 06:45:24
Is there a way to use global variables declared in another js file when analyzing the file using jslint . Currently I have to declare all my global variables in the header, however that's really slow and not practical. /* global console, myglobalvar1, othervar... */ Is there a way to import the other script file like in Re-sharper? /// <reference path="my.js" /> JSLint is probably suggesting a useful code architecture improvement for you here, actually. Why not put all of those globals in the same namespace? Rather than... var Global1 = "spam", Global2 = 2; ... use... var MyStuff = MyStuff ||

jslint Import global variables from another file

岁酱吖の 提交于 2019-12-01 05:13:56
问题 Is there a way to use global variables declared in another js file when analyzing the file using jslint . Currently I have to declare all my global variables in the header, however that's really slow and not practical. /* global console, myglobalvar1, othervar... */ Is there a way to import the other script file like in Re-sharper? /// <reference path="my.js" /> 回答1: JSLint is probably suggesting a useful code architecture improvement for you here, actually. Why not put all of those globals

How to set 'use strict' globally with JSLint

谁说胖子不能爱 提交于 2019-12-01 03:31:48
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 yourLuckyNumber = prompt('Enter your lucky number (between 1 and '+ max +')'); var myLuckyNumber = Math.floor

Why does JSLint tell me to use “=== undefined” instead of “typeof … === 'undefined'”?

元气小坏坏 提交于 2019-12-01 03:11:52
I coded the following: showTitles = (typeof showTitles !== 'undefined') ? showTitles : 'Y'; showSelectGroup = (typeof showSelectGroup !== 'undefined') ? showSelectGroup : 'Y'; But JSLint is saying: Warning 3 JS Lint: Unexpected 'typeof'. Use '===' to compare directly with undefined. How should I change my code? Note that whether this is best practice in general is debatable, but if you want to make it work with JSLint, you could do this showTitles = (showTitles !== undefined) ? showTitles : 'Y'; Probably by using showTitles = (showTitles === undefined) ? 'Y' : showTitles; showSelectGroup =

Unexpected '++' in jslint [duplicate]

风格不统一 提交于 2019-12-01 00:01:32
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why avoid increment (“++”) and decrement (“--”) operators in JavaScript? The “unexpected ++” error in jslint jslint.com is giving me the error: Unexpected '++'. for this line: for (i = 0; i < l; ++i) { I tried i++ but no go. 回答1: JSLint does not like the increment and decrement operators. Replace it with i += 1 or add the plusplus: true directive to the top of your file (if you're not sure how to set JSLint

'debugger' command and JSLint

随声附和 提交于 2019-11-30 20:09: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 } 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: /*jslint browser:true, white: true, debug: true */ This error is raised to highlight a lack of convention and

Function was used before it was defined - JSLint

五迷三道 提交于 2019-11-30 17:56:38
JSLint does not like this code saying "'b' was used before it was defined" var a = function () { b(); }, b = function () { alert("Hello, world!"); }; a(); but perfectly happy with this var a, b; a = function () { b(); }; b = function () { alert("Hello, world!"); }; a(); But I am not defining anything in my second code snippet. I am merely declaring variable b. So why is JSLint doing this? Is there a reason I should be declaring all my functions first? PS I understand I could have just changed order of a and b, but in real project my functions are event handlers and sometimes they call each

jslint: why does this code result in a “Strict violation” error message?

谁都会走 提交于 2019-11-30 17:32:53
Running the following simple code results in a "Strict violation." error message. I have been trying to find documentation on why, and how to fix it. Any input will be much appreciated. The error: Error: Problem at line 6 character 4: Strict violation. } (this)); The sample code: /*jslint browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */ "use strict"; (function (window) { } (this)); Regards, Egil. I had a look at the source code of jslint, which says: function reservevar(s, v) { return

Run JSLint on a .js file from debugging console in chrome or firefox

孤人 提交于 2019-11-30 13:59:44
Is it possible to run JSLint on one or more .js files by having JSLint loaded afterwards in the header from debugging/developer console in chrome or firefox? The reason that I want to do that is that I want to print in console.log() the parsing of JSLint in JSON ,it says in documentation: // You can obtain the parse tree that JSLint constructed while parsing. The // latest tree is kept in JSLINT.tree. A nice stringication can be produced // with // JSON.stringify(JSLINT.tree, [ // 'string', 'arity', 'name', 'first', // 'second', 'third', 'block', 'else' // ], 4)); Cracker You can run JSLint on

“Use the array literal notation []” for var os_map = {}

跟風遠走 提交于 2019-11-30 12:08:57
I don't understand why I get the error message when I run JSLint with a JavaScript file. I get the message var os_map = {}; Problem at line 28 character 36: Use the array literal notation []. if I run this code in JSLint . The options for the JSLint as the following. /*jslint onevar: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */ Claiming object (, which is {} ) should be okay, but JSLint suggets to use an empty array (, which is [] ) : I found an answer. I was wrong. There's nothing wrong