Metric-Comment.Density

Comment Density

Required inputs: RFG

Computes the comment density (also called comment frequency) of a routine, which roughly corresponds to the ratio between comments before, within, and on the same line as the routine and the number of statements of the routine. For a given routine r, let st(r) be the number of statements of the routine. Let p(r) be the number of comments before the routine and on the same line as the routine definition, i.e., the value Metric.Comment.Preceding, and let i(r) be the number of comments within the routine, i.e., the value Metric.Comment.Internal. Then the comment density d(r) of r is computed as follows:

comments(r) = p(r) + i(r)
if (st(r) > 0) {
    d(r) = comments(r) / st(r)
} else if (comments(r) > 0) {
    d(r) = MAX_INT
} else {
    d(r) = 0
}

Possible Messages

This rule has no predefined messages.

Options

display_name

display_name : str | None = 'Comment Density'

Description of the metric shown in the dashboard. If None, rfg_metric_name is used.
 

max_value

max_value : float | None = None

Maximum allowed value. None if unlimited.
 

min_value

min_value : float | None = 0.2

Minimum allowed value. None if unlimited.
 

rfg_metric_name

rfg_metric_name : str = 'Metric.Comment.Density'

Name of the node attribute storing the metric value in the RFG.