janus.metrics.complexity_metrics#

Exceptions#

NodeException

Common base class for all non-exit exceptions.

Classes#

TreeSitterMetric

A class for calculating node-based complexity metrics of code.

Functions#

cyclomatic_complexity(target, **kwargs)

Calculate the cyclomatic complexity score.

effort(target, **kwargs)

Calculate the Halstead effort.

volume(target, **kwargs)

Calculate the Halstead volume.

difficulty(target, **kwargs)

Calculate the Halstead difficulty.

maintainability(target, **kwargs)

Calculate the maintainability score.

Module Contents#

exception janus.metrics.complexity_metrics.NodeException#

Bases: Exception

Common base class for all non-exit exceptions.

Initialize self. See help(type(self)) for accurate signature.

class janus.metrics.complexity_metrics.TreeSitterMetric(code, language)#

A class for calculating node-based complexity metrics of code.

Parameters:
  • code (str) – The code to get metrics on

  • language (Optional[str]) – The language the code is written in

get_cyclomatic_complexity()#
Return type:

int

get_lines_of_code()#
Return type:

int

get_program_vocabulary()#
Return type:

int

get_program_length()#
Return type:

int

get_volume()#
Return type:

float

get_difficulty()#
Return type:

float

get_effort()#
Return type:

float

get_time_to_program()#
Return type:

float

get_num_bugs()#
Return type:

float

get_maintainability()#
Return type:

float

janus.metrics.complexity_metrics.cyclomatic_complexity(target, **kwargs)#

Calculate the cyclomatic complexity score.

Parameters:

target (str) – The target text.

Returns:

The cyclomatic complexity.

Return type:

float

janus.metrics.complexity_metrics.effort(target, **kwargs)#

Calculate the Halstead effort.

Parameters:

target (str) – The target text.

Returns:

The Halstead effort.

Return type:

float

janus.metrics.complexity_metrics.volume(target, **kwargs)#

Calculate the Halstead volume.

Parameters:

target (str) – The target text.

Returns:

The Halstead volume.

Return type:

float

janus.metrics.complexity_metrics.difficulty(target, **kwargs)#

Calculate the Halstead difficulty.

Parameters:

target (str) – The target text.

Returns:

The Halstead difficulty.

Return type:

float

janus.metrics.complexity_metrics.maintainability(target, **kwargs)#

Calculate the maintainability score.

Parameters:

target (str) – The target text.

Returns:

The maintainability score.

Return type:

float