Sha256: f69294d0223a7e2e4f7ae9dac9fe794a41d0af358988491714ead24339d0e93e

Contents?: true

Size: 1.57 KB

Versions: 12

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This auto-corrects whitespace
    class SpaceCorrector
      extend SurroundingSpace

      class << self
        attr_reader :processed_source

        def empty_corrections(processed_source, corrector, empty_config,
                              left_token, right_token)
          @processed_source = processed_source
          range = range_between(left_token.end_pos, right_token.begin_pos)
          if offending_empty_space?(empty_config, left_token, right_token)
            corrector.remove(range)
            corrector.insert_after(left_token.pos, ' ')
          elsif offending_empty_no_space?(empty_config, left_token, right_token)
            corrector.remove(range)
          end
        end

        def remove_space(processed_source, corrector, left_token, right_token)
          @processed_source = processed_source
          if left_token.space_after?
            range = side_space_range(range: left_token.pos, side: :right)
            corrector.remove(range)
          end
          return unless right_token.space_before?

          range = side_space_range(range: right_token.pos, side: :left)
          corrector.remove(range)
        end

        def add_space(processed_source, corrector, left_token, right_token)
          @processed_source = processed_source
          unless left_token.space_after?
            corrector.insert_after(left_token.pos, ' ')
          end
          return if right_token.space_before?

          corrector.insert_before(right_token.pos, ' ')
        end
      end
    end
  end
end

Version data entries

12 entries across 11 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.83.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.82.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.81.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.80.1 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.80.0 lib/rubocop/cop/correctors/space_corrector.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/space_corrector.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.79.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.78.0 lib/rubocop/cop/correctors/space_corrector.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-0.77.0 lib/rubocop/cop/correctors/space_corrector.rb