Sha256: a0e798db64706ce43cc3fa9c848a6cc4fe21de8e0682815ab78c01ed23d6ac7b

Contents?: true

Size: 1.02 KB

Versions: 6834

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`.'.freeze

        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

6,834 entries across 6,828 versions & 26 rubygems

Version Path
ory-client-0.0.1.alpha36 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb