Sha256: 25403b6a4b7eab37509e57638257fa10a25b6029de87b553da25f654df6e1697

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for uses of the `then` keyword in multi-line if statements.
      #
      # @example This is considered bad practice:
      #
      #   if cond then
      #   end
      #
      # @example If statements can contain `then` on the same line:
      #
      #   if cond then a
      #   elsif cond then b
      #   end
      class MultilineIfThen < Cop
        include IfNode
        include OnNormalIfUnless

        def on_normal_if_unless(node)
          return unless node.loc.begin
          return unless node.loc.begin.source_line =~ /then\s*(#.*)?$/
          add_offense(node, :begin)
        end

        def message(node)
          "Do not use `then` for multi-line `#{node.loc.keyword.source}`."
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(range_with_surrounding_space(node.loc.begin,
                                                          :left))
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.46.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.45.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.44.1 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.44.0 lib/rubocop/cop/style/multiline_if_then.rb