Sha256: 54fcac7c601a8c1610183b4f00632382dd3adcc33f72a778eca44474246e11ae

Contents?: true

Size: 575 Bytes

Versions: 5

Compression:

Stored size: 575 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for rewriting endless methods to normal method definitions
    module EndlessMethodRewriter
      def correct_to_multiline(corrector, node)
        replacement = <<~RUBY.strip
          def #{node.method_name}#{arguments(node)}
            #{node.body.source}
          end
        RUBY

        corrector.replace(node, replacement)
      end

      private

      def arguments(node, missing = '')
        node.arguments.any? ? node.arguments.source : missing
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/mixin/endless_method_rewriter.rb
rubocop-1.69.2 lib/rubocop/cop/mixin/endless_method_rewriter.rb
rubocop-1.69.1 lib/rubocop/cop/mixin/endless_method_rewriter.rb
rubocop-1.69.0 lib/rubocop/cop/mixin/endless_method_rewriter.rb
rubocop-1.68.0 lib/rubocop/cop/mixin/endless_method_rewriter.rb