With this article, I wanted to do something completely different from my previous two. If you've read them, you saw that they are detailed descriptions of respective topics – somewhat like guides that arm you with complete knowledge on a subject.
The problem with that is – you leave the reader without something solid. You just can't write "Guide to .NET Reporting" that'll design reports that the reader needs. So, this time, I wanted to provide you with something you can use on a daily basis, without needing to chew on knowledge presented here or tailor it to fit your needs. I wanted to do something short, sweet, and immediately useful.
In choosing the topic, I was somewhat selfish. During the years of my coding, there was nothing that caused me more joy and pain at the same time than JavaScript development. I mean, every time I needed to code some JavaScript, it was like getting a crush on a bad kinky girl – you are taken in by the charm while thinking that a few tricks will do the job... but as soon as you commit yourself, the situation gets messy and you start to feel lost and depressed.
With girls, I have developed an arsenal of excuses (she is into money, she likes guys who treat her like garbage, and so on), but with JavaScript, just one – being no one's child, JavaScript is left without tools that support proper development.
Happily for me, during one late night browsing session, I stumbled upon JavaScript video tutorials from Douglas Crockford. Old man simply 0wnZ; if you haven't seen them, and you are into JavaScript, then stop wasting time – open up a few packages of popcorn and watch the videos (The JavaScript Programming Language, Theory of the DOM, Advanced JavaScript). You'll save tons of time that would otherwise be spent on reading lousy written JavaScript books/tutorials or Googling for explanations of copy-pasted code statements that you just can't get into.
Besides being great for explaining JavaScript, they've lead me to JSLint, a useful tool that provides verification of JavaScript code, thus shortening periods you spend in browser testing your scripts, enabling you to be more productive. After seeing it in action, I immediately started thinking on how to integrate it with Visual Studio.
I wanted to provide users with the ability to JSLint a file, code section, or integrate JavaScript verification with a build.
Here is the JSLint.VS in action on a file:

And, here it is validating a code statement:

Finally, here is JSLint.VS in action when the programmer decides to Build Solution:

JSLint.VS is a pretty standard Visual Studio add-in. I won't go into the basics, so if you lack knowledge about add-ins, you'll probably want to read an article like this to catch on the concepts.
As in any Visual Studio add-in, Connect is the main class that handles the events of Visual Studio and executes the commands. In this project, it is used to register JSLint entries into VS context menus, catch changes to JavaScript files, notify other classes when Building of a Solution is started, and so on...
OptionsForm is the interface with the user, enabling the configuration of JSLint.VS. You can see it in action in the image below:

