Why and How Javascript Developers Use Linters
Total Page:16
File Type:pdf, Size:1020Kb
Why and How JavaScript Developers Use Linters Master’s Thesis Krist´ın Fjola´ Tomasd´ ottir´ Why and How JavaScript Developers Use Linters THESIS submitted in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE in COMPUTER SCIENCE by Krist´ın Fjola´ Tomasd´ ottir´ born in Reykjav´ık, Iceland Software Engineering Research Group Department of Software Technology Faculty EEMCS, Delft University of Technology Delft, the Netherlands www.ewi.tudelft.nl c 2017 Krist´ın Fjola´ Tomasd´ ottir.´ All rights reserved. Why and How JavaScript Developers Use Linters Author: Krist´ın Fjola´ Tomasd´ ottir´ Student id: 4518063 Email: [email protected] Abstract A linter is a type of static analysis tool that warns software developers about pos- sible errors in code or violations to coding standards. By using such a tool, errors can be surfaced early in the development process when they are cheaper to fix, and code can be kept more readable and maintainable. For such a tool to be successful, it is important for its creators to understand the needs and challenges of developers when using a linter. Furthermore, it needs to be made clear to developers why using such a tool can be beneficial, along with how linters can be configured to identify appropriate and relevant issues for their projects. In this thesis, we examine developers’ perceptions of linters to increase our knowl- edge on these tools for JavaScript, the most widely used programming language in the world today. More specifically, we study why and how developers use ESLint, the most popular JavaScript linter, along with the challenges that they face while using the tool. We collect data with three different methods where we first interview 15 experts on using linters, then analyze over 9,500 ESLint configuration files and finally survey more than 300 developers from the JavaScript community. The combined results from these analyses provide developers, tool makers and researchers with valuable knowl- edge and advice on using and developing a linter for JavaScript. Thesis Committee: Chair: Prof. Dr. A. van Deursen, Faculty EEMCS, TU Delft University supervisor: Dr. M. F. Aniche, Faculty EEMCS, TU Delft Committee Member: Prof. Dr. G. Gousios, Faculty EEMCS, TU Delft Prof. Dr. C. Hauff, Faculty EEMCS, TU Delft Preface This thesis is the product of my graduation project to obtain a master’s degree in Computer Science at Delft University of Technology. I would like to thank my supervisor Arie van Deursen for his invaluable advice over the past year. Many thanks go to the participants of this study, those who took part in the interviews and those who spent time to pilot test my survey, and in particular Joseph Hejderup for his valuable input. Special thanks go to my second supervisor, Maur´ıcio Aniche, for his endless help and enjoyable collaboration during this project. Not only did he always make time to answer all my questions and review my work, but also gave me moral support and continued to encourage me throughout my project. Lastly, I am lucky to have been able to spend the two years of my MSc studies in Delft, where I have gotten to meet many amazing people from all over the world. From both friends and colleagues I have learned countless lessons that have influenced my greatly as a person, for which I am ever thankful. Krist´ın Fjola´ Tomasd´ ottir´ Delft, the Netherlands August 28, 2017 iii Contents Preface iii Contents v List of Figures ix 1 Introduction 1 2 Background 5 2.1 JavaScript . 5 2.1.1 History of JavaScript . 5 2.1.2 JavaScript’s Ecosystem . 6 2.1.3 JavaScript’s Nature and Language Features . 7 2.2 JavaScript Linters . 8 2.2.1 Available Linters . 8 2.2.2 ESLint . 9 3 Related Work 17 3.1 Perceptions of Static Analysis Tools . 17 3.2 Configurations of Static Analysis Tools . 18 3.3 Effectiveness of Static Analysis Tools . 19 3.4 False Positives in Static Analysis Tools . 19 3.5 Static Analysis Tools Used in Industry . 20 3.6 Static and Dynamic Analysis for JavaScript . 21 4 Developers’ Perceptions of Linters 23 4.1 Research Questions . 23 4.2 Methodology . 24 4.2.1 Interview Design . 24 4.2.2 Interview Procedure . 25 4.2.3 Data Analysis . 25 v CONTENTS 4.2.4 Participants . 26 4.2.5 Limitations . 27 4.3 Results . 29 4.3.1 RQ1 Reasons for Using a Linter . 29 4.3.2 RQ2 Configuring Linters . 34 4.3.3 RQ3 Challenges of Using a Linter . 36 4.4 Discussion . 40 4.4.1 Reasons for Using a Linter . 40 4.4.2 Configuring Linters . 40 4.4.3 Challenges of Using a Linter . 42 4.5 Conclusion . 42 5 Exploring Linter Configurations in JavaScript Projects 43 5.1 Research Questions . 43 5.2 Methodology . 44 5.2.1 Dataset . 44 5.2.2 Collecting Configuration Files . 47 5.2.3 Parsing Configuration Files . 49 5.3 Results . 50 5.3.1 RQ4 Prevalence of Configurations . 50 5.3.2 RQ5 Common Configurations . 53 5.4 Discussion . 62 5.4.1 Prevalence of Configurations . 62 5.4.2 Common Configurations . 64 5.5 Conclusion . 66 6 The Experiences and Perceptions of the JavaScript Community 67 6.1 Research Questions . 67 6.2 Methodology . 68 6.2.1 Survey Design . 68 6.2.2 Survey Evaluation . 70 6.2.3 Sampling and Responses . 74 6.2.4 Data Analysis . 76 6.2.5 Limitations . 76 6.3 Results . 78 6.3.1 Participants . 78 6.3.2 RQ6 Why Developers Use Linters . 79 6.3.3 RQ7 Configuring Linters . 84 6.3.4 RQ8 Important ESLint Categories and Rules . 86 6.3.5 RQ9 Challenges of Using a Linter . 90 6.4 Discussion . 92 6.4.1 Participants . 92 6.4.2 Why Developers Use Linters . 92 6.4.3 Configuring Linters . 93 vi Contents 6.4.4 Important ESLint Categories and Rules . 93 6.4.5 Challenges of Using a Linter . 94 6.4.6 Limitations . 95 6.5 Conclusion . 96 7 Conclusion 97 7.1 Revisiting the Research Questions . 97 7.1.1 Developers’ Perceptions of Linters . 97 7.1.2 Exploring Linter Configurations in JavaScript projects . 98 7.1.3 The Experiences and Perceptions of the JavaScript Community . 99 7.2 Implications . 99 7.2.1 Developers . 100 7.2.2 Tool and Preset Makers . 101 7.2.3 Researchers . 103 7.3 Final Conclusion . 105 Bibliography 107 A Interview Questions 121 A.1 Participant Information . 121 A.2 Linter Usage . 121 B Data Collection Query 123 B.1 Query . 123 vii List of Figures 2.1 Number of npm downloads for ESLint, JSHint, JSLint, JSCS and Standard from January 2015 - May 2017 [162] . 9 6.1 The country of residence of participants . 79 6.2 The primary roles of participants in software development . 79 6.3 Participants’ experience in software development and with JavaScript. Axes show years of experience and percentage of participants with the corresponding answer. 80 6.4 The importance of using a linter in a JavaScript project. 82 6.5 The percentage of participants that had used one of the following linters: ES- Lint, JSHint, JSLint, TSLint, JSCS and Standard JS. 84 6.6 How participants use presets . 86 ix Chapter 1 Introduction An important part of software development is to maintain code by keeping it readable and defect free. A well known method to do so is using automatic static analysis tools (ASATs) which automatically examine code to look for defects or any issues related to best practices or code style. These tools aid in finding issues and refactoring opportunities early in the software development process, when they require less effort and are cheaper to fix [73, 105]. Due to their many benefits, ASATs have become commonly used in software development [69]. There is an abundance of available ASATs, both academic tools and tools used in in- dustry. These tools vary in functionality, use diverse approaches for static analysis and can work for different languages [139]. Some tools focus on coding styles, code smells or general maintainability issues, while some others try to identify faults in code, sometimes examining specific types of defects such as related to security or concurrency [169, 74]. One type of ASATs are linters, which often use a relatively simple analysis method to catch non-complex errors and violations to coding standards. In recent years, linters have become commonly used tools for dynamic languages such as JavaScript [69]. JavaScript has become a very popular programming language in the last years and in fact has been the most commonly used language on GitHub since 2013 [91]. It is known as the language of the web and has recently also become popular for server side development, serving as a general-purpose language. A notable characteristic of JavaScript is its dynamic nature. For example, it allows for generating new code during runtime exe- cution and for dynamic typing where variables do not need to be declared before they are used. Partly due to its dynamic features, JavaScript is considered to be an error-prone lan- guage [129]. For example, it can be easy to introduce unexpected program behavior with simple syntactic or spelling mistakes, which can go unnoticed for a long time [128, 133]. A linter can therefore be especially useful for JavaScript to detect these types of mistakes. Additionally, as JavaScript has become an extremely widespread language, it becomes even more important to have tool support that aids developers in keeping JavaScript code main- tainable, secure and correct. Several studies have focused on static analysis for JavaScript since ASATs have different kinds of requirements for dynamic languages than for static languages [126, 111, 86].