Random Forest for Code Smell Detection in JavaScript

  • Diego S. Sarafim USP
  • Karina V. Delgado USP
  • Daniel Cordeiro USP


JavaScript has become one of the most widely used programming languages. JavaScript is a dynamic, interpreted, and weakly-typed scripting language especially suited for the development of web applications. While these characteristics allow the language to offer high levels of flexibility, they also can make JavaScript code more challenging to write, maintain and evolve. One of the risks that JavaScript and other programming languages are prone to is the presence of code smells. Code smells result from poor programming choices during source code development that negatively influence source code comprehension and maintainability in the long term. This work reports the result of an approach that uses the Random Forest algorithm to detect a set of 11 code smells based on software metrics extracted from JavaScript source code. It also reports the construction of two datasets, one for code smells that affect functions/methods, and another for code smells related to classes, both containing at least 200 labeled positive instances of each code smell and both extracted from a set of 25 open-source JavaScript projects.


Abbes, M., Khomh, F., Gueheneuc, Y.-G., and Antoniol, G. (2011). An empirical study of the impact of two antipatterns, blob and spaghetti code, on program comprehension. In 2011 15th european conference on software maintenance and reengineering, pages 181-190. IEEE.

AlAbwaini, N., Aldaaje, A., Jaber, T., Abdallah, M., and Tamimi, A. (2018). Using program slicing to detect the dead code. In 2018 8th International Conference on Computer Science and Information Technology (CSIT), pages 230-233. IEEE.

Almashfi, N. and Lu, L. (2020). Code smell detection tool for Java Script programs. In 2020 5th International Conference on Computer and Communication Systems (ICCCS), pages 172-176. IEEE.

Amorim, L., Costa, E., Antunes, N., Fonseca, B., and Ribeiro, M. (2015). Experience report: Evaluating the effectiveness of decision trees for detecting code smells. In 2015 IEEE 26th international symposium on software reliability engineering (ISSRE), pages 261-269. IEEE.

Antunes, N. and Vieira, M. (2015). On the metrics for benchmarking vulnerability detection tools. In 2015 45th Annual IEEE/IFIP international conference on dependable systems and networks, pages 505-516. IEEE.

Arcelli Fontana, F., Mäntylä, M. V., Zanoni, M., and Marino, A. (2016). Comparing and experimenting machine learning techniques for code smell detection. Empirical Software Engineering, 21(3):1143-1191.

Azeem, M. I., Palomba, F., Shi, L., and Wang, Q. (2019). Machine learning techniques for code smell detection: A systematic literature review and meta-analysis. Information and Software Technology, 108:115-138.

Banker, R. D., Datar, S. M., Kemerer, C. F., and Zweig, D. (1993). Software complexity and maintenance costs. Communications of the ACM, 36(11):81-95.

Fard, A. M. and Mesbah, A. (2013). Jsnose: Detecting Javascript code smells. In 2013 IEEE 13th international working conference on Source Code Analysis and Manipulation (SCAM), pages 116-125. IEEE.

Fontana, F. A., Braione, P., and Zanoni, M. (2012). Automatic detection of bad smells in code: An experimental assessment. J. Object Technol., 11(2):5-1.

Fontana, F. A., Zanoni, M., Marino, A., and Mäntylä, M. V. (2013). Code smell detection: Towards a machine learning-based approach. In 2013 IEEE international conference on software maintenance, pages 396-399. IEEE.

Fowler, M. (2018). Refactoring: improving the design of existing code. Addison-Wesley Professional.

Khomh, F., Penta, M. D., Guéhéneuc, Y.-G., and Antoniol, G. (2012). An exploratory study of the impact of antipatterns on class change-and fault-proneness. Empirical Software Engineering, 17(3):243-275.

Maiga, A., Ali, N., Bhattacharya, N., Sabane, A., Guéhéneuc, Y.-G., and Aimeur, E. (2012). Smurf: A svm-based incremental anti-pattern detection approach. In 2012 19th Working Conference on Reverse Engineering, pages 466-475. IEEE.

Maneerat, N. and Muenchaisri, P. (2011). Bad-smell prediction from software design model using machine learning techniques. In 2011 Eighth international joint conference on computer science and software engineering (JCSSE), pages 331-336. IEEE.

Marinescu, R. (2004). Detection strategies: Metrics-based rules for detecting design flaws. In 20th IEEE International Conference on Software Maintenance, 2004. Proceedings., pages 350-359. IEEE.

Nguyen, H. V., Nguyen, H. A., Nguyen, T. T., Nguyen, A. T., and Nguyen, T. N. (2012). Detection of embedded code smells in dynamic web applications. In 2012 Proceedings of the 27th IEEE/ACM International Conference on Automated Software Engineering, pages 282-285. IEEE.

Obbink, N. G., Malavolta, I., Scoccia, G. L., and Lago, P. (2018). An extensible approach for taming the challenges of Javascript dead code elimination. In 2018 IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER), pages 291-401. IEEE.

Padilha, J., Pereira, J., Figueiredo, E., Almeida, J., Garcia, A., and Sant'Anna, C. (2014). On the effectiveness of concern metrics to detect code smells: An empirical study. In International Conference on Advanced Information Systems Engineering, pages 656-671. Springer.

Parnas, D. L. (1994). Software aging. In Proceedings of 16th International Conference on Software Engineering, pages 279-287. IEEE.

Tamburri, D. A., Palomba, F., Serebrenik, A., and Zaidman, A. (2019). Discovering community patterns in open-source: a systematic approach and its evaluation. Empirical Software Engineering, 24(3):1369-1417.

Yamashita, A. and Moonen, L. (2013). Exploring the impact of inter-smell relations on software maintainability: An empirical study. In 2013 35th International Conference on Software Engineering (ICSE), pages 682-691. IEEE.
Como Citar

Selecione um Formato
SARAFIM, Diego S.; DELGADO, Karina V.; CORDEIRO, Daniel. Random Forest for Code Smell Detection in JavaScript. In: ENCONTRO NACIONAL DE INTELIGÊNCIA ARTIFICIAL E COMPUTACIONAL (ENIAC), 19. , 2022, Campinas/SP. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2022 . p. 13-24. ISSN 2763-9061. DOI: https://doi.org/10.5753/eniac.2022.227328.

Artigos mais lidos do(s) mesmo(s) autor(es)

1 2 > >>