Sha256: 0392e38960a474c804a8733eae519084ddc4934c451e36855964ad74941438a8

Contents?: true

Size: 605 Bytes

Versions: 9

Compression:

Stored size: 605 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop looks for *unless* expressions with *else* clauses.
      class UnlessElse < Cop
        MSG = 'Never 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

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/unless_else.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/unless_else.rb
rubocop-0.27.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.26.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.26.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.25.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.24.1 lib/rubocop/cop/style/unless_else.rb
rubocop-0.24.0 lib/rubocop/cop/style/unless_else.rb
rubocop-0.23.0 lib/rubocop/cop/style/unless_else.rb