Sha256: a1f9e07392e4db8ba8cfe424acd21d978bedd4009215fb53d6fdf6acd1aa0f01

Contents?: true

Size: 1.54 KB

Versions: 87

Compression:

Stored size: 1.54 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
          corrector.insert_after(left_token.pos, ' ') unless left_token.space_after?
          return if right_token.space_before?

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

Version data entries

87 entries across 87 versions & 10 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/correctors/space_corrector.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.29.1 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.29.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.28.2 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.28.1 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.28.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.27.0 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.26.1 lib/rubocop/cop/correctors/space_corrector.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.26.0 lib/rubocop/cop/correctors/space_corrector.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/space_corrector.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.25.1 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.25.0 lib/rubocop/cop/correctors/space_corrector.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/space_corrector.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/space_corrector.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.24.1 lib/rubocop/cop/correctors/space_corrector.rb
rubocop-1.24.0 lib/rubocop/cop/correctors/space_corrector.rb