Tweaking a VS2010 plugin to run JSLint in the command line

We’ve gone to some lengths at work to automate, and have a continuous delivery style pipeline for all things build and deployment related. It’s well on its way, but not ‘perfect’ yet. Maybe perfection isn’t attainable, or maybe when you have a red button on the desk that when pushed does *everything*. None-the-less aiming for perfection will continue to drive us to improve.

So here I wanted to discuss what steps I took to get a nice JSLint Visual Studio plugin to form part of our build process. It was a bit of fussing about getting it to work, and it’s an example of still being imperfect, but for now it serves the build pipeline well enough.

If you don’t use JSLint for your JavaScript code, you probably should. It’s a static analysis tool to analyse and report on broken coding rules for JavaScript. Try it out on the creator (Douglas Crockford’s) site

There is an easily accessible Visual Studio plugin called exactly what you would expect “JSLint for Visual Studio 2010” and here is the direct link for it on the VS Gallery for your installation pleasure.

If you do anything and stop reading here you’ve done well, install it and happy JavaScripting.

JSLint for Visual Studio 2010 Extension

But what about continuous integration?

For us it wasn’t enough, we wanted our build process which runs as psake scripts to fail if JSLint rules were broken.

Just for a bit more completeness on the psake digression and how the command line tool will execute under MSBuild, here’s a snippet of the ‘targets’ code that is referenced by the .csproj files that contain JavaScript. The input parameter on the executable being the directory containing the script files relative to .csproj file.

<Target Name="AfterBuild"> 
    <Message Text="Running jslint..." Importance="Normal" /> 
    <Exec Command="&quot;..\jslint\JSLint.CLI.exe&quot; .\Scripts\ " /> 

So the search for command lines tools began. I found some existing command line tools, some which had more complex dependencies, others which seemed to be more ‘primitive’, i.e. did not report on errors the IDE based JSLint plugin was reporting.

There were 2 main objectives driving the choice of the tool

  1. Similarity and accuracy to and the Visual Studio extension
  2. Ease of setup

There was some discussion happening on StackOverflow, here and here but nothing I tried digging deeper into seemed suitable.

I then had an idea…

Take the core logic of the Visual Studio extension and wrap it in a very simple console application to execute as part of the build process.

With the approach I took, it seems even option 2 was difficult to achieve (consumed some time), but at least it had the least external dependencies to the other options out there.

The very first step was to obtain and install the VS2010 SDK, as this was an project which referenced many interop assemblies for interacting with the IDE. It needs to be the Service Pack 1 SDK in fact, and here’s a direct link. Once I was able to compile the extension it was then a matter of understanding how it operates and how to access a method to perform the ‘linting‘.

There were 2 major hacks to get access to some inner workings of the extension to operate:

  1. Making some ‘protected/internal’ methods and properties public
  2. Modifying where the JSLint logic obtained the settings file from (JSLintOptions.xml).

Locating JSLintOptions.xml proved somewhat difficult at first, as it was tucked away hiding in the Roaming section of my user folder on Windows (\Users\*\AppData\Roaming\). These hacks could greatly benefit from some re-factoring effort if I have ever have the time, or someone else is so inclined. But after an initial attempt to refactor out the most core of logic things fell apart in the land of SDK dependencies, so I rolled back and opted for a less elegant approach which was the 2 hacks listed above.

The logic for the console application is then trivially simple:

  1. Read .js files.
  2. Using the JSLinter class method Lint() supply the .js file content/
  3. Write errors to console
  4. Return error code, 0 (Success), 1 (JavaScript warnings), etc.

Show me the code!

If you want to see the hacks I had to make to get this to work head on over to this git repository on BitBucket. I offer no warranty it may be fragile so manipulate with caution.

If you just want the command line executable, then it’s built and stored in the repository in the /output folder, if I make any updates to the executable, I’ll also update that executable.

Areas for improvement in the console app:

  • Taking path locations as input parameters/external file of locations
  • Taking alternate settings files for rules to ignore/include
  • General tidyup

Outstanding issue

The final hiccup is not directly related to the use of the command line tool itself, but building the command line tool from source as part of a more comprehensive-all-inclusive build process. Adding commands in the .csproj file post-build settings was not sufficient. The build and copy of the executable needs run as a directive in the targets ‘afterbuild’ section of the .csproj file.

CSProject Settings Dialog - Post Build Events

Not suitable to place actions in 'post build' section

This led to a conflict between MSBuild and the VS2010 SDK, which was very frustrating and currently isn’t solved yet. The question is up on StackOverflow.

Generic Personality Tests For Software Engineers

I rarely rant on my blog, but when a friend of mine brought up that he had to take a personality test as part of the interview process (a step prior to being given an offer), it just frustrated me so much. So at this point dear reader you may move along if this isn’t of interest as this is all my opinion on personality tests for software engineers.

Summary and Disclaimer
Unless your organisation has thought long and hard about designing a personality test specific to software engineers, don’t subject candidates to a generic personality tests. It reflects poorly on your understanding of software engineers.

If you use a generic personality test…

Q: Do you care about hiring and retaining the best software engineers?
A: test A resounding – No.

Q: Do you understand what it takes to be a good software engineers?
A: A clear – No.

Q: Does your organisation care about the previous two questions?
A: If no, then fair enough. Continue using the test, and move along.


You have to be kidding me. When a professional organisation subjects any reasonably qualified software engineer to the same type of tests they subject potential employees in their specific field to then they are not concerned about hiring and retaining the best, or they have been ill-informed on how to recruit top software engineers. What got me fired up about this information was that the type of questions he described. They were so broad and irrelevant to what it would take to do his job. This frustration was further compounded when it was apparent that this test carried some significant weight in the recruitment process. They didn’t even bother to undertake more suitable programming/problem solving exercises that an Engineer would actually do in day to day activities in this job role.

At this point you may counter my argument with, a general statement such as “why not just use any and all tools available to help make a decision“. To this I answer: such questions are not relevant enough to accurately judge a good software engineer, and do more harm than good.

Here are some categories we derived from the discussion after he sat the test, and we analysed the questions that invoked the anger that’s feeding this post.

  1. Questioning the norm.
  2. Long standing ideas.
  3. Repetitive routines.
  4. Breaking rules.
  5. Data analysis.
  6. Being creative.

Here we are both speculating a bit, but the type of questions that represented the first 4 categories seemed to attempt to discover candidates that would be deemed as rebellious. As a software developer answering these questions you have to completely put aside what makes you a good software developer. I would give credit if the organisation was actively seeking ‘rebellious’ software developers ready to challenge the norm and bring improvements. But based on their sector, and other information this seems highly unlikely. The questions that matched the last 2 categories seemed reasonable.

A very brief search uncovered this reasearch paper; very SDLC and waterfall focused analysis of personalities (pdf), there didn’t seem to be any concept of applying Computer Science knowledge/research into this personality test. In fact several questions were difficult even to interpret for your typical software engineer.

If I was subjected to such a test as part of an application where the test wasn’t clearly justified as relevant to engineers, it would be safe to say right there an then to avoid stress I would decline and withdraw my candidacy.

Take away: treat your engineers with a bit more respect.