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
rubocop-0.69.0 lib/rubocop/cop/correctors/parentheses_corrector.rb