Sha256: 0a67e4a2a1c788c7479db413d0c3e441622236b446da6e91cc55619cf1047d6f

Contents?: true

Size: 987 Bytes

Versions: 6

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # 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 `%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, :expression, format(MSG, node.keyword))
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.49.1 lib/rubocop/cop/lint/condition_position.rb
rubocop-0.49.0 lib/rubocop/cop/lint/condition_position.rb
rubocop-0.48.1 lib/rubocop/cop/lint/condition_position.rb
rubocop-0.48.0 lib/rubocop/cop/lint/condition_position.rb
rubocop-0.47.1 lib/rubocop/cop/lint/condition_position.rb
rubocop-0.47.0 lib/rubocop/cop/lint/condition_position.rb