Sha256: e490d45cfbde0b58373e61fcd802a9265b9eefdcb6d3e173ad7263df424b4198

Contents?: true

Size: 606 Bytes

Versions: 15

Compression:

Stored size: 606 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop looks for *unless* expressions with *else* clauses.
      class UnlessElse < Cop
        MSG = 'Do not use `unless` with `else`. Rewrite these with the ' \
              'positive case first.'

        def on_if(node)
          loc = node.loc

          # discard ternary ops and modifier if/unless nodes
          return unless loc.respond_to?(:keyword) && loc.respond_to?(:else)
          return unless loc.keyword.is?('unless') && loc.else

          add_offense(node, :expression)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.35.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.34.2 lib/rubocop/cop/style/unless_else.rb
rubocop-0.34.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.34.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.33.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.32.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.32.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.31.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.30.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.30.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.29.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.29.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.28.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.27.1 lib/rubocop/cop/style/unless_else.rb