Project

cycromatic

0.01
No commit activity in last 3 years
No release in over 3 years
Compute Cyclomatic Complexity of Ruby programs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.12
~> 5.0
~> 10.0

Runtime

~> 2.3
~> 2.1
 Project Readme

Cycromatic

Cycromatic calculates cyclomatic complexity of Ruby programs.

Installation

Install by gem:

$ gem install cycromatic

Usage

Run cycromatic command to calculate complexity:

$ cycromatic ruby_program.rb    # Specify paths to .rb files
$ cycromatic app config         # Specify directories including .rb files

The output will be like the following:

$ cycromatic ../contror/lib/contror/anf/translator.rb
../contror/lib/contror/anf/translator.rb	[toplevel]:1	1
../contror/lib/contror/anf/translator.rb	initialize:8	1
../contror/lib/contror/anf/translator.rb	translate:14	1
../contror/lib/contror/anf/translator.rb	with_new_block:20	3
../contror/lib/contror/anf/translator.rb	current_block:37	1
../contror/lib/contror/anf/translator.rb	push_stmt:41	1
../contror/lib/contror/anf/translator.rb	normalize_node:46	3
../contror/lib/contror/anf/translator.rb	translate0:59	52
../contror/lib/contror/anf/translator.rb	translate_arg:478	3
../contror/lib/contror/anf/translator.rb	translate_call:491	2
../contror/lib/contror/anf/translator.rb	translate_params:533	2
../contror/lib/contror/anf/translator.rb	value_node?:547	7
../contror/lib/contror/anf/translator.rb	fresh_var:566	1
../contror/lib/contror/anf/translator.rb	translate_var:571	5

The tool accepts --format=json option to output in JSON format.

Calculation

It calculates complexities as the following:

  • Basic block have complexity of 1 (base case)
  • Branching construct have complexity of 1
  • Loop construct have complexity of 1
  • && and || have complexity of 1
  • Safe navigation operator have complexity of 1
  • Passing iterator block does not introduce complexity

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/soutaro/cycromatic.