Sha256: 48f4a494e9ad76d3ec61774d8e4414dbda437d7b1ff33d7819a5af1c20435491

Contents?: true

Size: 719 Bytes

Versions: 6836

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This class does condition auto-correction
    class ConditionCorrector
      class << self
        def correct_negative_condition(node)
          condition = negated_condition(node)

          lambda do |corrector|
            corrector.replace(node.loc.keyword, node.inverse_keyword)
            corrector.replace(condition.source_range,
                              condition.children.first.source)
          end
        end

        private

        def negated_condition(node)
          condition = node.condition
          condition = condition.children.first while condition.begin_type?
          condition
        end
      end
    end
  end
end

Version data entries

6,836 entries across 6,811 versions & 27 rubygems

Version Path
rubocop-0.60.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.59.2 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.59.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.59.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.58.2 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.58.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.58.0 lib/rubocop/cop/correctors/condition_corrector.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.57.2 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.57.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.57.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.56.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.55.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.54.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.53.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.52.1 lib/rubocop/cop/correctors/condition_corrector.rb