Video: https://youtu.be/_FAUq98qELY
JScent is a program analyzer that detects code smells. Code smells are potential issues with source code that can correspond to a deeper problem in the program. For example, JScent can detect issues such as long methods, too many comments, feature envy, message chains, dead code and more. JScent produces a report that summarizes all the code smells found in a concise and usable way - easily accessible in the console. The JScent analysis can be classified both as a value-agnostic static analysis and a meta-properties analysis, as some code smells lean more toward syntax and others more toward semantics and high-level Software Engineering principles.
Sample Report:
JScent is aimed at developers and teams who are trying to build code that is maintainable, extensible, and well structured. The reports generated are not intended to be prescriptive but rather point out areas that may be cause for concern as a project grows in size and scope.
JScent is structured in a way that it is easily extensible to add new code smells in the future. Next steps for the team include adding more nuanced, difficult to spot smells to the analysis report.
Instructions
Put all the JS files you want to analyze in the /input folder, and run main.js to start.
Example code smells detectable by JScent
- Long message chain - In code you see a series of calls resembling a->b()->c()->d()
- Feature envy - A method accesses the data of another object more than its own data.
- Long parameter list - A method with more than 3 parameters
- Large objects - A class/object that is doing too much
- Dead code - A variable, parameter, field, method or class is no longer used (usually because it is obsolete).
- Long Methods - A method contains too many lines of code
- Switch statement - A switch statement with too many cases
- Method comments - A method is filled with explanatory comments
Credit and References
- Initial program parsing done using the esprima node library (esprima.org)
- JSNose: Detecting JavaScript code smells - https://www.ece.ubc.ca/~amesbah/docs/scam13.pdf
- Code smell defn's: https://sourcemaking.com/refactoring/smells