Sha256: 616d9e3ef9dd083dbd6720424a3872c4d972846ac858e5ad213851c46f3a2574

Contents?: true

Size: 816 Bytes

Versions: 8

Compression:

Stored size: 816 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Lint
      # This cop checks for nested method definitions.
      #
      # @example
      #   # `bar` definition actually produces methods in the same scope
      #   # as the outer `foo` method. Furthermore, the `bar` method
      #   # will be redefined every time the `foo` is invoked
      #   def foo
      #     def bar
      #     end
      #   end
      #
      class NestedMethodDefinition < Cop
        include OnMethodDef

        MSG = 'Method definitions must not be nested. ' \
              'Use `lambda` instead.'

        def on_method_def(node, _method_name, _args, _body)
          node.each_descendant(:def) do |nested_def_node|
            add_offense(nested_def_node, :expression)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.35.0 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.34.2 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.34.1 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.34.0 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.33.0 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.32.1 lib/rubocop/cop/lint/nested_method_definition.rb
rubocop-0.32.0 lib/rubocop/cop/lint/nested_method_definition.rb