Class: Roodi::Checks::AbcMetricMethodCheck
- Defined in:
- lib/roodi/checks/abc_metric_method_check.rb
Overview
TODO: Add summary
TODO: Add detail
Constant Summary collapse
- ASSIGNMENTS =
ASSIGNMENTS = [:attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn]
[:lasgn]
- BRANCHES =
BRANCHES = [:if, :else, :while, :until, :for, :rescue, :case, :when, :and, :or]
[:vcall, :call]
- CONDITIONS =
CONDITIONS = [:and, :or]
[:==, :<=, :>=, :<, :>]
- OPERATORS =
*= /= %= += <<= >>= &= |= ^=
[:*, :/, :%, :+, :<<, :>>, :&, :|, :^]
- DEFAULT_SCORE =
10
Constants inherited from Check
Instance Attribute Summary collapse
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #evaluate_start(node) ⇒ Object
-
#initialize ⇒ AbcMetricMethodCheck
constructor
A new instance of AbcMetricMethodCheck.
- #interesting_nodes ⇒ Object
Methods inherited from Check
#add_error, #end_file, #errors, #evaluate_end, #evaluate_node, #evaluate_node_end, #evaluate_node_start, make, #position, #start_file
Constructor Details
#initialize ⇒ AbcMetricMethodCheck
Returns a new instance of AbcMetricMethodCheck.
21 22 23 24 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 21 def initialize super() self.score = DEFAULT_SCORE end |
Instance Attribute Details
#score ⇒ Object
Returns the value of attribute score.
19 20 21 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 19 def score @score end |
Instance Method Details
#evaluate_start(node) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 30 def evaluate_start(node) method_name = node[1] a = count_assignments(node) b = count_branches(node) c = count_conditionals(node) score = Math.sqrt(a*a + b*b + c*c) add_error "Method name \"#{method_name}\" has an ABC metric score of <#{a},#{b},#{c}> = #{score}. It should be #{@score} or less." unless score <= @score end |
#interesting_nodes ⇒ Object
26 27 28 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 26 def interesting_nodes [:defn] end |