Sha256: 8939b3f607e56708928c8526af28fb07213d4c609ece8a659c987d4a81b12b4f

Contents?: true

Size: 695 Bytes

Versions: 9

Compression:

Stored size: 695 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # This autocorrects parentheses
    class ParenthesesCorrector
      class << self
        def correct(corrector, node)
          corrector.remove(node.loc.begin)
          corrector.remove(node.loc.end)
          return unless ternary_condition?(node) && next_char_is_question_mark?(node)

          corrector.insert_after(node.loc.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

9 entries across 9 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/correctors/parentheses_corrector.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.33.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.32.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.31.2 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.31.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.31.0 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.30.1 lib/rubocop/cop/correctors/parentheses_corrector.rb
rubocop-1.30.0 lib/rubocop/cop/correctors/parentheses_corrector.rb