Sha256: b152af079a606d80db0e7cbea4b9e5fce6bb7ff8bf5d07692cfb79fd06f0612c

Contents?: true

Size: 688 Bytes

Versions: 13

Compression:

Stored size: 688 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for uses of semicolon in if statements.
      #
      # @example
      #
      #   # bad
      #   result = if some_condition; something else another_thing end
      #
      #   # good
      #   result = some_condition ? something : another_thing
      #
      class IfWithSemicolon < Cop
        include OnNormalIfUnless

        MSG = 'Do not use if x; Use the ternary operator instead.'.freeze

        def on_normal_if_unless(node)
          beginning = node.loc.begin
          return unless beginning && beginning.is?(';')
          add_offense(node)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rubocop-0.58.2 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.58.1 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.58.0 lib/rubocop/cop/style/if_with_semicolon.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.57.2 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.57.1 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.57.0 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.56.0 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.55.0 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.54.0 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.53.0 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.52.1 lib/rubocop/cop/style/if_with_semicolon.rb
rubocop-0.52.0 lib/rubocop/cop/style/if_with_semicolon.rb