Sha256: 03fb9739be1624b8d78858e2fbf53cd3971dbc4c40b4c604bc268d2c88aa5475

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

# encoding: utf-8
# 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

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/multiline_if_then.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.43.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.42.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.41.2 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.41.1 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.41.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.40.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.39.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.38.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.37.2 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.37.1 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.37.0 lib/rubocop/cop/style/multiline_if_then.rb
rubocop-0.36.0 lib/rubocop/cop/style/multiline_if_then.rb