Sha256: 6bcdfd508d0912ba45d130e6740158c3c233da1f685e5f2eafd85a66f47914bc

Contents?: true

Size: 746 Bytes

Versions: 61

Compression:

Stored size: 746 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This auto-corrects parentheses
    class ParenthesesCorrector
      class << self
        def correct(node)
          lambda do |corrector|
            corrector.remove(node.loc.begin)
            corrector.remove(node.loc.end)

            if ternary_condition?(node) && next_char_is_question_mark?(node)
              corrector.insert_after(node.loc.end, ' ')
            end
          end
        end

        private

        def ternary_condition?(node)
          node.parent&.if_type? && node.parent&.ternary?
        end

        def next_char_is_question_mark?(node)
          node.loc.last_column == node.parent.loc.question.column
        end
      end
    end
  end
end

Version data entries

61 entries across 42 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.89.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.89.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.88.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.87.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.87.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.86.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/correctors/parentheses_corrector.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/correctors/parentheses_corrector.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.85.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.85.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.83.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.82.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.81.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.80.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-0.80.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/correctors/parentheses_corrector.rb