Sha256: 649402bf4dcd70ad943bf56686816efba397682775d3a0c53057853f2917ea7b

Contents?: true

Size: 731 Bytes

Versions: 2

Compression:

Stored size: 731 Bytes

Contents

# encoding: utf-8

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

      def on_if(node)
        process_control_op(node)

        super
      end

      def on_while(node)
        process_control_op(node)

        super
      end

      def on_until(node)
        process_control_op(node)

        super
      end

      private

      def process_control_op(node)
        cond, _body = *node

        cond_source = cond.loc.expression.source

        if cond_source.start_with?('(') && cond_source.end_with?(')')
          add_offence(:convetion, cond.loc.line, MSG)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/parentheses_around_condition.rb
rubocop-0.8.2 lib/rubocop/cop/parentheses_around_condition.rb