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 Method Summary collapse
- #evaluate_start(node) ⇒ Object
-
#initialize(options = {}) ⇒ 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, #position, #start_file
Constructor Details
#initialize(options = {}) ⇒ AbcMetricMethodCheck
Returns a new instance of AbcMetricMethodCheck.
19 20 21 22 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 19 def initialize( = {}) super() @score = ['score'] || DEFAULT_SCORE end |
Instance Method Details
#evaluate_start(node) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 28 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
24 25 26 |
# File 'lib/roodi/checks/abc_metric_method_check.rb', line 24 def interesting_nodes [:defn] end |