Academia.eduAcademia.edu

DLint: dynamically checking bad coding practices in JavaScript

Abstract

JavaScript has become one of the most popular programming languages, yet it is known for its suboptimal design. To effectively use JavaScript despite its design flaws, developers try to follow informal code quality rules that help avoid correctness, maintainability, performance, and security problems. Lightweight static analyses, implemented in "lint-like" tools, are widely used to find violations of these rules, but are of limited use because of the language's dynamic nature. This paper presents DLint, a dynamic analysis approach to check code quality rules in JavaScript. DLint consists of a generic framework and an extensible set of checkers that each addresses a particular rule. We formally describe and implement 28 checkers that address problems missed by state-of-the-art static approaches. Applying the approach in a comprehensive empirical study on over 200 popular web sites shows that static and dynamic checking complement each other. On average per web site, DLint detects 49 problems that are missed statically, including visible bugs on the web sites of IKEA, Hilton, eBay, and CNBC.

Key takeaways

  • • Our implementation of DLint can be easily extended with additional checkers, providing the basis for a practical tool that fills an unoccupied spot in the JavaScript tool landscape.
  • DLint currently contains 28 checkers that address rules related to inheritance (Section 2.2), types and type errors (Section 2.3), misuse of the JavaScript language (Section 2.4), misuse of an API (Section 2.5), and uncommon values (Section 2.6).
  • For a fair comparison, we focus on JSHint checkers that have a corresponding DLint checker.
  • DLint complements existing static checkers by revealing problems that are missed statically and by finding violations of rules that cannot be easily checked through static analysis.
  • First, both DLint and JSHint include a limited set of checkers, which may or may not be representative for dynamic and static analyses that check code quality rules in JavaScript.