Sha256: 6ee8c46b9c8f3e3337bfa1c3dffd0c78d77712906357aceff322862a2ad0e9ef

Contents?: true

Size: 513 Bytes

Versions: 4

Compression:

Stored size: 513 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    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)

        if loc.keyword.source == 'unless' && loc.else
          add_offence(:convention, loc.line, MSG)
        end

        super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/unless_else.rb
rubocop-0.8.2 lib/rubocop/cop/unless_else.rb
rubocop-0.8.1 lib/rubocop/cop/unless_else.rb
rubocop-0.8.0 lib/rubocop/cop/unless_else.rb