Sha256: a0e798db64706ce43cc3fa9c848a6cc4fe21de8e0682815ab78c01ed23d6ac7b

Contents?: true

Size: 1.02 KB

Versions: 6833

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,833 entries across 6,827 versions & 26 rubygems

Version Path
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
mfk_openapi_ruby_client-1.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.2.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.1.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.0.3 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.0.2 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.0.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
passbase-1.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/layout/condition_position.rb