jslint

How to display all JavaScript global variables with static code analysis?

佐手、 提交于 2019-11-28 11:55:43
问题 I know that I can type into Chrome or FF the following command: Object.keys(window); but this displays DHTMLX stuff and also function names in which I'm not interested in. And it doesn't display variables in functions that have not been executed yet. We have more than 20,000 lines of JavaScript codebase, so I would prefer static code analyis. I found JavsScript Lint. It is a great tool but I don't know how to use it for displaying global vars. So I'm searching for memory leaks, forgotten var

Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function

懵懂的女人 提交于 2019-11-28 10:52:11
I have the following code: if (typeof console === "object" && typeof console.error === "function") { function e(msg) {"use strict"; console.info(msg);} } For which jsLint gives the following error: Function statements should not be placed in blocks. Use a function expression or move the statement to the top of the outer function. Why is it giving this error and what does it mean? You should not be creating function inside if block. You are much better off doing: var e = function(){}; if(typeof console === "object" && typeof console.error === "function"){ e = function (msg){ ... }; } KyleMit

Is a reversed switch statement acceptable JavaScript?

我是研究僧i 提交于 2019-11-28 07:57:09
问题 JSLint is complaining that (true) is a weird condition . Which is understandable if I wasn't using it on a reversed switch statement. So is JSLint wrong or should I not be using reversed switch statements? Thanks for any help/enlightenment. switch (true) { case (menuLinksLength < 4): numberOfColumns = 1; break; case (menuLinksLength > 3 && menuLinksLength < 7): numberOfColumns = 2; break; case (menuLinksLength > 6 && menuLinksLength < 10): numberOfColumns = 3; break; case (menuLinksLength > 9

How to tell JSLint not to ask for { on single line if statements

泪湿孤枕 提交于 2019-11-28 07:05:03
问题 Right now I have the following code: if (c > last) break; And jslint complains with jslint:crud.js:69:19:Expected '{' and instead saw 'break'. There are several ways to overcome it: if (c > last) { break; } or if (c > last) { break; } But I'd like jslint not to complain when the if statement is on the same line. Is there some way to configure it? BTW: I'm working with sublime text and the sublime-jslint plugin, with the following configuration: { // Path to the jslint jar. // Leave blank to

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

匆匆过客 提交于 2019-11-28 04:48:43
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 config/jshint.yml would be nice. For JSHint you can create .jshintrc to your project directory with {

Is there a working JSLint Eclipse plug-in?

☆樱花仙子☆ 提交于 2019-11-28 03:26:49
Can anyone point to a functioning JSLint plug-in for Eclipse? Martin There is a plugin here and it works ok. (site is down sometime in 2011) The update site is http://update.rockstarapps.com/site.xml (site down 2012-07-24) You can also run jslint4java as an external tool: Download jslint4java Put jslint4java.jar somewhere Add an external tool configuration in Eclipse (Run > External Tools > External Tools Configurations > Program > New...): Location: /usr/bin/java (or your path to javaw.exe) Arguments: -jar /path/to/jslint4java.jar ${resource_loc} Now you can select a js file in the Project

The “unexpected ++” error in jslint [duplicate]

三世轮回 提交于 2019-11-28 03:10:09
This question already has an answer here: Why avoid increment (“++”) and decrement (“--”) operators in JavaScript? 17 answers What is the best practice for that then? Jslint explains that it "adds confusion". I don't see it really... EDIT: The code, as requested: var all,l,elements,e; all = inElement.getElementsByTagName('*'); l = all.length; elements = []; for (e = 0; e < l; (e++)) { if (findIn) { if (all[e].className.indexOf(className) > 0) { elements[elements.length] = all[e]; } } else { if (all[e].className === className) { elements[elements.length] = all[e]; } } } unomi Use i += 1 instead

Unexpected token operator «=», expected punc «,»

核能气质少年 提交于 2019-11-27 23:36:52
问题 i am getting the following error Parse error: Unexpected token operator «=», expected punc «,» Line 159, column 26 This is my code function fitBounds(type="all", shape=null) { var bounds = new google.maps.LatLngBounds(); if ( type == "all" ){ if ((circles.length > 0) | (polygons.length > 0)){ $.each(circles, function(index, circle){ bounds.union(circle.getBounds()); }); $.each(polygons, function(index, polygon){ polygon.getPath().getArray().forEach(function(latLng){ bounds.extend(latLng); });

How can I change jslint(VS 2010 extension) to ignore files?

▼魔方 西西 提交于 2019-11-27 23:19:24
问题 I have js lint installed in Vs 2010 as a extension through the extension manager. It finds lots of errors but they are all from external plugins or from the jquery library. I am not going to go and fix stuff in an external plugin or jquery file. So how can I get it to not check these files? I am also wondering how can I get it to ignore checking href links. I am using asp.net mvc so my links are like this <a href="/account/reg">reg </a> So it can't find this path as it is the path to the

How come JQuery doesn't pass JSLint? [duplicate]

别来无恙 提交于 2019-11-27 23:18:00
问题 Possible Duplicate: What good is JSLint if jQuery fails the validation http://code.jquery.com/jquery-1.4.4.js Go to there and paste it in www.jslint.com Isn't Jquery supposed to be valid.... 回答1: It's far too much work to comply with it AND be cross-browser compliant. JSLint is useful but its only a generic parser. jQuery has good reasons to throw errors in it. Sometimes you just need simple dirty hacks to get code working in non-compliant browsers. let's look at them one by one : Problem at