Sha256: 8f43e4a76c3a7d449cfb310d6b02b12a36d8b9c1afad8ddbc3f527d8e4e17260

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module RuboCop
  module RSpec
    # Helps determine the offending location if there is not a blank line
    # following the node. Allows comments to follow directly after.
    module BlankLineSeparation
      include FinalEndLocation
      include RuboCop::Cop::RangeHelp

      def missing_separating_line(node)
        line = final_end_location(node).line

        line += 1 while comment_line?(processed_source[line])

        return if processed_source[line].blank?

        yield offending_loc(line)
      end

      def offending_loc(last_line)
        offending_line = processed_source[last_line - 1]

        content_length = offending_line.lstrip.length
        start          = offending_line.length - content_length

        source_range(processed_source.buffer, last_line, start, content_length)
      end

      def last_child?(node)
        return true unless node.parent&.begin_type?

        node.equal?(node.parent.children.last)
      end

      def autocorrect(node)
        lambda do |corrector|
          missing_separating_line(node) do |location|
            corrector.insert_after(location.end, "\n")
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubocop-rspec-1.41.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.40.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.39.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.38.1 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.38.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.37.1 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.37.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.36.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.35.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.34.1 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.34.0 lib/rubocop/rspec/blank_line_separation.rb
rubocop-rspec-1.33.0 lib/rubocop/rspec/blank_line_separation.rb