Sha256: 30965081a84574d698748e85a5ed69a50c105fd617f04a0f265937cb8361261f

Contents?: true

Size: 885 Bytes

Versions: 50

Compression:

Stored size: 885 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Enforces the presence of parentheses in `super` containing arguments.
      #
      # `super` is a keyword and is provided as a distinct cop from those designed for method call.
      #
      # @example
      #
      #   # bad
      #   super name, age
      #
      #   # good
      #   super(name, age)
      #
      class SuperWithArgsParentheses < Base
        extend AutoCorrector

        MSG = 'Use parentheses for `super` with arguments.'

        def on_super(node)
          return if node.parenthesized?

          add_offense(node) do |corrector|
            range = node.loc.keyword.end.join(node.first_argument.source_range.begin)
            corrector.replace(range, '(')
            corrector.insert_after(node.last_argument, ')')
          end
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 10 rubygems

Version Path
rubocop-1.74.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.73.2 lib/rubocop/cop/style/super_with_args_parentheses.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.73.1 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.73.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.72.2 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.72.1 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.72.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.71.2 lib/rubocop/cop/style/super_with_args_parentheses.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.71.1 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.71.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.70.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.69.2 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.69.1 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.69.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.68.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.67.0 lib/rubocop/cop/style/super_with_args_parentheses.rb
rubocop-1.66.1 lib/rubocop/cop/style/super_with_args_parentheses.rb