Sha256: 3b91045d9195c1b1f020414a2db572ed3328286fd558bf86c976723ec05fc2a6

Contents?: true

Size: 651 Bytes

Versions: 1

Compression:

Stored size: 651 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, unless the condition contains an assignment.'

      def inspect(source, tokens, ast, comments)
        on_node([:if, :while, :until], ast) do |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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.8.0 lib/rubocop/cop/parentheses_around_condition.rb