Sha256: 35d0348a46e6e36e45204ac72fc578a97f99d33e682fb33eb7b8a4f874141b79

Contents?: true

Size: 1.75 KB

Versions: 39

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Helps determine the offending location if there is not an empty line
      # following the node. Allows comments to follow directly after
      # in the following cases.
      # - `rubocop:enable` directive
      # - followed by empty line(s)
      module EmptyLineSeparation
        include FinalEndLocation
        include RangeHelp

        def missing_separating_line_offense(node)
          return if last_child?(node)

          missing_separating_line(node) do |location|
            msg = yield(node.method_name)
            add_offense(location, message: msg) do |corrector|
              corrector.insert_after(location.end, "\n")
            end
          end
        end

        def missing_separating_line(node)
          line = final_end_line = final_end_location(node).line
          while processed_source.line_with_comment?(line + 1)
            line += 1
            comment = processed_source.comment_at_line(line)
            if DirectiveComment.new(comment).enabled?
              enable_directive_line = line
            end
          end

          return if processed_source[line].blank?

          yield offending_loc(enable_directive_line || final_end_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
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 7 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/mixin/empty_line_separation.rb