Contributed by Khurshidali Shaikh on 4 Jul 2011
Static code analysis in Ruby can be done using metric_fu. metric_fu is a nice gem which internally uses Saikuro, Flog, Flay, Rcov, Reek, Roodi, Churn, RailsBestPractices and generals useful quality metrics about the code. With the help of above it analyzes code for complexity, convention compliance, duplicate and unused code.
Saikuro analyzes code and reports cyclomatic complexity of each method in the analyzed code. Each method has a complexity of 1 by default. In addition Saikuro adds 1 to the cyclomatic complexity for each of the below :
Flog scores an ABC(Assignment, Branches, Conditions) metric on the methods. With the help of this classes that have a high average flog score may be further looked at for optimization and refactoring.
Flay analyzes code for structural similarities. Code reported by Flay is a good candidate for refactoring.
Rcov is a code coverage tool. It analyses the code coverage by running the unit tests in the project.
Reek reports code smells in the ruby code. Some of the code smells its reports are missing comments, long methods, long class, long parameter list, uncommunicative names, etc. A complete list of code smells reported by Reek cane be found here – https://github.com/kevinrutherford/reek/wiki/code-smells
Roodi stands for Ruby Object Oriented Design Inferometer. It parses your Ruby code and warns you about design issues you have based on the checks that is has configured. Follwing checks are the supported checks. A yml file can be provided to include only selected checks
Gives a number of times a file, class, method has been changed during the life of the project. Churn evaluates this by looking at the commits done in the SCM repository. Chrun supports Git, Mercurial and SVN (partially)
Analyses code for Rails Best Practices. The default supported checks are here https://github.com/flyerhzm/rails_best_practices/wiki
There are some other tools that may also be useful
Visit us at Neevtech.com to know more about our offerings.
© 2013 Neevtech Blog | Neev Technologies