Sha256: e0a8faa276f051bb7b42a934ba7bd9597a679a8613569b84400316ffd859dc7f

Contents?: true

Size: 637 Bytes

Versions: 73

Compression:

Stored size: 637 Bytes

Contents

# frozen_string_literal: true

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

          corrector.replace(node.loc.keyword, node.inverse_keyword)
          corrector.replace(condition, condition.children.first.source)
        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

73 entries across 73 versions & 8 rubygems

Version Path
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.23.0 lib/rubocop/cop/correctors/condition_corrector.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.22.3 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.22.2 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.22.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.22.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.21.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.20.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.19.1 lib/rubocop/cop/correctors/condition_corrector.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.19.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.18.4 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.18.3 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.18.2 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.18.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.18.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.17.0 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.16.1 lib/rubocop/cop/correctors/condition_corrector.rb
rubocop-1.16.0 lib/rubocop/cop/correctors/condition_corrector.rb