Sha256: 11e6a1d9a803df6645162ec3520aeb740fc437f48bc1905a1cb1368ca56b7a89

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # Check for uses of braces or do/end around single line or
      # multi-line blocks.
      class Blocks < Cop
        MULTI_LINE_MSG = 'Avoid using {...} for multi-line blocks.'
        SINGLE_LINE_MSG = 'Prefer {...} over do...end for single-line blocks.'

        def on_block(node)
          block_length = Util.block_length(node)
          block_begin = node.loc.begin.source

          if block_length > 0 && block_begin == '{'
            add_offence(:convention, node.loc.begin, MULTI_LINE_MSG)
          elsif block_length == 0 && block_begin != '{'
            add_offence(:convention, node.loc.begin, SINGLE_LINE_MSG)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.10.0 lib/rubocop/cop/style/blocks.rb