Sha256: 3c13c6ef491148c46c571dbd36e4bc8f4e3a9609078d482b9b978aa20e00df40

Contents?: true

Size: 678 Bytes

Versions: 2

Compression:

Stored size: 678 Bytes

Contents

require 'simplabs/excellent/checks/cyclomatic_complexity_check'

module Simplabs

  module Excellent

    module Checks

      class CyclomaticComplexityBlockCheck < CyclomaticComplexityCheck

        DEFAULT_THRESHOLD = 4
      
        def initialize(options = {})
          super(options[:threshold] || DEFAULT_THRESHOLD)
        end
      
        def interesting_nodes
          [:iter]
        end

        def evaluate(node)
          complexity = count_complexity(node)
          add_error('Block has cyclomatic complexity of {{score}}.', { :score => complexity }, -(node.line - node[1].line)) unless complexity <= @threshold
        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplabs-excellent-1.0.0 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
simplabs-excellent-1.0.1 lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb