Sha256: e95180eb5a9b1b11abe85e6e691f3ae843f4f88b739b87ca5423bf5119e09de9

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for trailing code after the method definition.
      #
      # @example
      #   # bad
      #   def some_method; do_stuff
      #   end
      #
      #   def f(x); b = foo
      #     b[c: x]
      #   end
      #
      #   # good
      #   def some_method
      #     do_stuff
      #   end
      #
      #   def f(x)
      #     b = foo
      #     b[c: x]
      #   end
      #
      class TrailingBodyOnMethodDefinition < Base
        include Alignment
        include TrailingBody
        extend AutoCorrector

        MSG = "Place the first line of a multi-line method definition's " \
              'body on its own line.'

        def on_def(node)
          return unless trailing_body?(node)
          return if node.endless? && node.body.parenthesized_call?

          add_offense(first_part_of(node.body)) do |corrector|
            LineBreakCorrector.correct_trailing_body(
              configured_width: configured_indentation_width,
              corrector: corrector,
              node: node,
              processed_source: processed_source
            )
          end
        end
        alias on_defs on_def
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-1.11.0 lib/rubocop/cop/style/trailing_body_on_method_definition.rb