Sha256: df1b72641003869a066c229d143d0130562c6c5af836fa69f577fb831590895b

Contents?: true

Size: 897 Bytes

Versions: 14

Compression:

Stored size: 897 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # Checks for colon (:) not followed by some kind of space.
      class SpaceAfterColon < Cop
        include IfNode

        MSG = 'Space missing after colon.'

        def on_pair(node)
          oper = node.loc.operator
          return unless oper.is?(':') && followed_by_space?(oper)

          add_offense(oper, oper)
        end

        def on_if(node)
          return unless ternary_op?(node)

          colon = node.loc.colon
          return unless followed_by_space?(colon)

          add_offense(colon, colon)
        end

        def followed_by_space?(colon)
          colon.source_buffer.source[colon.end_pos] =~ /\S/
        end

        def autocorrect(range)
          @corrections << lambda do |corrector|
            corrector.insert_after(range, ' ')
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_colon.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.30.1 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.30.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.29.1 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.29.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.28.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.27.1 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.27.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.26.1 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.26.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.25.0 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.24.1 lib/rubocop/cop/style/space_after_colon.rb
rubocop-0.24.0 lib/rubocop/cop/style/space_after_colon.rb