Sha256: 24938bd8ad6317849d68f2102b147aec7281c29476319a06dbba3a635dc4178d

Contents?: true

Size: 623 Bytes

Versions: 4

Compression:

Stored size: 623 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    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.line, MULTI_LINE_MSG)
        elsif block_length == 0 && block_begin != '{'
          add_offence(:convention, node.loc.line, SINGLE_LINE_MSG)
        end

        super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/blocks.rb
rubocop-0.8.2 lib/rubocop/cop/blocks.rb
rubocop-0.8.1 lib/rubocop/cop/blocks.rb
rubocop-0.8.0 lib/rubocop/cop/blocks.rb