Class: Reek::Smells::NestedIterators Private

Inherits:
SmellDetector show all
Defined in:
lib/reek/smells/nested_iterators.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A Nested Iterator occurs when a block contains another block.

NestedIterators reports failing methods only once.

See Nested-Iterators for details.

Constant Summary collapse

MAX_ALLOWED_NESTING_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The name of the config field that sets the maximum depth of nested iterators to be permitted within any single method.

'max_allowed_nesting'
DEFAULT_MAX_ALLOWED_NESTING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1
IGNORE_ITERATORS_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The name of the config field that sets the names of any methods for which nesting should not be considered

'ignore_iterators'
DEFAULT_IGNORE_ITERATORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[]

Constants inherited from SmellDetector

SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from SmellDetector

#smells_found, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SmellDetector

#config_for, #configure_with, contexts, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_category, #smell_category, smell_type, #smell_type, #value

Constructor Details

This class inherits a constructor from Reek::Smells::SmellDetector

Class Method Details

.default_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
# File 'lib/reek/smells/nested_iterators.rb', line 24

def self.default_config
  super.merge(
    MAX_ALLOWED_NESTING_KEY => DEFAULT_MAX_ALLOWED_NESTING,
    IGNORE_ITERATORS_KEY => DEFAULT_IGNORE_ITERATORS
  )
end

Instance Method Details

#examine_context(ctx) ⇒ Array<SmellWarning>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks whether the given block is inside another.

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/reek/smells/nested_iterators.rb', line 36

def examine_context(ctx)
  exp, depth = *find_deepest_iterator(ctx)

  if depth && depth > value(MAX_ALLOWED_NESTING_KEY, ctx, DEFAULT_MAX_ALLOWED_NESTING)
    [SmellWarning.new(self,
                      context: ctx.full_name,
                      lines: [exp.line],
                      message: "contains iterators nested #{depth} deep",
                      parameters: { name: ctx.full_name, count: depth })]
  else
    []
  end
  # BUG: no longer reports nesting outside methods (eg. in Optparse)
end