So we all know how to run JSLint from Node, but what if you want to use Firebug or something to step through? The version Crockford uses on jslint.com is minimized and includes a lot of overhead you don't need to run locally (http://jslint.com/webjslint.js). It's obviously not that difficult to set up.

Here's the easy version. I'm not sure how well the formatting will keep with this email-to-blog post, but hopefully I'll eventually remember to return and clean it up.

So save the below into index.html and knock yourself out. No jQuery or nuttin required.

Gosh, I hope this post works. HTML always worries me with Blogger. It's anyone's guess how it'll parse it this week.

<html>
    <head>
        <script src="jslint.js"></script>

        <script>
            function jslintalizeMe()
            {
                var i, divOut, errs, errsMsg = "";

                divOut = document.getElementById("errors");
                divOut.innerHTML = "";

                if (!JSLINT(document.forms[0].elements[0].value))
                {
                    errs = JSLINT.errors;
                    for (i=0; i < errs.length; i++)
                    {
                        err = errs[i];
                        if (null !== err)
                        {
                            if (undefined !== err.id)
                            {
                                errsMsg += "Error: " 
                                + err.code 
                                + " -- line " 
                                + err.line 
                                + " char " 
                                + err.character + "<br />"
                                + "    " 
                                + err.evidence + "<br />"
                                + "    " +
                                 err.reason + "<br /><br />\n";
                            }
                            else
                            {
                                errsMsg += err.reason;
                            }
                        }
                    }
                    divOut.innerHTML = errsMsg;
                }
            }
        </script>

    </head>

    <body>

        <form>
            <textarea rows="24" cols="80"
                placeholder="// Paste quality code here"></textarea>
            <br />
            <button onclick="jslintalizeMe();return false;">JSLint</button>
        </form>

        <div id="errors"></div>
    </body>
</html>
Look, that's ugly, I get it. But it's the easiest way to get JSLint running in a good, easily Firebuggable fashion. Enjoy. ;^)

Labels: ,