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
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.75.1 lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.75.0 lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.74.0 lib/rubocop/cop/correctors/condition_corrector.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.73.0 lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-0.72.0 lib/rubocop/cop/correctors/condition_corrector.rb