jslint

How can I use JSLint for a segment of code which depends on JQuery?

别来无恙 提交于 2019-12-12 14:24:49
问题 I'm relatively new to Javascript, and I'd like to run the piece of code I spent the weekend playing with through JSLint so that it can point out where I was being a total idiot :) Unfortunately, I get tons of errors about missing function declarations, which are part of the JQuery javascript library and various plugins for it. Is there any way I can run such code through JSLint? 回答1: If you're using the web version of jslint, you can simply add the $ object in the predefined option: If you're

Can I prevent passing wrong number of parameters to methods with JS Lint, JS Hint, or some other tool?

本小妞迷上赌 提交于 2019-12-12 10:46:03
问题 I'm new to javascript programming (and scripting languages in general), but I've been using JS Lint to help me when I make syntax errors or accidentally declare a global variable. However, there is a scenario that JS Lint does not cover, which I feel would be incredibly handy. See the code below: (function () { "use strict"; /*global alert */ var testFunction = function (someMessage) { alert("stuff is happening: " + someMessage); }; testFunction(1, 2); testFunction(); }()); Notice that I am

JSLint doesn’t expect my tildes

大城市里の小女人 提交于 2019-12-12 09:35:11
问题 JSLint insists that my use of the somewhat exotic tilde operator in the below example is unexpected. What I’m wondering is whether this is a limitation of JSLint? or strict mode? or what else am I missing? (function () { 'use strict'; if (~'foo'.indexOf('bar')) { return 'wild accusations'; } }()); Also, why shouldn’t I use the simple-looking tilde operator instead of the more complex example below? Surely there must be a good reason not to? if ('foo'.indexOf('bar') >= 0) { … } 回答1: From the

JSLint : Expected '!!' and instead saw '?'

偶尔善良 提交于 2019-12-12 05:59:14
问题 I am getting the error in the question mark. Here is the code var isParallelStage = ($("#workflowStagesList .workflowStageListItemActive").find("p").text() === "P") ? true : false; Error: JSLint : Expected '!!' and instead saw '?'. 回答1: ? true : false is an antipattern - it's totally useless, an identity function, you can simply omit it, you've already got a boolean. And if you didn't, you should use !! or Boolean(…) to cast your value to a boolean. 来源: https://stackoverflow.com/questions

Fix error in spectrum color picker

跟風遠走 提交于 2019-12-12 05:47:43
问题 I implemented spectrum color picker, and I'm trying to fix up the JSLint errors. I have 2 types of errors which I can't seem to fix. Here are the errors 'var' was used before it was defined Move the invocation into the parens that contain the function Here's the code with the errors: (function (factory) { "use strict"; if (typeof define === 'function' && define.amd) { // AMD define(['jquery'], factory); } else if (typeof exports === "object" && typeof module === "object") { // CommonJS module

Using JSLint in Java/GWT

巧了我就是萌 提交于 2019-12-11 14:02:44
问题 I'm currently working on a project in Java, that will allow users to type Javascript code into a GWT Widget. How would I go about importing/using JSLint to check for errors? I looked around and found LSLint4Java, but I couldn't find the way to import it into eclipse. I just need a simple JS error checker that will check a string for errors. If anyone has any other suggestions for error checking, please share them! Thanks. 回答1: The JSlint javascript source can be found here. You could include

JSLint Type Confusion: function and object with jQuery .css()

假如想象 提交于 2019-12-11 13:17:07
问题 I am having difficulty getting these lines to validate using JSLint. I'm assuming (perhaps incorrectly) that they are actually valid. Here is the relevant code: var shadowBox = $('<div/>').appendTo($(document.body)); // ... shadowBox.css({ left: (e.originalEvent.clientX + 10).toString() + 'px', top: e.originalEvent.clientY.toString() + 'px' }); The validation errors I am getting are: Problem at line 492 character 22: Type confusion: function and .css: object. shadowBox.css({ and Problem at

Silencing JSLint warnings in brackets

∥☆過路亽.° 提交于 2019-12-11 10:16:01
问题 I just started a gulp-angular Yeoman project and opened it in brackets, and nearly everywhere I'm getting 'something' was used before it was defined , specifically 'angular' was used before it was defined . I've messed around with extensions and other fixes, but I honestly don't know what I'm doing and I haven't been able to find any good documentation. What can I do to silence these warnings across the entire project? In other words, how can I avoid using /*global angular*/ in pretty much

Fail on Post-Build event?

白昼怎懂夜的黑 提交于 2019-12-11 07:44:56
问题 Is there a way to force the build to fail given certain conditions in the post-build event? The package I'm working with runs jslint and a few other solutions all together on post-build, I would like Visual Studio to fail if jslint produces an error. I am aware of the jslint plugin for VS2010 that will fail the build on error, but my requirements are restricting me to using the packaged bugchecking solution in which jslint is contained. 回答1: Post build events are basically batch scripts - you

Why does JSLint restrict the use of HTML event handlers?

守給你的承諾、 提交于 2019-12-11 06:46:01
问题 Using the "Good Parts" defaults on JSLint, the use of HTML event handlers (such as onclick) is not allowed. What is the logic behind this? What is bad about them that should be avoided? 回答1: Using the "Good Parts" defaults on JSLint, the use of HTML event handlers (such as onclick) is not allowed. The use of event handlers in the actual markup is flagged, yes: <div onclick="..."> This is generally considered bad practice. Mixing scripting behaviour into markup is hard to read and manage;