jslint

JSLint validation for Javascript with JQuery

╄→гoц情女王★ 提交于 2019-12-06 09:27:40
问题 I am using JavaScript patterns with JQuery. I want JSLint to validate my code with maximum code quality. I have below screen shot for JSLint option to enable. Someone tell me what option should I check when coding JavaScript with JQuery. Please 回答1: Check the assume a browser checkbox and on the Predefined section, type jQuery and $ . 来源: https://stackoverflow.com/questions/10557583/jslint-validation-for-javascript-with-jquery

jslint - Don't make functions within a loop

白昼怎懂夜的黑 提交于 2019-12-06 04:39:09
问题 Refering to this topic: Don't make functions within a loop. - jslint error How would you handle a jquery .each(function () {...} within a for loop? knowing that i need the context of the "for" in my "each" function. Sure I could map every required to parameters to a function a function declared outside of the loop but from my perspective, it impacts the readability. Any thoughts? Thanks in advance. 回答1: Well, you can keep the context of the for in your loop, as everything in the for is

JSLint complains about redefining undefined

只谈情不闲聊 提交于 2019-12-06 03:10:56
问题 undefined is technically able to be redefined, so it is not a reserved word. As a result, I usually write code in an anonymous function that forces undefined to be an undefined variable, as so: (function (undefined) { "use strict"; var o = { test: "testvalue" }; if (o.test === undefined) { // Do stuff here } else { // Do other stuff there } }()); However, JSLint mentions the following error: Problem at line 1 character 15: Expected an identifier and instead saw 'undefined' (a reserved word).

javaScript reserved keywords

一曲冷凌霜 提交于 2019-12-06 01:35:48
问题 I am wondering how JavaScript's reserved keywords / functions are managed. Example: According to: http://www.quackit.com/javascript/javascript_reserved_words.cfm delete is a reserved keyword by JavaScript. Then consider the following snippet for some context: var cookieManager = { get: function (name) { // function contents ... console.log("cookieManager.get() called"); return true; }, set: function (name, value, days) { // function contents ... console.log("cookieManager.set() called");

JSLint says new keyword is missing [duplicate]

落花浮王杯 提交于 2019-12-05 17:09:23
This question already has an answer here: How to fix JSLint “missing new” error 2 answers Let's say I have some JavaScript that looks like this: function A() { var MyVar, SomeParameter; // do work MyVar = FunctionB(SomeParameter); } JsLint says I'm Missing 'new'. at the line MyVar = FunctionB(SomeParameter); Why should I rewrite as MyVar = new FunctionB(SomeParameter); Is there going to be any benefit? It is the convention that constructors (eg: Array , Object ) are starting with a capital. JSLint complains, because it thinks that you're trying to use a constructor, without new keyword. To fix

Expected ';' and instead saw ','. - JSLint multivar setting

我与影子孤独终老i 提交于 2019-12-05 15:02:45
问题 As of about 14 January 2016, JSLint has started complaining about var or let declarations that have more than one variable per declaration, and has created a new directive, multivar that ignores this new "problem". This is a pretty significant change, as earlier versions would complain if you did have two var s in the same code block. That is, as of today (18 Jan 2016), this code now breaks in JSLint: /*jslint white:true, browser:true, devel:true */ function a(b) { "use strict"; var c, d; //

How to disable JSLint ES6 errors with const and let in Adobe Brackets?

人盡茶涼 提交于 2019-12-05 13:45:58
I have Googled and looked through this site everywhere, but I can only find answers for JSHint instead of JSLint. To get rid of the "use function form of use strict" error I add in /*jslint node: true */ . But to disable errors for using const and let I can't seem to find anything. JSHint has esversion: 6 but this doesn't work on JSLint. Use the Preferences API: var PreferencesManager = brackets.getModule("preferences/PreferencesManager"); prefs = PreferencesManager.getExtensionPrefs("jslint"); prefs.set("options.es6", true); Or set it one of the config files: the brackets.json file of the

Javascript Regex to specify what is allowed (rather than what is not)

落花浮王杯 提交于 2019-12-05 12:09:58
I've been using this: str2 = str1.replace(/[^\w]/gi, ''); It works fine, but falls foul of JSLint for having an insecure '^' as outlined in the posts here and here . The consensus is that it is better to use your regex to specify what is allowed rather than what is not. No one ever demonstrates how to do this, however. I've even got Flanagan and Crockford in front of me here, but to my shame I'm still not sure what to do. So... how do you set str2 to only allow the \w characters found in str1 using a positive test rather than a negative one? Try with \W (capital W). The \w selects word, while

How to fix JSLint “missing new” error

老子叫甜甜 提交于 2019-12-05 11:13:14
问题 Code below passed through JSLint causes an error: Problem at line 8 character 9: Missing 'new'. ResizeGrid(); How to fix? "use strict"; var ResizeGrid; function t() { var x; if (x) { ResizeGrid(); } } 回答1: Tick Tolerate uncapitalized constructors or rename to resizeGrid(); to prevent lint from assuming its a function constructor (although calling an undefined var like that will raise other errors). 回答2: You should name functions with a lower case initial letter, unless they are intended as

JSLint mixed spaces and tabs error

落爺英雄遲暮 提交于 2019-12-05 09:24:09
问题 I have run the following through JSLint: $(document).ready(function() { /* Add paragraph on page load */ // Get all header elements var header = document.getElementsByTagName('h1'), parent, newP, text; // Loop through the elements for (var i=0, m = header.length; i < m; i++) { parent = header[i].parentNode; newP = document.createElement("p"); text = document.createTextNode('This paragraph was inserted with JavaScript!'); newP.appendChild(text); // Insert the new P element after the header