Sha256: 1f6dfa0083997aa2b6497f64e9a8f9340548e8500562851377aa13b636ccd46a

Contents?: true

Size: 830 Bytes

Versions: 7

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for END blocks in method definitions.
      #
      # @example
      #
      #   # bad
      #
      #   def some_method
      #     END { do_something }
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def some_method
      #     at_exit { do_something }
      #   end
      #
      # @example
      #
      #   # good
      #
      #   # outside defs
      #   END { do_something }
      class EndInMethod < Cop
        MSG = '`END` found in method definition. Use `at_exit` instead.'.freeze

        def on_postexe(node)
          inside_of_method = node.each_ancestor(:def, :defs).count.nonzero?
          add_offense(node, :keyword) if inside_of_method
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.50.0 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.49.1 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.49.0 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.48.1 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.48.0 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.47.1 lib/rubocop/cop/lint/end_in_method.rb
rubocop-0.47.0 lib/rubocop/cop/lint/end_in_method.rb