Sha256: 2b60e81897c27c9dbf643a35f0e06581b076a65b070222a6b51e57aaf6e45faf

Contents?: true

Size: 1.02 KB

Versions: 47

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This cop checks for conditions that are not on the same line as
      # if/while/until.
      #
      # @example
      #
      #   # bad
      #
      #   if
      #     some_condition
      #     do_something
      #   end
      #
      # @example
      #
      #   # good
      #
      #   if some_condition
      #     do_something
      #   end
      class ConditionPosition < Cop
        MSG = 'Place the condition on the same line as `%<keyword>s`.'

        def on_if(node)
          return if node.ternary?

          check(node)
        end

        def on_while(node)
          check(node)
        end

        def on_until(node)
          check(node)
        end

        private

        def check(node)
          return if node.modifier_form? || node.single_line_condition?

          add_offense(node.condition)
        end

        def message(node)
          format(MSG, keyword: node.parent.keyword)
        end
      end
    end
  end
end

Version data entries

47 entries across 28 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/condition_position.rb
rubocop-0.82.0 lib/rubocop/cop/layout/condition_position.rb
rubocop-0.81.0 lib/rubocop/cop/layout/condition_position.rb
rubocop-0.80.1 lib/rubocop/cop/layout/condition_position.rb
rubocop-0.80.0 lib/rubocop/cop/layout/condition_position.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/condition_position.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/layout/condition_position.rb
rubocop-0.79.0 lib/rubocop/cop/layout/condition_position.rb
rubocop-0.78.0 lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/layout/condition_position.rb
rubocop-0.77.0 lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/layout/condition_position.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/layout/condition_position.rb