Finally, JSLintProcessor is the class that does the main work – on the Build event / user request (Connect.cs) to lint file, it builds the error list using the selected options (OptionForm.cs). The biggest problem was to figure out what to use for running the JavaScript code. After ditching the idea of having a hidden browser window reference in this class (it just sounds horrible, doesn't it?), I turned to the Windows Script Host. As WHS process takes some time to start, it is practically impossible to start an individual WSH process for every JavaScript lint file in big projects. So, during checking, I join all the scripts into one big temporary lint file, and then split results to provide links to the original scripts in the Task list.
To sum up everything said, here is the class diagram showing the main parts of the previously mentioned classes. You can also notice the additional, less important, helper classes – for holding data (FileDataHolder, JSLintOptionsItem) and serializing JSLint options to hard disk (DictionarySerializer).

I left lots of comments in the code, so I'm sure that you'll manage on your own if you are into further extending this add-in. Requesting features through comments that I'll implement for you is always an option.
As said in the introduction, I hope that reading this article enriched your development arsenal with one useful tool. Before leaving you to play with the source code, one final word of warning – as Douglas said in one of his speeches – JSLint will probably insult you. If you are an average JavaScript coder, in the first few runs, you'll be buried with errors, so be ready on JSLint notifications that tell you - your code is crap.
On the other hand, every error is followed by a concise description of the problem (while this website contains detailed explanations on why something is preferred) – meaning that by fixing errors, you'll develop nice JavaScript coding habits. The more of us have those, the more understandable and maintainable JavaScript code we'll see in the future... enabling us easier sharing and learning, while trying to live up to the big hype that surrounds Web 2.0.
- January 28, 2009 - Bugfixes related to build integration, CodePlex page (thanks to Alexander Turlov & Frederick Staats)
- December 11, 2007 - Updated add-in to support Visual Studio 2008, a few small bug fixes.
- November 25, 2007 - Initial version of the article.
| You must Sign In to use this message board. |
|
|
 |
|
 |
OK, maybe I'm an idiot, but how do you access the settings screen???
I'm running the pre-compiled binaries under VS 2008, tried both with and without SP1, is this something that changed with plugins in 2008?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
This has the potential to be a fantastic tool, if it worked a bit better. I know the guy who wrote it originally appears to have moved onto bigger and better things, so I wonder if anyone else has the ability and time to take on this project and push it forward?
3 things I noticed so far, are:
1) Scott Mitchell's discovery of the .JS associations being hijacked, preventing JSLint.VS from working (http://scottonwriting.net/sowblog/posts/13995.aspx)
2) The logic surrounding lower level folders and solution folders, e.g. if you have a solution containing Tests, Web, Libraries, Solution Files, Services, with your actual projects inside these solution folders, then JSLint.VS options only lists the top level solution folders, and not the projects below them.
Similarly, if you structure your js files in the following way root/js/jquery/plugins, JSLint.VS options only allows you to check the /js level, and nothing below it.
3) I'm now seeing an issue where the first pass of the JSLint.VS process returns over 700 errors, but if I then try to re-run the process, it initially shows 700 errors before quickly reducing in errors back to 0, before hanging.
4) As it's using the old JSLint.js edition, and a newer edition is out, it would be nice to use the new version and include the new options.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
--------------------------- Microsoft Visual Studio --------------------------- The Add-in 'JSLint.VS - The JavaScript Verifier for Visual Studio' failed to load or caused an exception. Would you like to remove this Add-in? If you choose yes, the file it was loaded from, 'C:\Documents and Settings\FSCHENK\My Documents\Visual Studio 2008\Addins\JSLintJsLint.AddIn', will be renamed.
Error Message: Unspecified error
Error number: 80004005 --------------------------- Yes No --------------------------- I answer Yes, VS2008 starts then, but there is nothing in Tools-->Add-in Manager, and no ontext menu for .js files Sorry, please help
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry, but I have to confirm this. I did exactly the same as intrader. The only difference is that I get error number 80131604. I have a standard VS 2008 installation (in German - may that cause problems?)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I've followed the instructions, I'm getting the add-in showing up and enabled in VS, and I'm able to JSLint a code fragment through the context menu, however, no menu item to check a file? And when I do a build, just says no errors found - even though one of the files is the one I'd just done a fragment lint on...
Is there something I'm missing?
EDIT: Seems that's it's cooooooompletely nerfed - it's just told me that var pos = tmp.indexOf ('UTC', 0); is "missing whitespace after 'i'", and selecting a fragment for linting has just done the whole file?!?!?!
C# has already designed away most of the tedium of C++.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In the options there are such as "Assume a Yahoo Widget" and "Assume a Rhino". I suppose those are favorites of the JSLint author and it's understood. But since the plug-in is for VS and .NET web development doesn't it make sense to add something like "Assume Microsoft Ajax" and "Assume Ajax Control Toolkit"? Some people may ask about jQuery too
Alexander Turlov MCSD.NET
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Those are exposed because Douglas has those options for JSLint.
I guess if we wanted to add Assume Microsoft Ajax and Assume Ajax Control Toolkit I need to speak with him about adding them to JSLint (or some of us should dig into jslint.js, implement stuff and then merge with him).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
With JavaScript development getting into the list of regular web development tasks there are still not so many tools out there to help developers with catching bugs and typos. Even with the VS 2008 JS intellisense support it's just a little easier. And it's really annoying when you have to run your web site under the debugger to find out just a few annoying typos that break the whole page. So your work is really on time!
A suggestion: haven't you thought to move your project over some web site that hosts open source projects or code, like Codeplex, Microsoft Code, sourceforge, etc.? It may be much easier to keep your project up to date, communicate to the community and achieve much greater visibility too.
Once again, thanks for a nice job.
Alexander Turlov MCSD.NET
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I was really excited when I wrote this tool because back then I've done lots of JavaScript development, and as you say - it's nice when you are able to catch bugs and typos without firing up browser.
However, during the time I've switched onto other technologies and lost time to support JSLint. I could upload it to CodePlex but I doubt there is broad interest in keeping library going forward. I might, however upload new version of source to the article because I've implemented couple of bugfixes (thanks to Joseph Schrag who provided testing).
In any case, thanks for your comments and praises.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I agree that this has been very helpful for me too. I do frequent JSLint checking on JavaScript integrated into my VS2008 development environment.
I just spent the day upgrading the latest posted JSLint.VS to use the current Edition 2009-01-22 of the tool from Dougless (and all the new options) from http://jslint.com. I've also updated the solution and project to be VS2008 based.
I've noticed a some bugs related to the build integration (sometimes it seems to work and sometimes it doesn't.) I'm wondering if the bugs you are talking about are related to the build integration?
I'm interested in any bug fixes you may have and can share the updates I've made if you are interested.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Yes, bugfixes are exactly targeted at build integration (I've missed event subscription in OnConnect method).
As Alex suggested I've opened CodePlex site and posted code with fixes there -> http://www.codeplex.com/jslint[^].
I will provide anyone interested with access and help on how to set VS to access/check-out/check-in files... So if you wish to merge your changes just send me your Codeplex username and I'll give you full access to repository.
P.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This is a great article but it looks like the project has been converted to 2008. Do you still have the 2005 version around for those of us that have not been able to upgrade?
thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry, this is working fine for me in VS 2005. The problem seems to be that I am running Windows in a strange mode and Visual Studio was not loading Addins correctly. After I setup Windows the right way then everything started working great.
Thanks again for such as useful tool.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I am using VS2005, and I installed it as stated in the install.txt file. When I start VS2005 I have the addin, I can select javascript and I can right click - JSLint Selected Fragment.
But what I put, it always is saying that it didn't find any error. And I know for sure that the javascript code is wrong.
How can I fix this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
I somehow left out !install.txt from article_bin.zip ;(. CodeProject won't let me update article (seems they are doing some update), so I'm pasting steps here. I'll update article_bin.zip as soon as I can:
[these steps works when installing any add-in ] 1. Close all instances of Visual Studio .NET 2. Copy files from zip to %My Documents%\Visual Studio 2005\Addins (if directory does not exist, create it) 3. When you re-start Visual Studio you should have JSLint.VS entry in Tools -> Add-in Manager, and appropriate menu items in context menus.
And thanks for notifying that install info is missing.
-- modified at 18:14 Thursday 29th November, 2007 OK, article_bin.zip now contains !install.txt...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
 | VS 2008  Mohamed A. Meligy | 11:20 26 Nov '07 |
|
|
 |
|
 |
I can't say for sure because I haven't installed VS 2008 on my machine. But I don't see why it would not work; in worst case scenario VS 2008 can probably convert VS 2005 projects into needed format after which you only need to recompile Add-in.
I'll update post as soon as I get chance to install new Visual Studio; in the meantime, if you can test Add-in on VS 2008, drop notification 
cheers!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|