Class: Rubocop::Cop::Style::BlockNesting

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/style/block_nesting.rb

Overview

This cop checks for excessive nesting of conditional and looping constructs. Despite the cop's name, blocks are not considered as a extra level of nesting.

The maximum level of nesting allowed is configurable.

Constant Summary collapse

NESTING_BLOCKS =
[:case, :if, :while, :while_post, :until, :until_post,
:for, :resbody]

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#investigate(processed_source) ⇒ Object



15
16
17
18
19
# File 'lib/rubocop/cop/style/block_nesting.rb', line 15

def investigate(processed_source)
  return unless processed_source.ast
  max = BlockNesting.config['Max']
  check_nesting_level(processed_source.ast, max, 0)
end