Sha256: ea7ea4d8987ce6e601f42c1d9be728d1422921d54f78ef46176525e2a462b525

Contents?: true

Size: 920 Bytes

Versions: 6791

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for if and unless statements used as modifiers of other if or
      # unless statements.
      #
      # @example
      #
      #  # bad
      #  tired? ? 'stop' : 'go faster' if running?
      #
      #  # bad
      #  if tired?
      #    "please stop"
      #  else
      #    "keep going"
      #  end if running?
      #
      #  # good
      #  if running?
      #    tired? ? 'stop' : 'go faster'
      #  end
      class IfUnlessModifierOfIfUnless < Cop
        include StatementModifier

        MSG = 'Avoid modifier `%<keyword>s` after another conditional.'.freeze

        def on_if(node)
          return unless node.modifier_form? && node.body.if_type?

          add_offense(node, location: :keyword,
                            message: format(MSG, keyword: node.keyword))
        end
      end
    end
  end
end

Version data entries

6,791 entries across 6,785 versions & 25 rubygems

Version Path
rubocop-0.67.1 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.67.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.66.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.65.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.64.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.63.1 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.63.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.62.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.61.1 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.61.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.60.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.59.2 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.59.1 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.59.0 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.58.2 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
rubocop-0.58.1 lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb