Sha256: 3f48487b82234948930604c4752617dcc20cacd1efc3654f0966b20c5f4b9d93

Contents?: true

Size: 788 Bytes

Versions: 14

Compression:

Stored size: 788 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class ParenthesesAroundCondition < Cop
      ERROR_MESSAGE = "Don't use parentheses around the condition of an " +
        'if/unless/while/until, unless the condition contains an assignment.'

      def inspect(file, source, tokens, sexp)
        [:if, :elsif, :unless, :while, :until,
         :if_mod, :unless_mod, :while_mod, :until_mod].each do |keyword|
          each(keyword, sexp) do |s|
            if s[1][0] == :paren && s[1][1][0][0] != :assign
              positions = all_positions(s[1])
              if positions.first.lineno == positions.last.lineno
                add_offence(:convention, positions.first.lineno, ERROR_MESSAGE)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubocop-0.7.2 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.7.1 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.7.0 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.6.1 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.6.0 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.5.0 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.6 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.5 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.4 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.3 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.2 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.1 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.4.0 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.3.2 lib/rubocop/cop/parentheses_around_condition.rb