A Case Study of a Large-Scale JavaScript Maintainability Project


I recently had to refactor the jslint codebase. It’s an interesting case study in large-scale JavaScript maintainability, and also an example of how to write really efficient code (especially for V8).

If you’re not familiar with it, jslint is a JavaScript program that tries to catch bugs and enforce style. Here’s a very simple example:

function add(a, b) {

return a + b;

}

By default, jslint complains about this:

function add(a, b) { // ‘b’ was used before it was defined.

return a + b; // ‘b’ was used before it was defined.

} // Missing ‘use strict’ statement.

JSLint has some interesting quirks:

The goal of JSLint is to help programmers make their programs better. JSLint looks at some source code and warns about possible problems. The number of warnings may be reduced by inserting appropriate “use strict”; and /*jslint…*/ directives into the source code.

This article presents a case study of the porting of JSLint to Node.js. The original code was written in 2009, and was mostly rewritten in 2012. There are now over thirteen thousand instances of JSLint running on the web pages of thousands of sites.

JSLint is an open-source static code analysis tool written in JavaScript. The tool is used primarily to locate problems in JavaScript programs and to enforce coding conventions. It has been used extensively as a linter for browser-based JavaScript applications.

JSLint was originally written as a command line tool that ran in Windows; it was later ported to run in a browser window, so that it could be used as a web application. After this, JSLint was modified to run on Node.js and as an extension for Visual Studio and Visual Studio Code.

The porting project to Node.js can be divided into three distinct phases: preprocessing, processing and postprocessing. During preprocessing, the source code is loaded from a file or directory into an array of tokens; during processing, the code is analyzed and errors are reported; during postprocessing, the results are returned to the user via standard output or standard error streams.

A common problem with large-scale JavaScript projects

JSLint was a project that started slowly and then suddenly went viral. Douglas Crockford had been writing about JavaScript for years, but it was the release of jslint.com that caused his ideas to spread rapidly through the community.

JSLint is a code quality tool for JavaScript. It checks your code for suspicious constructs, bad practices, and mistakes. It’s safe to use on any codebase because it only makes suggestions; it never modifies your source files in any way.

Over the time we have developed rules for our code to facilitate maintainability and readability. These rules are enforced by a tool, JSLint. This article explains how we developed these rules, why we decided for some rules, and how our coding style changed over time.

The Rules

We have gathered some of our most important rules in the appendix. These are rules that we had to learn the hard way. But before I tell you about these rules, let me explain the most important of them: “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” (John F. Woods)

Now that you understand why it is so important to write clean code, let’s see what a few of those other rules mean.

In the year 2000, Douglas Crockford discovered the JSON data interchange format. It is a subset of the object literal notation of JavaScript, as defined in the ECMAScript Programming Language Standard, Third Edition. The JSON format is often used for serializing and transmitting structured data over a network connection. It is used primarily to transmit data between a server and web application, serving as an alternative to XML.

Because JSON derives from JavaScript, it can be natively parsed by JavaScript engines. This property gives JSON a significant advantage over its XML predecessors. Although this format has proved to be efficient for many use cases, its support in languages other than JavaScript is not universal. This can present problems for interoperability when applications written in different languages need to communicate via the common data format.

To address this issue, Douglas Crockford provided an implementation of JSON encoder/decoder for several programming languages including C, Java, Perl and PHP. I had recently started working with JavaScript professionally (in my job at Yahoo!), so I was curious about how JSON would compare in performance against native XML parsers such as Xerces and libxml2 which are popular in the industry.

I created a test suite that compares the speed and memory usage of various parser implementations against their native equivalents

When the software team at Box started development on Box Edit for Windows and Mac, we had a tough decision to make. We knew it would be a challenge to build native applications that worked seamlessly with Box, but we wanted to keep the product simple.

As a result, we decided to do something that’s pretty rare in the world of native desktop applications: we chose JavaScript as the primary language for our apps.

We’re writing a series of posts to detail what we learned during this process and help other teams who may be facing similar choices. In this particular post, we’ll focus on how we found success with JSLint by working together with Douglas Crockford and his team to improve the tool while maintaining our own custom ruleset.

How We Ended Up With JavaScript

At the time I wrote JSLint, Douglas Crockford was working at Yahoo on their Global Security team. He had discovered a number of common coding patterns that were being used by hackers to introduce vulnerabilities into client-side JavaScript code. Rather than simply blocking these patterns, he decided to write a tool that would identify the bad patterns so that they could be fixed. That tool became JSLint.

I was attracted to the project because, like most programmers, I have always thought of myself as a good programmer and have been occasionally shocked to discover just how bad my code can be. Until I met Douglas, I had no idea just how bad my code was.

JSLint is an open source project that is distributed under the MIT License. It defines a set of coding conventions and provides a tool for enforcing those conventions. The conventions are designed to encourage defensive coding practices, such as always initializing variables and avoiding global variables.


Leave a Reply

Your email address will not be published. Required fields are marked *