Just found this - JSLint

This post is more than 2 years old.

Earlier this week I received a copy of JavaScript Patterns. I've only finished the first two chapters and already I'm finding it to be an incredible book. (I'll be doing a review when I finish.) One of the first things I learned while reading it concerned a tool called JSLint. To quote their FAQ, JSLint is a code quality tool. It can read in JavaScript and report on problems, best practices, anti-patterns, etc. It is very configurable so if you find it too strict you can knock it down a peg or two. I spent a few minutes last night (before my Black Ops session!) working on a ColdFusion Builder Extension. Why? It isn't really needed - there is an eclipse plugin already for JSLint. But it gave me an excuse to write another extension and revel in how darn cool ColdFusion Builder is. Here is a quick example of it in action:

Currently the extension can be used on JavaScript files within the project view and code snippets in open CFM files. (You can't run extensions on editor files that are not CFM or CFCs.) I also took the opportunity to finally begin work on a CFC to make extension writing easier. Here are a few examples of what the CFC can do:

<cfparam name="ideeventinfo"> <cfset builderHelper = new builderHelper(ideeventinfo)> <cfset runAs = builderHelper.getRunType()>

You begin by passing in the XML packet CFBuilder sends on all requests to the CFC. The getRunType returns how the extension was run. Since my JSLint extension runs from both the project explorer and the editor I need to know which was used.

<cfif runAs is "projectView"> <cfset selectedResource = builderHelper.getSelectedResource()> <cffile action="read" file="#selectedResource.path#" variable="contents"> <cfset resource = selectedResource.path> <cfelseif runAs is "editor"> <cfset data = builderHelper.getSelectedText()> <cfset contents = data.text> <cfset resource = data.path> <cfelse> <cfthrow message="JSLint extension run in a way it is not supposed to be run."> </cfif>

If we called the extension via the project view, I ask for the selected resource. This returns a structure of the path of the selection as well as the type (folder versus file). If the editor was used, I simply run getSelectedText. This method will check to see if there was an actual selection. If not, it grabs the entire contents of the file. Finally, here is another method in action:

<script src="#builderHelper.getrooturl()#jquery-1.4.3.min.js"></script>

Anyway, I plan on adding to this as time goes on. Click the download link below to get the extension.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Ryan Vikander posted on 11/11/2010 at 1:56 AM

This is pretty sweet. Might be one of the most used extensions I have right now. Thanks Ray!

Comment 2 by Raymond Camden posted on 11/11/2010 at 2:47 AM

Glad you like it. If there is enough interest, I'll add support for modifying the options.

Comment 3 by Raymond Camden posted on 11/11/2010 at 2:53 AM

One thing I forgot to mention - and Ryan found it right away. I said you could right click on a CFM file. If you do that and there is ANY code in there, it will break the extension. If you right click in a CFM file but select JavaScript only, it should be ok.

Comment 4 by salvatore fusto posted on 11/11/2010 at 12:31 PM

days ago i read about an AIR app, based on jslint, usefull to test js files everywhere on file system but, sorry for this, i've not bookmarked: i i'll found it i'll post.

Comment 5 by Tom Jenkins posted on 11/11/2010 at 1:36 PM

Very nice! Just thought I would do a quick check on the latest release of jQuery ... plenty of errors in that one :P

Comment 6 by Raymond Camden posted on 11/12/2010 at 1:13 AM

@TomJ: Funny you say that - I used it for testing as well.

Comment 7 by Edward Beckett posted on 11/12/2010 at 7:41 AM

@Ray ...

If you like jslint.com ...

You Should Love This ...